Skip to content

Commit 461c9ba

Browse files
JP-3923: Localize test warnings (try 2), fix test data packaging, misc test clean-ups (#9381)
2 parents 6380848 + d32c679 commit 461c9ba

File tree

69 files changed

+618
-486
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+618
-486
lines changed

jwst/assign_mtwcs/tests/data/__init__.py

Whitespace-only changes.

jwst/assign_mtwcs/tests/test_mtwcs.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import os
2-
1+
from astropy.utils.data import get_pkg_data_filename
32
from stdatamodels.jwst import datamodels
43

54
from jwst.datamodels import ModelLibrary
65
from jwst.assign_mtwcs import AssignMTWcsStep
7-
from jwst.assign_mtwcs.tests import data
8-
9-
data_path = os.path.split(os.path.abspath(data.__file__))[0]
106

117

128
def test_mt_multislit():
13-
file_path = os.path.join(data.__path__[0], 'test_mt_asn.json')
9+
file_path = get_pkg_data_filename(
10+
"data/test_mt_asn.json", package="jwst.assign_mtwcs.tests")
1411
with datamodels.open(file_path) as model:
1512
assert model[0].slits[0].meta.wcs.output_frame.name == 'world'
1613
step = AssignMTWcsStep()

jwst/assign_wcs/tests/data/__init__.py

Whitespace-only changes.

jwst/assign_wcs/tests/test_nirspec.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test functions for NIRSPEC WCS - all modes.
33
"""
44
import functools
5-
import os.path
65
import shutil
76
from math import cos, sin
87

@@ -14,20 +13,16 @@
1413
from astropy.modeling import models as astmodels
1514
from astropy import table
1615
from astropy import wcs as astwcs
16+
from astropy.utils.data import get_pkg_data_filename
1717
from gwcs import wcs, wcstools
1818
from numpy.testing import assert_allclose
1919

2020
from stdatamodels.jwst import datamodels
2121
from stdatamodels.jwst.transforms import models as trmodels
2222

2323
from jwst.assign_wcs import nirspec, assign_wcs_step
24-
from jwst.assign_wcs.tests import data
2524
from jwst.assign_wcs.util import MSAFileError, in_ifu_slice
2625

27-
28-
data_path = os.path.split(os.path.abspath(data.__file__))[0]
29-
30-
3126
wcs_kw = {'wcsaxes': 2, 'ra_ref': 165, 'dec_ref': 54,
3227
'v2_ref': -8.3942412, 'v3_ref': -5.3123744, 'roll_ref': 37,
3328
'crpix1': 1024, 'crpix2': 1024,
@@ -36,13 +31,11 @@
3631
'pc1_1': 1, 'pc1_2': 0, 'pc2_1': 0, 'pc2_2': 1
3732
}
3833

39-
4034
slit_fields_num = ["shutter_id", "dither_position", "xcen", "ycen",
4135
"ymin", "ymax", "quadrant", "source_id",
4236
"stellarity", "source_xpos", "source_ypos",
4337
"slit_xscale", "slit_yscale"]
4438

45-
4639
slit_fields_str = ["name", "shutter_state", "source_name", "source_alias"]
4740

4841

@@ -53,13 +46,6 @@ def _compare_slits(s1, s2):
5346
assert getattr(s1, f) == getattr(s2, f)
5447

5548

56-
def get_file_path(filename):
57-
"""
58-
Construct an absolute path.
59-
"""
60-
return os.path.join(data_path, filename)
61-
62-
6349
def create_hdul(detector='NRS1'):
6450
"""
6551
Create a fits HDUList instance.
@@ -109,7 +95,8 @@ def create_nirspec_mos_file(grating='G235M', filt='F170LP'):
10995
image[0].header['grating'] = grating
11096
image[0].header['PATT_NUM'] = 1
11197

112-
msa_status_file = get_file_path('SPCB-GD-A.msa.fits.gz')
98+
msa_status_file = get_pkg_data_filename(
99+
"data/SPCB-GD-A.msa.fits.gz", package="jwst.assign_wcs.tests")
113100
image[0].header['MSAMETFL'] = msa_status_file
114101
return image
115102

@@ -203,7 +190,7 @@ def test_nirspec_ifu_against_esa(wcs_ifu_grating):
203190
"""
204191
Test Nirspec IFU mode using CV3 reference files.
205192
"""
206-
with fits.open(get_file_path('Trace_IFU_Slice_00_SMOS-MOD-G1M-17-5344175105_30192_JLAB88.fits')) as ref:
193+
with fits.open(get_pkg_data_filename("data/Trace_IFU_Slice_00_SMOS-MOD-G1M-17-5344175105_30192_JLAB88.fits", package="jwst.assign_wcs.tests")) as ref:
207194
# Test NRS1
208195
pyw = astwcs.WCS(ref['SLITY1'].header)
209196
# Test evaluating the WCS (slice 0)
@@ -245,7 +232,7 @@ def test_nirspec_fs_esa():
245232
# Test evaluating the WCS
246233
w1 = nirspec.nrs_wcs_set_input(im, "S200A1")
247234

248-
ref = fits.open(get_file_path('Trace_SLIT_A_200_1_V84600010001P0000000002101_39547_JLAB88.fits'))
235+
ref = fits.open(get_pkg_data_filename("data/Trace_SLIT_A_200_1_V84600010001P0000000002101_39547_JLAB88.fits", package="jwst.assign_wcs.tests"))
249236
pyw = astwcs.WCS(ref[1].header)
250237

251238
# get positions within the slit and the corresponding lambda
@@ -314,7 +301,8 @@ def test_msa_configuration_normal():
314301
# Test 1: Reasonably normal as well
315302
prog_id = '1234'
316303
msa_meta_id = 12
317-
msaconfl = get_file_path('msa_configuration.fits')
304+
msaconfl = get_pkg_data_filename(
305+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
318306
dither_position = 1
319307
slitlet_info = nirspec.get_open_msa_slits(prog_id, msaconfl, msa_meta_id, dither_position,
320308
slit_y_range=[-.5, .5])
@@ -327,7 +315,8 @@ def test_msa_configuration_normal():
327315
def test_msa_configuration_slit_scales():
328316
prog_id = '1234'
329317
msa_meta_id = 12
330-
msaconfl = get_file_path('msa_configuration.fits')
318+
msaconfl = get_pkg_data_filename(
319+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
331320
dither_position = 1
332321

333322
# mock slit scale for quadrant 4
@@ -346,7 +335,8 @@ def test_msa_configuration_no_background():
346335
# Test 2: Two main shutters, not allowed and should fail
347336
prog_id = '1234'
348337
msa_meta_id = 13
349-
msaconfl = get_file_path('msa_configuration.fits')
338+
msaconfl = get_pkg_data_filename(
339+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
350340
dither_position = 1
351341
with pytest.raises(MSAFileError):
352342
nirspec.get_open_msa_slits(prog_id, msaconfl, msa_meta_id, dither_position,
@@ -361,7 +351,8 @@ def test_msa_configuration_all_background():
361351
# Test 3: No non-background, not acceptable.
362352
prog_id = '1234'
363353
msa_meta_id = 14
364-
msaconfl = get_file_path('msa_configuration.fits')
354+
msaconfl = get_pkg_data_filename(
355+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
365356
dither_position = 1
366357
slitlet_info = nirspec.get_open_msa_slits(prog_id, msaconfl, msa_meta_id, dither_position,
367358
slit_y_range=[-.5, .5])
@@ -378,7 +369,8 @@ def test_msa_configuration_row_skipped():
378369
# Test 4: One row is skipped, should be acceptable.
379370
prog_id = '1234'
380371
msa_meta_id = 15
381-
msaconfl = get_file_path('msa_configuration.fits')
372+
msaconfl = get_pkg_data_filename(
373+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
382374
dither_position = 1
383375
slitlet_info = nirspec.get_open_msa_slits(prog_id, msaconfl, msa_meta_id, dither_position,
384376
slit_y_range=[-.5, .5])
@@ -395,7 +387,8 @@ def test_msa_configuration_multiple_returns():
395387
# Test 4: One row is skipped, should be acceptable.
396388
prog_id = '1234'
397389
msa_meta_id = 16
398-
msaconfl = get_file_path('msa_configuration.fits')
390+
msaconfl = get_pkg_data_filename(
391+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
399392
dither_position = 1
400393
slitlet_info = nirspec.get_open_msa_slits(prog_id, msaconfl, msa_meta_id, dither_position,
401394
slit_y_range=[-.5, .5])
@@ -415,7 +408,8 @@ def test_msa_fs_configuration():
415408
"""
416409
prog_id = '1234'
417410
msa_meta_id = 12
418-
msaconfl = get_file_path('msa_fs_configuration.fits')
411+
msaconfl = get_pkg_data_filename(
412+
"data/msa_fs_configuration.fits", package="jwst.assign_wcs.tests")
419413
dither_position = 1
420414
slitlet_info = nirspec.get_open_msa_slits(
421415
prog_id, msaconfl, msa_meta_id, dither_position, slit_y_range=[-.5, .5])
@@ -448,7 +442,8 @@ def test_msa_fs_configuration_unsupported(tmp_path):
448442
Test the get_open_msa_slits function with unsupported FS defined.
449443
"""
450444
# modify an existing MSA file to add a bad row
451-
msaconfl = get_file_path('msa_fs_configuration.fits')
445+
msaconfl = get_pkg_data_filename(
446+
"data/msa_fs_configuration.fits", package="jwst.assign_wcs.tests")
452447
bad_confl = str(tmp_path / 'bad_msa_fs_configuration.fits')
453448
shutil.copy(msaconfl, bad_confl)
454449

@@ -472,7 +467,8 @@ def test_msa_missing_source(tmp_path):
472467
Test the get_open_msa_slits function with missing source information.
473468
"""
474469
# modify an existing MSA file to remove source info
475-
msaconfl = get_file_path('msa_fs_configuration.fits')
470+
msaconfl = get_pkg_data_filename(
471+
"data/msa_fs_configuration.fits", package="jwst.assign_wcs.tests")
476472
bad_confl = str(tmp_path / 'bad_msa_fs_configuration.fits')
477473
shutil.copy(msaconfl, bad_confl)
478474

@@ -510,7 +506,8 @@ def test_msa_nan_source_posn(tmp_path):
510506
Test the get_open_msa_slits function with nan values for source position.
511507
"""
512508
# modify an existing MSA file to remove source info
513-
msaconfl = get_file_path('msa_fs_configuration.fits')
509+
msaconfl = get_pkg_data_filename(
510+
"data/msa_fs_configuration.fits", package="jwst.assign_wcs.tests")
514511
bad_confl = str(tmp_path / 'nan_msa_fs_configuration.fits')
515512
shutil.copy(msaconfl, bad_confl)
516513

@@ -599,7 +596,8 @@ def test_open_slits():
599596
"""
600597
image = create_nirspec_mos_file()
601598
model = datamodels.ImageModel(image)
602-
msaconfl = get_file_path('msa_configuration.fits')
599+
msaconfl = get_pkg_data_filename(
600+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
603601

604602
model.meta.instrument.msa_metadata_file = msaconfl
605603
model.meta.instrument.msa_metadata_id = 12
@@ -614,7 +612,8 @@ def test_shutter_size_on_sky():
614612
"""
615613
image = create_nirspec_mos_file()
616614
model = datamodels.ImageModel(image)
617-
msaconfl = get_file_path('msa_configuration.fits')
615+
msaconfl = get_pkg_data_filename(
616+
"data/msa_configuration.fits", package="jwst.assign_wcs.tests")
618617

619618
model.meta.instrument.msa_metadata_file = msaconfl
620619
model.meta.instrument.msa_metadata_id = 12
@@ -676,7 +675,8 @@ def test_functional_fs_msa(mode):
676675
im.meta.wcs = w
677676
slit_wcs = nirspec.nrs_wcs_set_input(im, 1)
678677

679-
ins_file = get_file_path(model_file)
678+
ins_file = get_pkg_data_filename(
679+
f"data/{model_file}", package="jwst.assign_wcs.tests")
680680
ins_tab = table.Table.read(ins_file, format='ascii')
681681

682682
# Setup the test
@@ -791,7 +791,8 @@ def test_functional_ifu_grating(wcs_ifu_grating):
791791
im, refs = wcs_ifu_grating('G395H', 'F290LP', gwa_xtil=0.35986012, gwa_ytil=0.13448857)
792792

793793
slit_wcs = nirspec.nrs_wcs_set_input(im, 0) # use slice 0
794-
ins_file = get_file_path(model_file)
794+
ins_file = get_pkg_data_filename(
795+
f"data/{model_file}", package="jwst.assign_wcs.tests")
795796
ins_tab = table.Table.read(ins_file, format='ascii')
796797
slitx = [0] * 5
797798
slity = [-.5, -.25, 0, .25, .5]
@@ -952,7 +953,8 @@ def test_functional_ifu_prism():
952953
w = wcs.WCS(pipeline)
953954
im.meta.wcs = w
954955
slit_wcs = nirspec.nrs_wcs_set_input(im, 0) # use slice 0
955-
ins_file = get_file_path(model_file)
956+
ins_file = get_pkg_data_filename(
957+
f"data/{model_file}", package="jwst.assign_wcs.tests")
956958
ins_tab = table.Table.read(ins_file, format='ascii')
957959
slitx = [0] * 5
958960
slity = [-.5, -.25, 0, .25, .5]

jwst/assign_wcs/tests/test_util.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
"""
22
Test the utility functions
33
"""
4-
5-
import os
6-
74
from astropy.modeling.models import Shift, Identity
85
from astropy.table import QTable
9-
6+
from astropy.utils.data import get_pkg_data_filename
107
from stdatamodels.jwst import datamodels
118

129
from jwst.lib.catalog_utils import SkyObject
@@ -16,17 +13,6 @@
1613
bounding_box_from_subarray, transform_bbox_from_shape
1714
)
1815

19-
from jwst.assign_wcs.tests import data
20-
21-
data_path = os.path.split(os.path.abspath(data.__file__))[0]
22-
23-
24-
def get_file_path(filename):
25-
"""
26-
Construct an absolute path.
27-
"""
28-
return os.path.join(data_path, filename)
29-
3016

3117
def test_transform_bbox_from_shape_2d():
3218
model = datamodels.ImageModel((512, 2048))
@@ -61,7 +47,8 @@ def read_catalog(catalogname):
6147

6248

6349
def test_create_grism_objects():
64-
source_catalog = get_file_path('step_SourceCatalogStep_cat.ecsv')
50+
source_catalog = get_pkg_data_filename(
51+
"data/step_SourceCatalogStep_cat.ecsv", package="jwst.assign_wcs.tests")
6552

6653
# create from test ascii file
6754
grism_objects = read_catalog(source_catalog)

jwst/assign_wcs/tests/test_wfss.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
import os.path
21
import numpy as np
2+
import pytest
33
from numpy.testing import assert_allclose
4-
54
from astropy.modeling.models import (Polynomial1D, Polynomial2D, Shift,
65
Const1D, Mapping)
76
from gwcs import wcs
87
from gwcs.wcstools import grid_from_bounding_box
9-
108
from stdatamodels.jwst.datamodels import SlitModel
119
from stdatamodels.jwst.transforms import models as transforms
1210

1311
from jwst.extract_2d.grisms import compute_wfss_wavelength
1412

15-
import pytest
16-
17-
from jwst.assign_wcs.tests import data
18-
data_path = os.path.split(os.path.abspath(data.__file__))[0]
19-
2013

2114
def create_nircam_slit(model, x0, y0, order):
2215
""" Create a SlitModel representing a grism slit."""

jwst/associations/tests/test_dms.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
"""Test DMSBaseMixin features"""
22
import inspect
3-
from os import path
4-
import pytest
53
import re
64

7-
from jwst.associations.tests.helpers import (
8-
t_path
9-
)
5+
import pytest
6+
from astropy.utils.data import get_pkg_data_filename
107

118
from jwst.associations import AssociationRegistry
129

1310

1411
@pytest.fixture(scope='module')
1512
def dms_registry():
1613
"""Create the registry"""
17-
dms_test_rules_path = t_path(path.join('data', 'dms_rules.py'))
14+
dms_test_rules_path = get_pkg_data_filename(
15+
"data/dms_rules.py", package="jwst.associations.tests")
1816
dms_registry = AssociationRegistry(
1917
[dms_test_rules_path], include_default=False
2018
)
@@ -69,7 +67,8 @@ def test_finalize(dms_registry, dms_asns):
6967

7068
def test_include_bases():
7169
"""Test for included bases"""
72-
dms_test_rules_path = t_path(path.join('data', 'dms_rules.py'))
70+
dms_test_rules_path = get_pkg_data_filename(
71+
"data/dms_rules.py", package="jwst.associations.tests")
7372
dms_registry = AssociationRegistry(
7473
[dms_test_rules_path], include_default=False, include_bases=True
7574
)

jwst/associations/tests/test_generate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test basic generate operations"""
22

3-
from jwst.associations.tests.helpers import t_path
3+
from astropy.utils.data import get_pkg_data_filename
44

55
from jwst.associations import (
66
AssociationPool,
@@ -13,7 +13,7 @@
1313
def test_simple():
1414
"""Test generate on simple registry"""
1515
registry = AssociationRegistry(
16-
[t_path('data/rules_basic.py')],
16+
[get_pkg_data_filename("data/rules_basic.py", package="jwst.associations.tests")],
1717
include_default=False
1818
)
1919
pool = AssociationPool()
@@ -26,8 +26,8 @@ def test_simple():
2626

2727
def test_unserialize():
2828
"""Test basic unserializing"""
29-
asn_file = t_path(
30-
'data/asn_mosaic.json'
29+
asn_file = get_pkg_data_filename(
30+
"data/asn_mosaic.json", package="jwst.associations.tests"
3131
)
3232
with open(asn_file, 'r') as asn_fp:
3333
asn = load_asn(asn_fp)

jwst/background/tests/data/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)