Skip to content

Commit

Permalink
Merge pull request #1091 from alphasentaurii/drc-test-updates
Browse files Browse the repository at this point in the history
tests/sync-latest-and-build
  • Loading branch information
alphasentaurii authored Oct 17, 2024
2 parents 7a05163 + 94fddbf commit c716c74
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 10 deletions.
1 change: 1 addition & 0 deletions changes/1091.testing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests for sync using symbolic context names
6 changes: 6 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pstats
import mock
import yaml
import re

# ==============================================================================

Expand Down Expand Up @@ -379,3 +380,8 @@ def run_and_profile(name, case, globs={}, locs={}):
def combined_spec(scope='session'):
return json.load(
open(Path(__file__).parent.parent / "crds" / "roman" / "specs" / "combined_specs.json", 'r'))


@fixture(scope='function')
def jwst_pmap_pattern():
return re.compile("jwst_[0-9]{4}.pmap")
8 changes: 4 additions & 4 deletions crds/core/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def determine_contexts(self):
elif config.get_crds_env_context():
contexts = [self.resolve_context(config.get_crds_env_context())]
else:
contexts = [self.resolve_context(self.observatory + "-operational")]
contexts = [self.resolve_context(self.observatory + "-latest")]
log.verbose("Determined contexts: ", contexts, verbosity=55)
return sorted(contexts)

Expand Down Expand Up @@ -855,11 +855,11 @@ def get_context_references(self):

def expand_all_instruments(observatory, context):
"""Expand symbolic context specifiers for rmaps with "all" for instrument
into the list of rmaps for every instrument in the related context (e.g. edit or operational).
into the list of rmaps for every instrument in the related context (e.g. edit or latest).
e.g. jwst-all-photom-operational --> [jwst-miri-photom-operational, jwst-nircam-photom-operational, ...]
e.g. jwst-all-photom-operational --> [jwst-miri-photom-latest, jwst-nircam-photom-latest, ...]
Expansion of "all" is determined by instruments in e.g. jwst-operational
Expansion of "all" is determined by instruments in e.g. jwst-latest
"""
mtch = config.CONTEXT_RE.match(context)
if mtch and mtch.group("instrument") == "all":
Expand Down
4 changes: 2 additions & 2 deletions crds/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ def verify_context_change(self, old_context):
except AttributeError:
new_context = heavy_client.load_server_info(self.observatory).operational_context
if old_context == new_context:
log.error("Expected operational context switch but starting and post-sync contexts are both", repr(old_context))
log.error("Expected latest context switch but starting and post-sync contexts are both", repr(old_context))
else:
log.info("Operational context updated from", repr(old_context), "to", repr(new_context))
log.info("Latest context updated from", repr(old_context), "to", repr(new_context))

def push_context(self):
"""Push the final context recorded in the local cache to the CRDS server so it can be displayed
Expand Down
23 changes: 23 additions & 0 deletions test/core/test_cmdline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pytest import mark
import os
import re
import logging
from crds.core import cmdline, utils, log
from crds.core import config as crds_config
Expand Down Expand Up @@ -320,3 +321,25 @@ def test_determine_contexts_direct(default_test_cache_state):
assert contexts[0] == "hst.pmap"
mappings = sorted(list(set(s.get_context_mappings())))
assert len(mappings) >= 116

@mark.jwst
@mark.core
@mark.cmdline
def test_determine_contexts_no_args(jwst_default_cache_state, jwst_pmap_pattern):
s = ContextsScript("cmdline.ContextsScript --jwst")
s.contexts = contexts = s.determine_contexts()
assert len(contexts) == 1
matches = re.match(jwst_pmap_pattern, contexts[0])
assert matches.group() is not None


@mark.jwst
@mark.core
@mark.cmdline
def test_determine_jwst_build_context(jwst_default_cache_state, jwst_pmap_pattern):
s = ContextsScript("cmdline.ContextsScript --contexts jwst-build")
s.contexts = contexts = s.determine_contexts()
matches = re.match(jwst_pmap_pattern, contexts[0])
assert matches.group() is not None
mapping_closure = sorted(list(set(s.get_context_mappings())))
assert len(mapping_closure) >= 199
14 changes: 11 additions & 3 deletions test/core/test_heavy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def test_getreferences_ignore_cache(jwst_shared_cache_state):
assert refs == {'flat': f'{cache_path}/references/jwst/jwst_miri_flat_0001.fits'}


@mark.jwst
@mark.core
@mark.heavy_client
def test_get_symbolic_build_context_name(jwst_shared_cache_state, jwst_pmap_pattern):
build_context = heavy_client.get_context_name("jwst", "jwst-build")
matches = re.match(jwst_pmap_pattern, build_context)
assert matches.group() is not None


@mark.jwst
@mark.core
@mark.heavy_client
Expand Down Expand Up @@ -159,11 +168,10 @@ def test_get_context_name_symbolic(jwst_serverless_state):
jwst_serverless_state.mode = 'local'
jwst_serverless_state.config_setup()
pattern = re.compile("jwst_[0-9]{4}.pmap")
ops_context = heavy_client.get_context_name("jwst", "jwst-operational")
latest_context = heavy_client.get_context_name("jwst", "jwst-latest")
edit_context = heavy_client.get_context_name("jwst", "jwst-edit")
ver_context = heavy_client.get_context_name("jwst", "jwst-versions")

for context in [ops_context, edit_context, ver_context]:
for context in [latest_context, edit_context, ver_context]:
matches = re.match(pattern, context)
assert matches.group() is not None

Expand Down
35 changes: 34 additions & 1 deletion test/test_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import crds
from crds.core import config, rmap
from crds.sync import SyncScript

from crds import log
import logging
log.THE_LOGGER.logger.propagate=True
log.set_verbose(50)

EXPECTED_MAPPINGS = [
'hst_cos.imap',
Expand Down Expand Up @@ -131,3 +134,33 @@ def test_sync_fetch_sqlite3_db(self):

def test_sync_dataset_ids(self):
self.run_script("crds.sync --contexts hst.pmap --dataset-ids LA9K03CBQ:LA9K03CBQ --fetch-references")


@mark.jwst
@mark.sync
def test_sync_jwst_latest(jwst_default_cache_state, caplog):
with caplog.at_level(logging.INFO, logger="CRDS"):
errors = SyncScript("crds.sync --contexts jwst-latest")()
out = caplog.text
assert errors == 0
assert "Symbolic context 'jwst-latest' resolves to" in out


@mark.jwst
@mark.sync
def test_sync_jwst_build(jwst_default_cache_state, caplog):
with caplog.at_level(logging.INFO, logger="CRDS"):
errors = SyncScript("crds.sync --contexts jwst-build")()
out = caplog.text
assert errors == 0
assert "Symbolic context 'jwst-build' resolves to" in out


@mark.jwst
@mark.sync
def test_sync_latest(jwst_default_cache_state, caplog):
with caplog.at_level(logging.INFO, logger="CRDS"):
errors = SyncScript("crds.sync --contexts latest")()
out = caplog.text
assert errors == 0
assert "Symbolic context 'latest' resolves to" in out

0 comments on commit c716c74

Please sign in to comment.