Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close files in tests and before raising exception in get_open_msa_slits #7599

Merged
merged 2 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ other

- Override package dependencies with requirements file when requested [#7557]

- Close files left open in test suite [#7599]

pathloss
--------

Expand Down
1 change: 1 addition & 0 deletions jwst/assign_wcs/nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ def get_open_msa_slits(msa_file, msa_metadata_id, dither_position,
log.warning(message)
message = ("MSA configuration file has more than 1 shutter with primary source")
log.warning(message)
msa_file.close()
raise MSAFileError(message)

# subtract 1 because shutter numbers in the MSA reference file are 1-based.
Expand Down
18 changes: 9 additions & 9 deletions jwst/assign_wcs/tests/test_nirspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ def test_nirspec_ifu_against_esa(wcs_ifu_grating):
"""
Test Nirspec IFU mode using CV3 reference files.
"""
ref = fits.open(get_file_path('Trace_IFU_Slice_00_SMOS-MOD-G1M-17-5344175105_30192_JLAB88.fits'))
with fits.open(get_file_path('Trace_IFU_Slice_00_SMOS-MOD-G1M-17-5344175105_30192_JLAB88.fits')) as ref:
# Test NRS1
pyw = astwcs.WCS(ref['SLITY1'].header)
# Test evaluating the WCS (slice 0)
im, refs = wcs_ifu_grating("G140M", "OPAQUE")
w0 = nirspec.nrs_wcs_set_input(im, 0)

# Test NRS1
pyw = astwcs.WCS(ref['SLITY1'].header)
# Test evaluating the WCS (slice 0)
im, refs = wcs_ifu_grating("G140M", "OPAQUE")
w0 = nirspec.nrs_wcs_set_input(im, 0)
# get positions within the slit and the corresponding lambda
slit1 = ref['SLITY1'].data # y offset on the slit
lam = ref['LAMBDA1'].data

# get positions within the slit and the corresponding lambda
slit1 = ref['SLITY1'].data # y offset on the slit
lam = ref['LAMBDA1'].data
# filter out locations outside the slit
cond = np.logical_and(slit1 < .5, slit1 > -.5)
y, x = cond.nonzero() # 0-based
Expand Down
9 changes: 5 additions & 4 deletions jwst/associations/tests/test_mkpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@


def test_hdu(exposures):
hdus = [
fits.open(exposure)[0]
for exposure in exposures
]
hdus = []
for exposure in exposures:
with fits.open(exposure) as hdulist:
hdus.append(hdulist[0])
pool = mkpool(hdus)
assert isinstance(pool, AssociationPool)
assert REQUIRED_PARAMS.issubset(pool.colnames)
Expand All @@ -41,6 +41,7 @@ def test_hdulist(exposures):
assert isinstance(pool, AssociationPool)
assert REQUIRED_PARAMS.issubset(pool.colnames)
assert len(pool) == len(exposures)
[h.close() for h in hduls]


def test_mkpool(exposures):
Expand Down
3 changes: 3 additions & 0 deletions jwst/outlier_detection/tests/test_outlier_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def test_outlier_step_square_source_no_outliers(we_three_sci, _jail):
np.testing.assert_allclose(image.data, corrected.data)
np.testing.assert_allclose(image.dq, corrected.dq)

container.close()
pristine.close()


@pytest.mark.parametrize("exptype", IMAGE_MODES)
def test_outlier_step_image_weak_CR_dither(exptype, _jail):
Expand Down
16 changes: 8 additions & 8 deletions jwst/residual_fringe/tests/test_background_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def read_fit_column(file):
file_dir = Path(__file__).parent.resolve()
file_path = str(file_dir / file)

hdu = fits.open(file_path)
col_data = hdu[1].data
col_weight = hdu[2].data
col_wnum = hdu[3].data
bg_fit = hdu[4].data
store_freq = hdu[0].header['FFREQ']

return col_data, col_weight, col_wnum, bg_fit, store_freq
with fits.open(file_path) as hdu:
col_data = hdu[1].data
col_weight = hdu[2].data
col_wnum = hdu[3].data
bg_fit = hdu[4].data
store_freq = hdu[0].header['FFREQ']

return col_data, col_weight, col_wnum, bg_fit, store_freq


@pytest.mark.parametrize("file", ['good_col.fits', 'edge_col.fits'])
Expand Down