Skip to content

Commit

Permalink
remove extraneous warning string checks, ensure config cleanup before…
Browse files Browse the repository at this point in the history
… test assertions
  • Loading branch information
alphasentaurii committed Sep 21, 2023
1 parent 64c6bf6 commit 46d54bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ jobs:
- ubuntu-latest
# - macos-latest # TEMP
python-version:
- 3.9
# - 3.9
- '3.10'
- 3.11
# - 3.11
steps:
- uses: actions/checkout@v3
with:
Expand Down
36 changes: 18 additions & 18 deletions test/bestrefs/test_bestrefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ def test_bestrefs_3_files(default_shared_state, caplog, hst_data):
{hst_data}/j8bt06o6q_raw.fits {hst_data}/j8bt09jcq_raw.fits"""
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
def test_bestrefs_compare_source_files(default_shared_state, caplog, hst_data):
Expand All @@ -86,6 +87,7 @@ def test_bestrefs_compare_source_files(default_shared_state, caplog, hst_data):
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" No file header updates requested; dry run. Use --update-bestrefs to update FITS headers.
===> Processing {hst_data}/j8bt05njq_raw.fits
instrument='ACS' type='ATODTAB' data='{hst_data}/j8bt05njq_raw.fits' :: New best reference: 'kcb1734ij_a2d.fits' --> 'n/a' :: Would update.
Expand Down Expand Up @@ -113,7 +115,6 @@ def test_bestrefs_compare_source_files(default_shared_state, caplog, hst_data):
19 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -124,7 +125,7 @@ def test_bestrefs_3_files_default_context_from_server(default_shared_state, capl
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text

default_shared_state.cleanup()
out_to_check = f""" No comparison context or source comparison requested.
No file header updates requested; dry run. Use --update-bestrefs to update FITS headers.
===> Processing {hst_data}/j8bt05njq_raw.fits
Expand All @@ -135,7 +136,6 @@ def test_bestrefs_3_files_default_context_from_server(default_shared_state, capl
5 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -146,6 +146,7 @@ def test_bestrefs_broken_dataset_file(default_shared_state, caplog, hst_data):
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" No comparison context or source comparison requested.
No file header updates requested; dry run. Use --update-bestrefs to update FITS headers.
===> Processing {hst_data}/j8bt05njq_raw.fits
Expand All @@ -158,7 +159,6 @@ def test_bestrefs_broken_dataset_file(default_shared_state, caplog, hst_data):
6 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -170,13 +170,12 @@ def test_bestrefs_broken_cache_and_server(broken_state, caplog, hst_data):
BestrefsScript(argv)()
assert pytest_wrapped_e.type == SystemExit
out = caplog.text
broken_state.cleanup()
out_to_check = """ (FATAL) CRDS server connection and cache load FAILED. Cannot continue.
See https://hst-crds.stsci.edu/docs/cmdline_bestrefs/ or https://jwst-crds.stsci.edu/docs/cmdline_bestrefs/
for more information on configuring CRDS, particularly CRDS_PATH and CRDS_SERVER_URL. : [Errno 2] No such file or directory: '/nowhere/config/hst/server_config'"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
broken_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -185,6 +184,7 @@ def test_bestrefs_catalog_dataset(default_shared_state, caplog):
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = """ Dumping dataset parameters from CRDS server at 'https://hst-crds.stsci.edu' for ['LB6M01030']
Dumped 1 of 1 datasets from CRDS server at 'https://hst-crds.stsci.edu'
Computing bestrefs for datasets ['LB6M01030']
Expand All @@ -194,7 +194,7 @@ def test_bestrefs_catalog_dataset(default_shared_state, caplog):
4 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()



@pytest.mark.bestrefs
Expand All @@ -204,6 +204,7 @@ def test_bestrefs_context_to_context(default_shared_state, caplog, hst_data):
with caplog.at_level(logging.INFO, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" No file header updates requested; dry run. Use --update-bestrefs to update FITS headers.
===> Processing {hst_data}/j8bt05njq_raw.fits
===> Processing {hst_data}/j8bt06o6q_raw.fits
Expand All @@ -213,7 +214,6 @@ def test_bestrefs_context_to_context(default_shared_state, caplog, hst_data):
4 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -223,6 +223,7 @@ def test_bestrefs_all_instruments_hst(default_shared_state, caplog, hst_data):
test_brs = BestrefsScript(argv)
test_brs.complex_init()
out = caplog.messages
default_shared_state.cleanup()
odd_pattern = re.compile(" Dumping dataset parameters for '[a-z0-9]{3,6}' from CRDS server at 'https://hst-crds.stsci.edu'")
even_pattern = re.compile(" Downloaded [0-9]{5,6} dataset ids for '[a-z0-9]{3,6}' since None")
for i, line in enumerate(out):
Expand All @@ -232,7 +233,6 @@ def test_bestrefs_all_instruments_hst(default_shared_state, caplog, hst_data):
assert re.match(even_pattern, line) is not None
elif i < 13:
assert re.match(odd_pattern, line) is not None
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -243,6 +243,7 @@ def test_bestrefs_datasets_since_auto_hst(default_shared_state, caplog):
test_brs.complex_init()
out = caplog.text
messages = caplog.messages
default_shared_state.cleanup()
out_to_check = """ Mapping differences from 'hst.pmap' --> 'test/data/hst/hst_0001.pmap' affect:
{'acs': ['biasfile']}
Possibly affected --datasets-since dates determined by 'hst.pmap' --> 'test/data/hst/hst_0001.pmap' are:
Expand All @@ -257,7 +258,6 @@ def test_bestrefs_datasets_since_auto_hst(default_shared_state, caplog):
else:
# using re b/c the numeric value is dynamic
assert re.match(pattern, messages[-2]) is not None
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -267,11 +267,11 @@ def test_bestrefs_dataset_drop_ids(default_shared_state, caplog, hst_data):
test_brs = BestrefsScript(argv)
test_brs.complex_init()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" Loading file '{hst_data}/test_cos.json'
Loaded 1 datasets from file '{hst_data}/test_cos.json' completely replacing existing headers."""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -281,19 +281,20 @@ def test_bestrefs_dataset_only_ids(default_shared_state, caplog, hst_data):
test_brs = BestrefsScript(argv)
test_brs.complex_init()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" Loading file '{hst_data}/test_cos.json'
Loaded 1 datasets from file '{hst_data}/test_cos.json' completely replacing existing headers."""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
def test_bestrefs_compare_source_canary(default_shared_state, caplog, hst_data):
argv = f"""crds.bestrefs --new-context hst_0551.pmap --compare-source --load-pickles {hst_data}/canary.json --differences-are-errors --hst"""
with caplog.at_level(logging.DEBUG, logger="CRDS"):
test_brs = BestrefsScript(argv)()
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" Loading file '{hst_data}/canary.json'
Loaded 1 datasets from file '{hst_data}/canary.json' completely replacing existing headers.
instrument='COS' type='BPIXTAB' data='LA7803FIQ' :: Comparison difference: 'bar.fits' --> 'yae1249sl_bpix.fits' :: Would update.
Expand All @@ -303,7 +304,6 @@ def test_bestrefs_compare_source_canary(default_shared_state, caplog, hst_data):
2 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -312,6 +312,7 @@ def test_bestrefs_donotreprocess_datasets(default_shared_state, caplog):
with caplog.at_level(logging.INFO, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = """ Dumping dataset parameters from CRDS server at 'https://hst-crds.stsci.edu' for ['JA9553LVQ', 'JBBGRCGFQ']
Dumped 2 of 2 datasets from CRDS server at 'https://hst-crds.stsci.edu'
Computing bestrefs for datasets ['JA9553LVQ', 'JBBGRCGFQ']
Expand All @@ -320,7 +321,6 @@ def test_bestrefs_donotreprocess_datasets(default_shared_state, caplog):
5 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -329,6 +329,7 @@ def test_bestrefs_donotreprocess_fix(default_shared_state, caplog, hst_data):
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" Command: ['crds.bestrefs', '--hst', '--old-context', 'hst_0628.pmap', '--new-context', 'hst_0633.pmap', '--print-affected', '--load-pickle', '{hst_data}/bestrefs_dnr_fix.json', '--verbosity=30']
Using explicit new context 'hst_0633.pmap' for computing updated best references.
Using explicit old context 'hst_0628.pmap'
Expand Down Expand Up @@ -365,7 +366,6 @@ def test_bestrefs_donotreprocess_fix(default_shared_state, caplog, hst_data):
5 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand All @@ -374,6 +374,7 @@ def test_bestrefs_multiple_updates_with_error(default_shared_state, caplog, hst_
with caplog.at_level(logging.DEBUG, logger="CRDS"):
BestrefsScript(argv)()
out = caplog.text
default_shared_state.cleanup()
out_to_check = f""" Command: ['crds.bestrefs', '--hst', '--old-context', 'hst_0628.pmap', '--new-context', 'hst_0633.pmap', '--print-affected', '--load-pickle', '{hst_data}/bestrefs_new_error.json', '--verbosity=30']
Using explicit new context 'hst_0633.pmap' for computing updated best references.
Using explicit old context 'hst_0628.pmap'
Expand Down Expand Up @@ -412,7 +413,6 @@ def test_bestrefs_multiple_updates_with_error(default_shared_state, caplog, hst_
3 infos"""
for msg in out_to_check.splitlines():
assert msg.strip() in out
default_shared_state.cleanup()


@pytest.mark.bestrefs
Expand Down
3 changes: 0 additions & 3 deletions test/certify/test_certify.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ def test_certify_recursive(default_shared_state, caplog):
Certifying '{cache}/mappings/hst/hst_cos_xtractab.rmap' (19/19) as 'MAPPING' relative to context 'hst.pmap'
########################################
0 errors
0 warnings
39 infos"""
for msg in expected_out.splitlines():
assert msg.strip() in out
Expand Down Expand Up @@ -622,7 +621,6 @@ def test_certify_jwst_missing_optional_parkey(jwst_serverless_state, jwst_data,
Checking JWST datamodels.
########################################
0 errors
0 warnings
7 infos"""
for msg in expected_out.splitlines():
assert msg.strip() in out
Expand Down Expand Up @@ -1542,7 +1540,6 @@ def test_fits_asdf_extension_fail(jwst_serverless_state, jwst_data, caplog):
Checking JWST datamodels.
########################################
1 errors
0 warnings
5 infos"""
for msg in expected_out.splitlines():
assert msg.strip() in out
Expand Down
1 change: 1 addition & 0 deletions test/test_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_matches_datasets_minimize_headers_contexts_condition(capsys, default_sh
MatchesScript(
"crds.matches --datasets JBANJOF3Q --minimize-headers --contexts hst_0048.pmap hst_0044.pmap --condition-values")()
out, _ = capsys.readouterr()
default_shared_state.cleanup()
out_to_check = """JBANJOF3Q:JBANJOF3Q : hst_0044.pmap : APERTURE='WFC1-2K' ATODCORR='OMIT' BIASCORR='OMIT' \
CCDAMP='B' CCDCHIP='1.0' CCDGAIN='2.0' CRCORR='OMIT' DARKCORR='OMIT' DATE-OBS='2010-01-31' DETECTOR='WFC' \
DQICORR='PERFORM' DRIZCORR='OMIT' FILTER1='F502N' FILTER2='F660N' FLASHCUR='OFF' FLATCORR='OMIT' FLSHCORR='OMIT' \
Expand Down

0 comments on commit 46d54bd

Please sign in to comment.