From cf22f64ff4cac6610f0186d510008ae86eec3d28 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Fri, 1 Mar 2024 17:11:55 -0500 Subject: [PATCH 01/16] JP-3552: updated pytest to use tmp_path instead of tmpdir --- docs/conftest.py | 10 ++++--- jwst/assign_wcs/tests/test_schemas.py | 5 ++-- jwst/assign_wcs/tests/test_wcs.py | 13 +++++----- jwst/associations/tests/test_asn_from_list.py | 26 ++++++++++--------- jwst/associations/tests/test_pool.py | 7 ++--- jwst/background/tests/test_background.py | 6 ++--- jwst/conftest.py | 4 +-- jwst/cube_build/tests/test_cube_build_step.py | 7 ++--- jwst/cube_build/tests/test_miri_cubepars.py | 7 ++--- .../cube_build/tests/test_nirspec_cubepars.py | 7 ++--- .../exp_to_source/tests/test_exp_to_source.py | 4 +-- jwst/exp_to_source/tests/test_main.py | 4 +-- .../extract_1d/tests/test_apply_apcorr_ifu.py | 13 +++++----- jwst/jump/tests/test_jump_step.py | 13 +++++----- jwst/lib/tests/test_velocity_aberration.py | 7 +++-- .../tests/test_master_background.py | 7 ++--- jwst/ramp_fitting/tests/test_ramp_fit_step.py | 7 ++--- jwst/regtest/test_infrastructure.py | 12 ++++----- jwst/scripts/okify_regtests.py | 6 ++--- jwst/skymatch/skyimage.py | 4 +-- jwst/skymatch/tests/test_skymatch.py | 20 +++++++------- jwst/stpipe/tests/test_step.py | 6 ++--- pyproject.toml | 5 +++- 23 files changed, 111 insertions(+), 89 deletions(-) diff --git a/docs/conftest.py b/docs/conftest.py index 179de8ddeb..a124f5f63b 100644 --- a/docs/conftest.py +++ b/docs/conftest.py @@ -1,4 +1,6 @@ import pytest +import os + @pytest.fixture(autouse=True) def _docdir(request): @@ -6,8 +8,10 @@ def _docdir(request): # Trigger ONLY for doctestplus. doctest_plugin = request.config.pluginmanager.getplugin("doctestplus") if isinstance(request.node.parent, doctest_plugin._doctest_textfile_item_cls): - tmpdir = request.getfixturevalue('tmpdir') - with tmpdir.as_cwd(): - yield + tmp_path = request.getfixturevalue('tmp_path') + old_cwd = os.getcwd() + os.chdir(tmp_path) + yield + os.chdir(old_cwd) else: yield diff --git a/jwst/assign_wcs/tests/test_schemas.py b/jwst/assign_wcs/tests/test_schemas.py index e20fe3a860..bb49f0f6ed 100644 --- a/jwst/assign_wcs/tests/test_schemas.py +++ b/jwst/assign_wcs/tests/test_schemas.py @@ -1,5 +1,6 @@ import inspect import sys +import os import warnings from astropy.modeling import models @@ -47,9 +48,9 @@ def distortion_model(): return dist -def test_distortion_schema(distortion_model, tmpdir): +def test_distortion_schema(distortion_model, tmp_path): """Make sure DistortionModel roundtrips""" - path = str(tmpdir.join("test_dist.asdf")) + path = os.path.join(tmp_path, "test_dist.asdf") dist = distortion_model dist.save(path) diff --git a/jwst/assign_wcs/tests/test_wcs.py b/jwst/assign_wcs/tests/test_wcs.py index 433fcf2106..8a9fea4987 100644 --- a/jwst/assign_wcs/tests/test_wcs.py +++ b/jwst/assign_wcs/tests/test_wcs.py @@ -1,4 +1,5 @@ import pytest +import os from numpy import zeros from numpy.testing import assert_allclose @@ -143,7 +144,7 @@ def test_v23_to_sky(): assert_allclose(radec, expected_ra_dec, atol=1e-10) -def test_frame_from_model_3d(tmpdir, create_model_3d): +def test_frame_from_model_3d(tmp_path, create_model_3d): """ Tests creating a frame from a data model. """ # Test CompositeFrame initialization (celestial and spectral) im = create_model_3d @@ -163,7 +164,7 @@ def test_frame_from_model_3d(tmpdir, create_model_3d): assert frame.frames[1].axes_names == ('ALPHA1A', 'BETA1A') -def test_frame_from_model_2d(tmpdir, create_model_2d): +def test_frame_from_model_2d(tmp_path, create_model_2d): """ Tests creating a frame from a data model. """ # Test 2D spatial custom frame im = create_model_2d @@ -173,13 +174,13 @@ def test_frame_from_model_2d(tmpdir, create_model_2d): assert frame.axes_names == ("RA", "DEC") -def test_create_fitswcs(tmpdir, create_model_3d): +def test_create_fitswcs(tmp_path, create_model_3d): """GWCS from create_fitswcs function and astropy.wcs give same result""" im = create_model_3d w3d = pointing.create_fitswcs(im) gra, gdec, glam = w3d(1, 1, 1) - path = str(tmpdir.join("fitswcs.fits")) + path = os.path.join(tmp_path, "fitswcs.fits") im.save(path) with fits.open(path) as hdulist: hdu = hdulist["SCI"] @@ -191,7 +192,7 @@ def test_create_fitswcs(tmpdir, create_model_3d): assert_allclose((ra, dec), (gra, gdec)) -def test_sip_approx(tmpdir): +def test_sip_approx(tmp_path): # some of the wcs info true_wcs = { 'ctype1': 'RA---TAN-SIP', @@ -274,7 +275,7 @@ def test_sip_approx(tmpdir): assert_allclose(fitswcs_res.dec.deg, gwcs_dec, atol=1.5e-6) # now write the file out, read it back in, and check that the fit values are preserved - path = str(tmpdir.join("tmp_sip_wcs.fits")) + path = os.path.join(tmp_path, "tmp_sip_wcs.fits") result.write(path) with open(path) as result_read: diff --git a/jwst/associations/tests/test_asn_from_list.py b/jwst/associations/tests/test_asn_from_list.py index 07e054f420..dbc9eefe9a 100644 --- a/jwst/associations/tests/test_asn_from_list.py +++ b/jwst/associations/tests/test_asn_from_list.py @@ -28,6 +28,7 @@ def test_level2(): assert name.startswith('jwnoprogram-o999_none') assert isinstance(serialized, str) + def test_level2_tuple(): """Test level 2 association when passing in a tuple""" items = [('file_1.fits', 'science'), ('file_2.fits', 'background'), @@ -48,6 +49,7 @@ def test_level2_tuple(): if not items[3][1]: assert product['members'][0]['exptype'] == 'science' + def test_file_ext(): """check that the filename extension is correctly appended""" items = ['a', 'b', 'c'] @@ -63,18 +65,18 @@ def test_file_ext(): assert name.endswith('yaml') -def test_level2_from_cmdline(tmpdir): +def test_level2_from_cmdline(tmp_path): """Create a level2 association from the command line""" rule = 'DMSLevel2bBase' - path = tmpdir.join('test_asn.json') + path = os.path.join(tmp_path, 'test_asn.json') inlist = ['a', 'b', 'c'] args = [ - '-o', path.strpath, + '-o', path, '-r', rule, ] args = args + inlist Main.cli(args) - with open(path.strpath, 'r') as fp: + with open(path, 'r') as fp: asn = load_asn(fp, registry=AssociationRegistry(include_bases=True)) assert asn['asn_rule'] == 'DMSLevel2bBase' assert asn['asn_type'] == 'None' @@ -195,19 +197,19 @@ def test_cmdline_fails(): "format", ['json', 'yaml'] ) -def test_cmdline_success(format, tmpdir): +def test_cmdline_success(format, tmp_path): """Create Level3 associations in different formats""" - path = tmpdir.join('test_asn.json') + path = os.path.join(tmp_path, 'test_asn.json') product_name = 'test_product' inlist = ['a', 'b', 'c'] args = [ - '-o', path.strpath, + '-o', path, '--product-name', product_name, '--format', format ] args = args + inlist Main.cli(args) - with open(path.strpath, 'r') as fp: + with open(path, 'r') as fp: asn = load_asn(fp, format=format) assert len(asn['products']) == 1 assert asn['products'][0]['name'] == product_name @@ -219,18 +221,18 @@ def test_cmdline_success(format, tmpdir): assert inlist == expnames -def test_cmdline_change_rules(tmpdir): +def test_cmdline_change_rules(tmp_path): """Command line change the rule""" rule = 'Association' - path = tmpdir.join('test_asn.json') + path = os.path.join(tmp_path, 'test_asn.json') inlist = ['a', 'b', 'c'] args = [ - '-o', path.strpath, + '-o', path, '-r', rule, ] args = args + inlist Main.cli(args) - with open(path.strpath, 'r') as fp: + with open(path, 'r') as fp: asn = load_asn(fp, registry=AssociationRegistry(include_bases=True)) assert inlist == asn['members'] diff --git a/jwst/associations/tests/test_pool.py b/jwst/associations/tests/test_pool.py index bb00133e6a..f666f69f45 100644 --- a/jwst/associations/tests/test_pool.py +++ b/jwst/associations/tests/test_pool.py @@ -1,15 +1,16 @@ +import os from jwst.associations.tests.helpers import t_path - from jwst.associations import AssociationPool POOL_FILE = t_path('data/jw93060_20150312T160130_pool.csv') -def test_pool(tmpdir): +def test_pool(tmp_path_factory): pool = AssociationPool.read(POOL_FILE) assert len(pool) == 636 - tmp_pool = str(tmpdir.mkdir(__name__).join('tmp_pool.csv')) + tmp_path = tmp_path_factory.mktemp(__name__) + tmp_pool = os.path.join(tmp_path, 'tmp_pool.csv') pool.write(tmp_pool) roundtrip = AssociationPool.read(tmp_pool) diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index 1d67e6dee0..96eff5f350 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -26,11 +26,11 @@ def get_file_path(filename): @pytest.fixture(scope='module') -def background(tmpdir_factory): +def background(tmp_path_factory): """Generate a background image to feed to background step""" - filename = tmpdir_factory.mktemp('background_input') - filename = str(filename.join('background.fits')) + filename = tmp_path_factory.mktemp('background_input') + filename = os.path.join(filename, 'background.fits') with datamodels.IFUImageModel((10, 10)) as image: image.data[:, :] = 10 image.meta.instrument.name = 'NIRSPEC' diff --git a/jwst/conftest.py b/jwst/conftest.py index 30a78f0390..67c1f472e2 100644 --- a/jwst/conftest.py +++ b/jwst/conftest.py @@ -52,7 +52,7 @@ def slow(request): @pytest.fixture(scope="module") -def jail(request, tmpdir_factory): +def jail(request, tmp_path_factory): """Run test in a pristine temporary working directory, scoped to module. This fixture is the same as _jail in ci_watson, but scoped to module @@ -63,7 +63,7 @@ def jail(request, tmpdir_factory): path = request.module.__name__.split('.')[-1] if request._parent_request.fixturename is not None: path = path + "_" + request._parent_request.fixturename - newpath = tmpdir_factory.mktemp(path) + newpath = tmp_path_factory.mktemp(path) os.chdir(str(newpath)) yield newpath os.chdir(old_dir) diff --git a/jwst/cube_build/tests/test_cube_build_step.py b/jwst/cube_build/tests/test_cube_build_step.py index 3d318fae4a..de06fc29ec 100644 --- a/jwst/cube_build/tests/test_cube_build_step.py +++ b/jwst/cube_build/tests/test_cube_build_step.py @@ -5,6 +5,7 @@ import numpy as np import pytest from astropy.io import fits +import os from gwcs import WCS from stdatamodels.jwst.datamodels import IFUImageModel @@ -16,11 +17,11 @@ @pytest.fixture(scope='module') -def miri_cube_pars(tmpdir_factory): +def miri_cube_pars(tmp_path_factory): """ Set up the miri cube pars reference file """ - filename = tmpdir_factory.mktemp('cube_pars') - filename = str(filename.join('miri_cube_pars.fits')) + filename = tmp_path_factory.mktemp('cube_pars') + filename = os.path.join(filename, 'miri_cube_pars.fits') hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'MIRI' diff --git a/jwst/cube_build/tests/test_miri_cubepars.py b/jwst/cube_build/tests/test_miri_cubepars.py index e3a65024e8..49cfac59c8 100644 --- a/jwst/cube_build/tests/test_miri_cubepars.py +++ b/jwst/cube_build/tests/test_miri_cubepars.py @@ -5,6 +5,7 @@ import numpy as np import pytest import math +import os from astropy.io import fits from jwst.cube_build import ifu_cube from jwst.cube_build import cube_build_io_util @@ -12,11 +13,11 @@ @pytest.fixture(scope='module') -def miri_cube_pars(tmpdir_factory): +def miri_cube_pars(tmp_path_factory): """ Set up the miri cube pars reference file """ - filename = tmpdir_factory.mktemp('cube_pars') - filename = str(filename.join('miri_cube_pars.fits')) + filename = tmp_path_factory.mktemp('cube_pars') + filename = os.path.join(filename, 'miri_cube_pars.fits') hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'MIRI' diff --git a/jwst/cube_build/tests/test_nirspec_cubepars.py b/jwst/cube_build/tests/test_nirspec_cubepars.py index 978e3f0d92..7241e78d3d 100644 --- a/jwst/cube_build/tests/test_nirspec_cubepars.py +++ b/jwst/cube_build/tests/test_nirspec_cubepars.py @@ -9,14 +9,15 @@ from jwst.cube_build import ifu_cube from jwst.cube_build import cube_build_io_util from jwst.cube_build import instrument_defaults +import os @pytest.fixture(scope='module') -def nirspec_cube_pars(tmpdir_factory): +def nirspec_cube_pars(tmp_path_factory): """ Set up the nirspec cube pars reference file """ - filename = tmpdir_factory.mktemp('cube_pars') - filename = str(filename.join('nirspec_cube_pars.fits')) + filename = tmp_path_factory.mktemp('cube_pars') + filename = os.path.join(filename, 'nirspec_cube_pars.fits') hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'NIRSPEC' diff --git a/jwst/exp_to_source/tests/test_exp_to_source.py b/jwst/exp_to_source/tests/test_exp_to_source.py index e3abec1c6d..b3f4060dee 100644 --- a/jwst/exp_to_source/tests/test_exp_to_source.py +++ b/jwst/exp_to_source/tests/test_exp_to_source.py @@ -34,10 +34,10 @@ def test_model_structure(run_exp_to_source): assert outputs[str(slit.source_id)].meta.filename != in_model.meta.filename -def test_model_roundtrip(tmpdir, run_exp_to_source): +def test_model_roundtrip(tmp_path, run_exp_to_source): inputs, outputs = run_exp_to_source files = [] - path = str(tmpdir) + path = str(tmp_path) for output in outputs: file_path = os.path.join(path, output) + '.fits' outputs[output].save(file_path) diff --git a/jwst/exp_to_source/tests/test_main.py b/jwst/exp_to_source/tests/test_main.py index a71bce6f7c..fe4c84605c 100644 --- a/jwst/exp_to_source/tests/test_main.py +++ b/jwst/exp_to_source/tests/test_main.py @@ -11,8 +11,8 @@ def test_help(capsys): assert out.startswith('usage:') -def test_default_run(tmpdir, capsys): - path = str(tmpdir) +def test_default_run(tmp_path, capsys): + path = str(tmp_path) args = [ '-o', path diff --git a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py index 6172b3870e..ea5551932a 100644 --- a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py +++ b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py @@ -1,6 +1,7 @@ import pytest import numpy as np from asdf import AsdfFile +import os from stdatamodels.jwst.datamodels import IFUCubeModel, NrsIfuApcorrModel, MirMrsApcorrModel @@ -8,10 +9,10 @@ @pytest.fixture(scope='module') -def dummy_nirspec_ref(tmpdir_factory): +def dummy_nirspec_ref(tmp_path_factory): """ Generate a dummy apcorr ref file """ - filename = tmpdir_factory.mktemp('dummy_apcorr') - filename = str(filename.join('dummy_nirspec_apcorr.asdf')) + filename = tmp_path_factory.mktemp('dummy_apcorr') + filename = os.path.join(filename, 'dummy_nirspec_apcorr.asdf') refap = {} refap['meta'] = {} @@ -51,10 +52,10 @@ def dummy_nirspec_ref(tmpdir_factory): @pytest.fixture(scope='module') -def dummy_miri_ref(tmpdir_factory): +def dummy_miri_ref(tmp_path_factory): """ Generate a dummy apcorr ref file """ - filename = tmpdir_factory.mktemp('dummy_apcorr') - filename = str(filename.join('dummy_miri_apcorr.asdf')) + filename = tmp_path_factory.mktemp('dummy_apcorr') + filename = os.path.join(filename, 'dummy_miri_apcorr.asdf') refap = {} refap['meta'] = {} diff --git a/jwst/jump/tests/test_jump_step.py b/jwst/jump/tests/test_jump_step.py index acdf0fad42..6e76007fcd 100644 --- a/jwst/jump/tests/test_jump_step.py +++ b/jwst/jump/tests/test_jump_step.py @@ -2,6 +2,7 @@ import numpy as np import pytest +import os from stdatamodels.jwst.datamodels import GainModel, ReadnoiseModel, RampModel @@ -11,12 +12,12 @@ @pytest.fixture(scope="module") -def generate_miri_reffiles(tmpdir_factory): +def generate_miri_reffiles(tmp_path_factory): def _generate_miri_reffiles(xsize=103, ysize=102, ingain=6): - gainfile = str(tmpdir_factory.mktemp("data").join("gain.fits")) - readnoisefile = str(tmpdir_factory.mktemp("data").join('readnoise.fits')) + gainfile = os.path.join(tmp_path_factory.mktemp("data"), "gain.fits") + readnoisefile = os.path.join(tmp_path_factory.mktemp("data"), 'readnoise.fits') ingain = ingain xsize = xsize @@ -49,11 +50,11 @@ def _generate_miri_reffiles(xsize=103, ysize=102, ingain=6): @pytest.fixture(scope="module") -def generate_nircam_reffiles(tmpdir_factory): +def generate_nircam_reffiles(tmp_path_factory): def _generate_nircam_reffiles(xsize=20, ysize=20, ingain=6): - gainfile = str(tmpdir_factory.mktemp("ndata").join("gain.fits")) - readnoisefile = str(tmpdir_factory.mktemp("ndata").join('readnoise.fits')) + gainfile = os.path.join(tmp_path_factory.mktemp("ndata"), "gain.fits") + readnoisefile = os.path.join(tmp_path_factory.mktemp("ndata"), 'readnoise.fits') ingain = ingain xsize = xsize diff --git a/jwst/lib/tests/test_velocity_aberration.py b/jwst/lib/tests/test_velocity_aberration.py index 8cbed1d3f2..3c921fb2e3 100644 --- a/jwst/lib/tests/test_velocity_aberration.py +++ b/jwst/lib/tests/test_velocity_aberration.py @@ -2,6 +2,8 @@ Test script for set_velocity_aberration.py """ import subprocess +import os + from numpy import isclose from astropy.io import fits import jwst.datamodels as dm @@ -29,9 +31,10 @@ def test_compute_va_effects_zero_velocity(): assert isclose(va_dec, GOOD_POS[1], atol=1e-16) -def test_velocity_aberration_script(tmpdir): +def test_velocity_aberration_script(tmp_path): """Test the whole script on a FITS file""" - path = str(tmpdir.join("velocity_aberration_tmpfile.fits")) + + path = os.path.join(tmp_path, "velocity_aberration_tmpfile.fits") model = dm.ImageModel() model.meta.ephemeris.velocity_x_bary = GOOD_VELOCITY[0] model.meta.ephemeris.velocity_y_bary = GOOD_VELOCITY[1] diff --git a/jwst/master_background/tests/test_master_background.py b/jwst/master_background/tests/test_master_background.py index 43853f1f58..7a21bbd940 100644 --- a/jwst/master_background/tests/test_master_background.py +++ b/jwst/master_background/tests/test_master_background.py @@ -4,6 +4,7 @@ import numpy as np import pytest import json +import os from stdatamodels.jwst import datamodels @@ -17,11 +18,11 @@ @pytest.fixture(scope='module') -def user_background(tmpdir_factory): +def user_background(tmp_path_factory): """Generate a user background spectrum""" - filename = tmpdir_factory.mktemp('master_background_user_input') - filename = str(filename.join('user_background.fits')) + filename = tmp_path_factory.mktemp('master_background_user_input') + filename = os.path.join(filename, 'user_background.fits') wavelength = np.linspace(0.5, 25, num=100) flux = np.linspace(2.0, 2.2, num=100) data = create_background(wavelength, flux) diff --git a/jwst/ramp_fitting/tests/test_ramp_fit_step.py b/jwst/ramp_fitting/tests/test_ramp_fit_step.py index dc2ebc1662..6e31e49e2a 100644 --- a/jwst/ramp_fitting/tests/test_ramp_fit_step.py +++ b/jwst/ramp_fitting/tests/test_ramp_fit_step.py @@ -1,5 +1,6 @@ import pytest import numpy as np +import os from stdatamodels.jwst.datamodels import dqflags, RampModel, GainModel, ReadnoiseModel @@ -179,10 +180,10 @@ def test_ramp_fit_step(generate_miri_reffiles, setup_inputs, max_cores): assert slopes.meta.cal_step.ramp_fit == "COMPLETE" -def test_subarray_5groups(tmpdir_factory): +def test_subarray_5groups(tmp_path_factory): # all pixel values are zero. So slope should be zero - gainfile = str(tmpdir_factory.mktemp("data").join("gain.fits")) - readnoisefile = str(tmpdir_factory.mktemp("data").join('readnoise.fits')) + gainfile = os.path.join(tmp_path_factory.mktemp("data"), "gain.fits") + readnoisefile = os.path.join(tmp_path_factory.mktemp("data"), 'readnoise.fits') model1, gdq, rnModel, pixdq, err, gain = setup_subarray_inputs( ngroups=5, subxstart=10, subystart=20, subxsize=5, subysize=15, readnoise=50) diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index 154220f0cc..0f44d3dfe5 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -39,10 +39,10 @@ def test_fitsdiff_defaults(fitsdiff_default_kwargs): @pytest.fixture -def two_tables(tmpdir): +def two_tables(tmp_path): """Return identical astropy tables written to 2 .ecsv file paths""" - path1 = str(tmpdir.join("catalog1.ecsv")) - path2 = str(tmpdir.join("catalog2.ecsv")) + path1 = os.path.join(tmp_path, "catalog1.ecsv") + path2 = os.path.join(tmp_path, "catalog2.ecsv") a = np.array([1, 4, 5], dtype=float) b = [2.0, 5.0, 8.5] c = ['x', 'y', 'z'] @@ -133,9 +133,9 @@ def test_diff_astropy_tables_all_equal(diff_astropy_tables, two_tables): assert diff_astropy_tables(path1, path2) -def test_text_diff(tmpdir): - path1 = str(tmpdir.join("test1.txt")) - path2 = str(tmpdir.join("test2.txt")) +def test_text_diff(tmp_path): + path1 = os.path.join(tmp_path, "test1.txt") + path2 = os.path.join(tmp_path, "test2.txt") with open(path1, "w") as text_file: print("foo", file=text_file) with open(path2, "w") as text_file: diff --git a/jwst/scripts/okify_regtests.py b/jwst/scripts/okify_regtests.py index 054ee98612..9c0b78ae94 100755 --- a/jwst/scripts/okify_regtests.py +++ b/jwst/scripts/okify_regtests.py @@ -156,9 +156,9 @@ def main(): name = args.job_name # Create and chdir to a temporary directory to store specfiles - with tempfile.TemporaryDirectory() as tmpdir: - print(f'Downloading test logs to {tmpdir}') - with pushd(tmpdir): + with tempfile.TemporaryDirectory() as tmp_path: + print(f'Downloading test logs to {tmp_path}') + with pushd(tmp_path): # Retrieve all the okify specfiles for failed tests. specfiles, asdffiles = artifactory_get_build_artifacts(build, name) diff --git a/jwst/skymatch/skyimage.py b/jwst/skymatch/skyimage.py index 65bc943bec..a8911b106a 100644 --- a/jwst/skymatch/skyimage.py +++ b/jwst/skymatch/skyimage.py @@ -70,14 +70,14 @@ def get_data_shape(self): class NDArrayMappedAccessor(DataAccessor): """ Data accessor for arrays stored in temporary files. """ def __init__(self, data, tmpfile=None, prefix='tmp_skymatch_', - suffix='.npy', tmpdir=''): + suffix='.npy', tmp_path=''): super().__init__() if tmpfile is None: self._close = True self._tmp = tempfile.NamedTemporaryFile( prefix=prefix, suffix=suffix, - dir=tmpdir + dir=tmp_path ) if not self._tmp: raise RuntimeError("Unable to create temporary file.") diff --git a/jwst/skymatch/tests/test_skymatch.py b/jwst/skymatch/tests/test_skymatch.py index b313cf3893..f83d3db815 100644 --- a/jwst/skymatch/tests/test_skymatch.py +++ b/jwst/skymatch/tests/test_skymatch.py @@ -363,7 +363,7 @@ def test_skymatch_overlap(nircam_rate, skymethod, subtract, skystat): assert abs(np.mean(im.data[dq_mask]) - lev) < 0.01 -def test_asn_input(nircam_rate, tmpdir): +def test_asn_input(nircam_rate, tmp_path): # This is the same test as 'test_skymatch_overlap' with # skymethod='match', subtract=True, skystat='mean' and with memory saving # feature enabled (data loaded from files as needed). @@ -393,9 +393,9 @@ def test_asn_input(nircam_rate, tmpdir): for im, lev in zip(container, levels): im.data += np.random.normal(loc=lev, scale=0.1, size=im.data.shape) - im1_path = str(tmpdir / "skymatch_im1.fits") - im2_path = str(tmpdir / "skymatch_im2.fits") - im3_path = str(tmpdir / "skymatch_im3.fits") + im1_path = str(tmp_path / "skymatch_im1.fits") + im2_path = str(tmp_path / "skymatch_im2.fits") + im3_path = str(tmp_path / "skymatch_im3.fits") im1.write(im1_path) im2.write(im2_path) @@ -407,7 +407,7 @@ def test_asn_input(nircam_rate, tmpdir): product_name='skymatch' ) asn_out_fname, out_serialized = assoc_out.dump(format='json') - asn_out_fname = str(tmpdir / asn_out_fname) + asn_out_fname = str(tmp_path / asn_out_fname) with open(asn_out_fname, "w") as asn_out: asn_out.write(out_serialized) @@ -454,7 +454,7 @@ def test_asn_input(nircam_rate, tmpdir): ) ) ) -def test_skymatch_2x(nircam_rate, tmpdir, skymethod, subtract): +def test_skymatch_2x(nircam_rate, tmp_path, skymethod, subtract): # Test that repetitive applications of skymatch produce the same results np.random.seed(1) im1 = nircam_rate.copy() @@ -477,9 +477,9 @@ def test_skymatch_2x(nircam_rate, tmpdir, skymethod, subtract): for im, lev in zip(container, levels): im.data += np.random.normal(loc=lev, scale=0.1, size=im.data.shape) - im1_path = str(tmpdir / "skymatch_im1.fits") - im2_path = str(tmpdir / "skymatch_im2.fits") - im3_path = str(tmpdir / "skymatch_im3.fits") + im1_path = str(tmp_path / "skymatch_im1.fits") + im2_path = str(tmp_path / "skymatch_im2.fits") + im3_path = str(tmp_path / "skymatch_im3.fits") im1.write(im1_path) im2.write(im2_path) @@ -491,7 +491,7 @@ def test_skymatch_2x(nircam_rate, tmpdir, skymethod, subtract): product_name='skymatch' ) asn_out_fname, out_serialized = assoc_out.dump(format='json') - asn_out_fname = str(tmpdir / asn_out_fname) + asn_out_fname = str(tmp_path / asn_out_fname) with open(asn_out_fname, "w") as asn_out: asn_out.write(out_serialized) diff --git a/jwst/stpipe/tests/test_step.py b/jwst/stpipe/tests/test_step.py index dde7088d76..b7732e6ab6 100644 --- a/jwst/stpipe/tests/test_step.py +++ b/jwst/stpipe/tests/test_step.py @@ -101,16 +101,16 @@ def test_reftype(cfg_file, expected_reftype): assert step.get_config_reftype() == expected_reftype -def test_saving_pars(tmpdir): +def test_saving_pars(tmp_path): """Save the step parameters from the commandline""" cfg_path = t_path(join('steps', 'jwst_generic_pars-makeliststep_0002.asdf')) - saved_path = tmpdir.join('savepars.asdf') + saved_path = os.path.join(tmp_path, 'savepars.asdf') step = Step.from_cmdline([ cfg_path, '--save-parameters', str(saved_path) ]) - assert saved_path.check() + assert os.path.exists(saved_path) with asdf.open(t_path(join('steps', 'jwst_generic_pars-makeliststep_0002.asdf'))) as af: original_config = StepConfig.from_asdf(af) diff --git a/pyproject.toml b/pyproject.toml index 6d6077e728..079398a84e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -232,7 +232,10 @@ results_root = "jwst-pipeline-results" text_file_format = "rst" doctest_plus = "enabled" doctest_rst = "enabled" -addopts = "--show-capture=no --report-crds-context" +addopts = ["-p no:legacypath", + "--show-capture=no", + "--report-crds-context", +] filterwarnings = [ "error::ResourceWarning", "ignore:Models in math_functions:astropy.utils.exceptions.AstropyUserWarning", From 782e2ca13171d21d94a06a9d5a85560097bef6ce Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Fri, 1 Mar 2024 17:19:44 -0500 Subject: [PATCH 02/16] added changelog entry --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 300a26e116..4e31d52cd7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -120,6 +120,9 @@ general - Remove unused asdf-transform-schemas dependency [#8337] +- Replaced all instances of pytest ``tmpdir`` and ``tmpdir_factory`` + fixtures with ``tmp_path`` and ``tmp_path_factory``. [#8327] + jump ---- From ec781649b66c8b3536bb071f5266d8947a0eb190 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Fri, 1 Mar 2024 17:32:37 -0500 Subject: [PATCH 03/16] pinning asdf oldest dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 079398a84e..188c0c9d76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ - "asdf>=2.15.1,<4", + "asdf>=3.1.0,<4", "astropy>=5.3", "BayesicFitting>=3.0.1", "crds>=11.17.14", From 717faedfc76c9866d556d20b5f1a4e02693e5702 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Mon, 4 Mar 2024 09:22:52 -0500 Subject: [PATCH 04/16] using most recent version of ci_watson --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 188c0c9d76..bb8005093d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -129,7 +129,7 @@ sdp = [ "pysiaf>=0.13.0", ] test = [ - "ci-watson>=0.5.0", + "git+https://github.com/spacetelescope/ci_watson.git@main", "colorama>=0.4.1", "readchar>=3.0", "ruff", From 41c260d89e054d6355600421b58aaca80387cd98 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Wed, 6 Mar 2024 17:15:49 -0500 Subject: [PATCH 05/16] replaced _jail with function_jail --- CHANGES.rst | 4 ++++ jwst/associations/lib/tests/test_diff.py | 2 +- jwst/associations/tests/test_main.py | 2 +- jwst/background/tests/test_background.py | 6 +++--- jwst/conftest.py | 15 +++++++++++++++ jwst/cube_build/tests/test_configuration.py | 10 +++++----- jwst/cube_build/tests/test_cube_build_step.py | 4 ++-- jwst/cube_build/tests/test_miri_cubepars.py | 6 +++--- jwst/cube_build/tests/test_nirspec_cubepars.py | 2 +- jwst/exp_to_source/tests/test_main.py | 2 +- jwst/extract_1d/tests/test_apply_apcorr_ifu.py | 2 +- .../tests/test_master_background.py | 4 ++-- jwst/mrs_imatch/tests/test_apply_background.py | 2 +- jwst/mrs_imatch/tests/test_configuration.py | 6 +++--- .../tests/test_outlier_detection.py | 12 ++++++------ jwst/regtest/conftest.py | 4 ++-- jwst/regtest/test_miri_dark.py | 4 ++-- jwst/regtest/test_miri_setpointing.py | 2 +- jwst/regtest/test_miri_spectral_leak.py | 2 +- jwst/regtest/test_nircam_tsgrism.py | 2 +- jwst/regtest/test_nircam_tsimg.py | 2 +- jwst/regtest/test_nirspec_exceptions.py | 10 +++++----- jwst/regtest/test_nirspec_image2.py | 2 +- jwst/resample/tests/test_resample_step.py | 2 +- jwst/residual_fringe/tests/test_configuration.py | 4 ++-- jwst/stpipe/tests/test_asdf_parameters.py | 2 +- jwst/stpipe/tests/test_pipeline.py | 10 +++++----- jwst/stpipe/tests/test_step.py | 2 +- jwst/straylight/tests/test_straylight_step.py | 2 +- jwst/tests/test_infrastructure.py | 2 +- jwst/wfs_combine/tests/test_wfs_combine.py | 2 +- 31 files changed, 76 insertions(+), 57 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4e31d52cd7..33863f9bc2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -123,6 +123,10 @@ general - Replaced all instances of pytest ``tmpdir`` and ``tmpdir_factory`` fixtures with ``tmp_path`` and ``tmp_path_factory``. [#8327] +- Replaced the ``_jail`` fixture from ``ci_watson`` with a local copy + of the fixture named ``function_jail`` to enforce ``no:legacypath`` + in the CI tests. [#8327] + jump ---- diff --git a/jwst/associations/lib/tests/test_diff.py b/jwst/associations/lib/tests/test_diff.py index 5dd1444005..7a2c5c9606 100644 --- a/jwst/associations/lib/tests/test_diff.py +++ b/jwst/associations/lib/tests/test_diff.py @@ -311,7 +311,7 @@ def test_fails(mismatched, standard=standard_asn): asn_diff.compare_asn_lists(left_asns, right_asns) -@pytest.mark.usefixtures('_jail') +@pytest.mark.usefixtures('function_jail') def test_fromfiles(): """Test from files diff --git a/jwst/associations/tests/test_main.py b/jwst/associations/tests/test_main.py index 77d50f6966..410b91aa1b 100644 --- a/jwst/associations/tests/test_main.py +++ b/jwst/associations/tests/test_main.py @@ -44,7 +44,7 @@ def test_asn_candidates(pool, all_candidates, case): (['nosuchpool.csv'], 1), ] ) -def test_cmdline_status(args, expected, _jail): +def test_cmdline_status(args, expected, function_jail): """Ensure command line status are as expected.""" full_args = ['asn_generate'] + args status = subprocess.run(full_args) diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index 96eff5f350..978b4278f3 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -84,7 +84,7 @@ def science_image(): return image -def test_nirspec_gwa(_jail, background, science_image): +def test_nirspec_gwa(function_jail, background, science_image): """Verify NIRSPEC GWA logic for in the science and background""" # open the background to read in the GWA values @@ -106,7 +106,7 @@ def test_nirspec_gwa(_jail, background, science_image): back_image.close() -def test_nirspec_gwa_xtilt(_jail, background, science_image): +def test_nirspec_gwa_xtilt(function_jail, background, science_image): """Verify NIRSPEC GWA Xtilt must be the same in the science and background image""" # open the background to read in the GWA values @@ -128,7 +128,7 @@ def test_nirspec_gwa_xtilt(_jail, background, science_image): back_image.close() -def test_nirspec_gwa_ytilt(_jail, background, science_image): +def test_nirspec_gwa_ytilt(function_jail, background, science_image): """Verify NIRSPEC GWA Ytilt must be the same in the science and background image""" # open the background to read in the GWA values diff --git a/jwst/conftest.py b/jwst/conftest.py index 67c1f472e2..16546c9610 100644 --- a/jwst/conftest.py +++ b/jwst/conftest.py @@ -69,6 +69,21 @@ def jail(request, tmp_path_factory): os.chdir(old_dir) +@pytest.fixture(scope="function") +def function_jail(request, tmp_path_factory): + """ + Run test in a pristine temporary working directory, scoped to function. + """ + old_dir = os.getcwd() + path = request.module.__name__.split('.')[-1] + if request._parent_request.fixturename is not None: + path = path + "_" + request._parent_request.fixturename + newpath = tmp_path_factory.mktemp(path) + os.chdir(str(newpath)) + yield newpath + os.chdir(old_dir) + + @pytest.hookimpl(trylast=True) def pytest_configure(config): terminal_reporter = config.pluginmanager.getplugin('terminalreporter') diff --git a/jwst/cube_build/tests/test_configuration.py b/jwst/cube_build/tests/test_configuration.py index 909ea545bd..33e7b2f962 100644 --- a/jwst/cube_build/tests/test_configuration.py +++ b/jwst/cube_build/tests/test_configuration.py @@ -202,7 +202,7 @@ def nirspec_medium_coverage(): return input_models -def test_calspec2_config(_jail, miri_ifushort_short): +def test_calspec2_config(function_jail, miri_ifushort_short): """ Determine cube based on calspec2 setup """ pars_input = {} @@ -249,7 +249,7 @@ def test_calspec2_config(_jail, miri_ifushort_short): assert cube_pars['1']['par2'] == ['short', 'short'] -def test_calspec3_config_miri(_jail, miri_full_coverage): +def test_calspec3_config_miri(function_jail, miri_full_coverage): """ Test CalSpec3 MIRI configuration default band cubes""" pars_input = {} @@ -322,7 +322,7 @@ def test_calspec3_config_miri(_jail, miri_full_coverage): assert cube_pars['12']['par2'] == ['long'] -def test_calspec3_config_miri_multi(_jail, miri_full_coverage): +def test_calspec3_config_miri_multi(function_jail, miri_full_coverage): """ Test CalSpec3 MIRI configuration default band cubes""" pars_input = {} @@ -376,7 +376,7 @@ def test_calspec3_config_miri_multi(_jail, miri_full_coverage): 'short', 'medium', 'long'] -def test_calspec3_config_nirspec(_jail, nirspec_medium_coverage): +def test_calspec3_config_nirspec(function_jail, nirspec_medium_coverage): """ Test CalSpec3 configuration for NIRSpec - default band cubes""" pars_input = {} @@ -424,7 +424,7 @@ def test_calspec3_config_nirspec(_jail, nirspec_medium_coverage): assert cube_pars['2']['par2'] == ['f170lp'] -def test_calspec3_config_nirspec_multi(_jail, nirspec_medium_coverage): +def test_calspec3_config_nirspec_multi(function_jail, nirspec_medium_coverage): """ Test CalSpec3 configuration for NIRSpec - Multiband cubes""" pars_input = {} diff --git a/jwst/cube_build/tests/test_cube_build_step.py b/jwst/cube_build/tests/test_cube_build_step.py index de06fc29ec..6e414694b1 100644 --- a/jwst/cube_build/tests/test_cube_build_step.py +++ b/jwst/cube_build/tests/test_cube_build_step.py @@ -104,7 +104,7 @@ def miri_image(): @pytest.mark.parametrize("as_filename", [True, False]) -def test_call_cube_build(_jail, miri_cube_pars, miri_image, tmp_path, as_filename): +def test_call_cube_build(function_jail, miri_cube_pars, miri_image, tmp_path, as_filename): """ test defaults of step are set up and user input are defined correctly """ if as_filename: fn = tmp_path / 'miri.fits' @@ -181,7 +181,7 @@ def nirspec_data(): @pytest.mark.parametrize("as_filename", [True, False]) -def test_call_cube_build_nirspec(_jail, nirspec_data, tmp_path, as_filename): +def test_call_cube_build_nirspec(function_jail, nirspec_data, tmp_path, as_filename): if as_filename: fn = tmp_path / 'test_nirspec.fits' nirspec_data.save(fn) diff --git a/jwst/cube_build/tests/test_miri_cubepars.py b/jwst/cube_build/tests/test_miri_cubepars.py index 49cfac59c8..e9b2a7f258 100644 --- a/jwst/cube_build/tests/test_miri_cubepars.py +++ b/jwst/cube_build/tests/test_miri_cubepars.py @@ -87,7 +87,7 @@ def miri_cube_pars(tmp_path_factory): return filename -def test_miri_use_cubepars(_jail, miri_cube_pars): +def test_miri_use_cubepars(function_jail, miri_cube_pars): """ Test reading in the miri cube pars file """ instrument_info = instrument_defaults.InstrumentInfo() @@ -183,7 +183,7 @@ def test_miri_use_cubepars(_jail, miri_cube_pars): assert math.isclose(this_cube.spatial_size, 0.13, abs_tol=0.00001) -def test_miri_cubepars_user_defaults(_jail, miri_cube_pars): +def test_miri_cubepars_user_defaults(function_jail, miri_cube_pars): """ Read in the miri cube pars file and override some defaults """ instrument_info = instrument_defaults.InstrumentInfo() @@ -326,7 +326,7 @@ def test_miri_cubepars_user_defaults(_jail, miri_cube_pars): assert math.isclose(this_cube.rois, user_rois, abs_tol=0.00001) -def test_miri_cubepars_multiple_bands(_jail, miri_cube_pars): +def test_miri_cubepars_multiple_bands(function_jail, miri_cube_pars): """Read in the miri cube pars file. Test cube has correct values when multiple bands are used """ diff --git a/jwst/cube_build/tests/test_nirspec_cubepars.py b/jwst/cube_build/tests/test_nirspec_cubepars.py index 7241e78d3d..a37bfb6e39 100644 --- a/jwst/cube_build/tests/test_nirspec_cubepars.py +++ b/jwst/cube_build/tests/test_nirspec_cubepars.py @@ -116,7 +116,7 @@ def nirspec_cube_pars(tmp_path_factory): return filename -def test_nirspec_cubepars(_jail, nirspec_cube_pars): +def test_nirspec_cubepars(function_jail, nirspec_cube_pars): """ Read in the nirspec cube pars file """ instrument_info = instrument_defaults.InstrumentInfo() diff --git a/jwst/exp_to_source/tests/test_main.py b/jwst/exp_to_source/tests/test_main.py index fe4c84605c..6104d672c3 100644 --- a/jwst/exp_to_source/tests/test_main.py +++ b/jwst/exp_to_source/tests/test_main.py @@ -24,7 +24,7 @@ def test_default_run(tmp_path, capsys): assert len(files) == 5 -def test_dry_run(_jail, capsys): +def test_dry_run(function_jail, capsys): no_files = glob('*.fits') assert len(no_files) == 0 diff --git a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py index ea5551932a..4c13b37e13 100644 --- a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py +++ b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py @@ -130,7 +130,7 @@ def test_select_apcorr_nirspec(nirspec_cube): assert apcorr_cls == ApCorrRadial -def test_table_type_miri(_jail, dummy_miri_ref, miri_cube): +def test_table_type_miri(function_jail, dummy_miri_ref, miri_cube): dummy_wave = np.zeros(100) + 0.5 with MirMrsApcorrModel(dummy_miri_ref) as apcorr_model: table = apcorr_model.apcorr_table diff --git a/jwst/master_background/tests/test_master_background.py b/jwst/master_background/tests/test_master_background.py index 7a21bbd940..1d0bcc5922 100644 --- a/jwst/master_background/tests/test_master_background.py +++ b/jwst/master_background/tests/test_master_background.py @@ -53,7 +53,7 @@ def science_image(): return image -def test_master_background_userbg(_jail, user_background, science_image): +def test_master_background_userbg(function_jail, user_background, science_image): """Verify data can run through the step with a user-supplied background""" # Run with a user-supplied background and verify this is recorded in header @@ -68,7 +68,7 @@ def test_master_background_userbg(_jail, user_background, science_image): assert result.meta.background.master_background_file == 'user_background.fits' -def test_master_background_logic(_jail, user_background, science_image): +def test_master_background_logic(function_jail, user_background, science_image): """Verify if calspec 2 background step was run the master background step will be skipped""" # the background step in calspec2 was done diff --git a/jwst/mrs_imatch/tests/test_apply_background.py b/jwst/mrs_imatch/tests/test_apply_background.py index fc50f7f78c..9bef74f20c 100644 --- a/jwst/mrs_imatch/tests/test_apply_background.py +++ b/jwst/mrs_imatch/tests/test_apply_background.py @@ -88,7 +88,7 @@ def miri_dither_ch12(): return input_models -def test_apply_background_2d(_jail, miri_dither_ch12): +def test_apply_background_2d(function_jail, miri_dither_ch12): """ Test if background polynomial is set it is subtracted correctly""" all_models = ModelContainer(miri_dither_ch12) diff --git a/jwst/mrs_imatch/tests/test_configuration.py b/jwst/mrs_imatch/tests/test_configuration.py index 53330f6cc4..9177db8c06 100644 --- a/jwst/mrs_imatch/tests/test_configuration.py +++ b/jwst/mrs_imatch/tests/test_configuration.py @@ -57,7 +57,7 @@ def miri_dither_ch12(): return input_models -def test_imatch_background_subtracted(_jail, miri_dither_ch12): +def test_imatch_background_subtracted(function_jail, miri_dither_ch12): """ Test if data is already background subtracted - raise error""" all_models = ModelContainer(miri_dither_ch12) @@ -73,7 +73,7 @@ def test_imatch_background_subtracted(_jail, miri_dither_ch12): step.run(new_container) -def test_imatch_background_reset(_jail, miri_dither_ch12): +def test_imatch_background_reset(function_jail, miri_dither_ch12): """ Test if background polynomial is already determined - reset it""" all_models = ModelContainer(miri_dither_ch12) @@ -107,7 +107,7 @@ def test_imatch_background_reset(_jail, miri_dither_ch12): assert test == 0 -def test_find_channel_index(_jail, miri_dither_ch12): +def test_find_channel_index(function_jail, miri_dither_ch12): """ Test if correct channel index is returned """ # channel 1 - model only has 1 background polynomial diff --git a/jwst/outlier_detection/tests/test_outlier_detection.py b/jwst/outlier_detection/tests/test_outlier_detection.py index 076655f20d..fc34d211ce 100644 --- a/jwst/outlier_detection/tests/test_outlier_detection.py +++ b/jwst/outlier_detection/tests/test_outlier_detection.py @@ -160,7 +160,7 @@ def we_three_sci(): return we_many_sci(numsci=3) -def test_outlier_step_no_outliers(we_three_sci, _jail): +def test_outlier_step_no_outliers(we_three_sci, function_jail): """Test whole step, no outliers""" container = ModelContainer(list(we_three_sci)) pristine = container.copy() @@ -177,7 +177,7 @@ def test_outlier_step_no_outliers(we_three_sci, _jail): np.testing.assert_allclose(image.dq, corrected.dq) -def test_outlier_step(we_three_sci, _jail): +def test_outlier_step(we_three_sci, function_jail): """Test whole step with an outlier including saving intermediate and results files""" container = ModelContainer(list(we_three_sci)) @@ -200,7 +200,7 @@ def test_outlier_step(we_three_sci, _jail): assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE -def test_outlier_step_on_disk(we_three_sci, _jail): +def test_outlier_step_on_disk(we_three_sci, function_jail): """Test whole step with an outlier including saving intermediate and results files""" for model in we_three_sci: @@ -230,7 +230,7 @@ def test_outlier_step_on_disk(we_three_sci, _jail): assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE -def test_outlier_step_square_source_no_outliers(we_three_sci, _jail): +def test_outlier_step_square_source_no_outliers(we_three_sci, function_jail): """Test whole step with square source with sharp edges, no outliers""" container = ModelContainer(list(we_three_sci)) @@ -256,7 +256,7 @@ def test_outlier_step_square_source_no_outliers(we_three_sci, _jail): @pytest.mark.parametrize("exptype", IMAGE_MODES) -def test_outlier_step_image_weak_CR_dither(exptype, _jail): +def test_outlier_step_image_weak_CR_dither(exptype, function_jail): """Test whole step with an outlier for imaging modes""" bkg = 1.5 sig = 0.02 @@ -283,7 +283,7 @@ def test_outlier_step_image_weak_CR_dither(exptype, _jail): @pytest.mark.parametrize("exptype, tsovisit", exptypes_tso + exptypes_coron) -def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, _jail): +def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, function_jail): """Test whole step with an outlier for TSO & coronagraphic modes""" bkg = 1.5 sig = 0.02 diff --git a/jwst/regtest/conftest.py b/jwst/regtest/conftest.py index 34898f3e56..6448d24150 100644 --- a/jwst/regtest/conftest.py +++ b/jwst/regtest/conftest.py @@ -104,7 +104,7 @@ def artifactory_result_path(): postmortem(request, 'sdpdata_module') if rtdata: try: - # The _jail fixture from ci_watson sets tmp_path + # The function_jail fixture sets tmp_path cwd = str(request.node.funcargs['tmp_path']) except KeyError: # The jail fixture (module-scoped) returns the path @@ -210,7 +210,7 @@ def _rtdata_fixture_implementation(artifactory_repos, envopt, request): @pytest.fixture(scope='function') -def rtdata(artifactory_repos, envopt, request, _jail): +def rtdata(artifactory_repos, envopt, request, function_jail): return _rtdata_fixture_implementation(artifactory_repos, envopt, request) diff --git a/jwst/regtest/test_miri_dark.py b/jwst/regtest/test_miri_dark.py index 04ac6ca15c..0a17657cc5 100644 --- a/jwst/regtest/test_miri_dark.py +++ b/jwst/regtest/test_miri_dark.py @@ -9,7 +9,7 @@ 'exposure', ['jw00001001001_01101_00001_mirimage', 'jw02201001001_01101_00001_MIRIMAGE'] ) -def test_miri_dark_pipeline(exposure, _jail, rtdata, fitsdiff_default_kwargs): +def test_miri_dark_pipeline(exposure, function_jail, rtdata, fitsdiff_default_kwargs): """Test the DarkPipeline on MIRI dark exposures""" rtdata.get_data(f"miri/image/{exposure}_uncal.fits") @@ -28,7 +28,7 @@ def test_miri_dark_pipeline(exposure, _jail, rtdata, fitsdiff_default_kwargs): 'exposure', ['jw01033005001_04103_00001-seg003_mirimage'] ) -def test_miri_segmented_dark(exposure, _jail, rtdata, fitsdiff_default_kwargs): +def test_miri_segmented_dark(exposure, function_jail, rtdata, fitsdiff_default_kwargs): """Test the dark_current step on MIRI segmented exposures""" rtdata.get_data(f"miri/image/{exposure}_linearity.fits") diff --git a/jwst/regtest/test_miri_setpointing.py b/jwst/regtest/test_miri_setpointing.py index 40ee8d8d82..4cd316024e 100644 --- a/jwst/regtest/test_miri_setpointing.py +++ b/jwst/regtest/test_miri_setpointing.py @@ -12,7 +12,7 @@ @pytest.mark.bigdata -def test_miri_setpointing(_jail, rtdata, engdb, fitsdiff_default_kwargs): +def test_miri_setpointing(function_jail, rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b MIRI image. """ diff --git a/jwst/regtest/test_miri_spectral_leak.py b/jwst/regtest/test_miri_spectral_leak.py index 4896b97938..77bd73575f 100644 --- a/jwst/regtest/test_miri_spectral_leak.py +++ b/jwst/regtest/test_miri_spectral_leak.py @@ -8,7 +8,7 @@ 'output', ['test_spectral_leak_asn_0_spectralleakstep.fits', 'test_spectral_leak_asn_1_spectralleakstep.fits'] ) -def test_miri_spectral_leak(output, _jail, rtdata, fitsdiff_default_kwargs): +def test_miri_spectral_leak(output, function_jail, rtdata, fitsdiff_default_kwargs): """Run cube_build on single file using coord system = ifu_align""" rtdata.get_asn("miri/mrs/test_spectral_leak_asn.json") diff --git a/jwst/regtest/test_nircam_tsgrism.py b/jwst/regtest/test_nircam_tsgrism.py index 42e9cb07cb..bc2b32b801 100644 --- a/jwst/regtest/test_nircam_tsgrism.py +++ b/jwst/regtest/test_nircam_tsgrism.py @@ -71,7 +71,7 @@ def test_nircam_tsgrism_stage3_whtlt(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsgrism(_jail, rtdata, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsgrism(function_jail, rtdata, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam file. """ diff --git a/jwst/regtest/test_nircam_tsimg.py b/jwst/regtest/test_nircam_tsimg.py index b3a4a8aa30..88f35ef469 100644 --- a/jwst/regtest/test_nircam_tsimg.py +++ b/jwst/regtest/test_nircam_tsimg.py @@ -65,7 +65,7 @@ def test_nircam_tsimage_stage3_phot(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsimg(_jail, rtdata, engdb, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsimg(function_jail, rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam TSO imaging file. diff --git a/jwst/regtest/test_nirspec_exceptions.py b/jwst/regtest/test_nirspec_exceptions.py index b55ecce83d..07e354c871 100644 --- a/jwst/regtest/test_nirspec_exceptions.py +++ b/jwst/regtest/test_nirspec_exceptions.py @@ -7,7 +7,7 @@ @pytest.mark.bigdata -def test_nirspec_missing_msa_fail(_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_fail(function_jail, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should be raised. @@ -26,7 +26,7 @@ def test_nirspec_missing_msa_fail(_jail, rtdata, fitsdiff_default_kwargs, caplog @pytest.mark.bigdata -def test_nirspec_missing_msa_nofail(_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_nofail(function_jail, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should NOT be raised. @@ -46,7 +46,7 @@ def test_nirspec_missing_msa_nofail(_jail, rtdata, fitsdiff_default_kwargs, capl @pytest.mark.bigdata -def test_nirspec_assignwcs_skip(_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_assignwcs_skip(function_jail, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure with the AssignWcs step skipped. The pipeline should abort. @@ -66,7 +66,7 @@ def test_nirspec_assignwcs_skip(_jail, rtdata, fitsdiff_default_kwargs, caplog): @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_api(_jail, rtdata, fitsdiff_default_kwargs): +def test_nirspec_nrs2_nodata_api(function_jail, rtdata, fitsdiff_default_kwargs): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on @@ -85,7 +85,7 @@ def test_nirspec_nrs2_nodata_api(_jail, rtdata, fitsdiff_default_kwargs): @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_strun(_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_nrs2_nodata_strun(function_jail, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on diff --git a/jwst/regtest/test_nirspec_image2.py b/jwst/regtest/test_nirspec_image2.py index 471f4cfa6a..8061d9cd36 100644 --- a/jwst/regtest/test_nirspec_image2.py +++ b/jwst/regtest/test_nirspec_image2.py @@ -10,7 +10,7 @@ @pytest.mark.bigdata -def test_nirspec_image2(_jail, rtdata, fitsdiff_default_kwargs): +def test_nirspec_image2(function_jail, rtdata, fitsdiff_default_kwargs): rtdata.get_data("nirspec/imaging/jw84600010001_02102_00001_nrs2_rate.fits") args = ["calwebb_image2", rtdata.input] diff --git a/jwst/resample/tests/test_resample_step.py b/jwst/resample/tests/test_resample_step.py index 64bd0e8038..2c3dde3fe4 100644 --- a/jwst/resample/tests/test_resample_step.py +++ b/jwst/resample/tests/test_resample_step.py @@ -293,7 +293,7 @@ def test_pixel_scale_ratio_imaging(nircam_rate, ratio): assert result2.meta.resample.pixel_scale_ratio == ratio -def test_weight_type(nircam_rate, _jail): +def test_weight_type(nircam_rate, function_jail): """Check that weight_type of exptime and ivm work""" im1 = AssignWcsStep.call(nircam_rate, sip_approx=False) _set_photom_kwd(im1) diff --git a/jwst/residual_fringe/tests/test_configuration.py b/jwst/residual_fringe/tests/test_configuration.py index 808c346cd6..817a19cc0b 100644 --- a/jwst/residual_fringe/tests/test_configuration.py +++ b/jwst/residual_fringe/tests/test_configuration.py @@ -25,7 +25,7 @@ def miri_image(): return image -def test_call_residual_fringe(_jail, miri_image): +def test_call_residual_fringe(function_jail, miri_image): """ test defaults of step are set up and user input are defined correctly """ # testing the ignore_regions_min @@ -42,7 +42,7 @@ def test_call_residual_fringe(_jail, miri_image): step.run(miri_image) -def test_fringe_flat_applied(_jail, miri_image): +def test_fringe_flat_applied(function_jail, miri_image): miri_image.meta.cal_step.fringe = 'SKIP' residual_fringe_reference_file = None diff --git a/jwst/stpipe/tests/test_asdf_parameters.py b/jwst/stpipe/tests/test_asdf_parameters.py index ad891608bf..f26f2d9ad4 100644 --- a/jwst/stpipe/tests/test_asdf_parameters.py +++ b/jwst/stpipe/tests/test_asdf_parameters.py @@ -13,7 +13,7 @@ DEFAULT_RESULT = [DEFAULT_PAR1, DEFAULT_PAR2, False] -def test_asdf_roundtrip_pipeline(_jail): +def test_asdf_roundtrip_pipeline(function_jail): """Save a Pipeline pars and re-instantiate with the save parameters""" # Save the parameters diff --git a/jwst/stpipe/tests/test_pipeline.py b/jwst/stpipe/tests/test_pipeline.py index af60b2161b..96b277e83d 100644 --- a/jwst/stpipe/tests/test_pipeline.py +++ b/jwst/stpipe/tests/test_pipeline.py @@ -104,7 +104,7 @@ def process(self, *args): return dm -def test_pipeline_from_config_file(_jail): +def test_pipeline_from_config_file(function_jail): config_file_path = join(dirname(__file__), 'steps', 'python_pipeline.cfg') pipe = Pipeline.from_config_file(config_file_path) @@ -114,7 +114,7 @@ def test_pipeline_from_config_file(_jail): pipe.run() -def test_pipeline_python(_jail): +def test_pipeline_python(function_jail): steps = { 'flat_field': {'threshold': 42.0} } @@ -132,7 +132,7 @@ def test_pipeline_python(_jail): pipe.run() -def test_prefetch(_jail, monkeypatch): +def test_prefetch(function_jail, monkeypatch): """Test prefetching""" # Setup mock to crds to flag if the call was made. @@ -172,7 +172,7 @@ def mock(self, parameters, reference_file_types, observatory): assert not mock_get_ref.called -def test_pipeline_from_cmdline_cfg(_jail): +def test_pipeline_from_cmdline_cfg(function_jail): args = [ join(dirname(__file__), 'steps', 'python_pipeline.cfg'), '--steps.flat_field.threshold=47', @@ -186,7 +186,7 @@ def test_pipeline_from_cmdline_cfg(_jail): pipe.run() -def test_pipeline_from_cmdline_class(_jail): +def test_pipeline_from_cmdline_class(function_jail): args = [ 'jwst.stpipe.tests.test_pipeline.MyPipeline', f"--science_filename={join(dirname(__file__), 'data', 'science.fits')}", diff --git a/jwst/stpipe/tests/test_step.py b/jwst/stpipe/tests/test_step.py index b7732e6ab6..177c9cc34e 100644 --- a/jwst/stpipe/tests/test_step.py +++ b/jwst/stpipe/tests/test_step.py @@ -597,7 +597,7 @@ def test_print_configspec(): step.print_configspec() -def test_call_with_config(caplog, _jail): +def test_call_with_config(caplog, function_jail): """Test call using a config file with substeps In particular, from JP-1482, there was a case where a substep parameter diff --git a/jwst/straylight/tests/test_straylight_step.py b/jwst/straylight/tests/test_straylight_step.py index ee5eb07365..3a78e1861e 100644 --- a/jwst/straylight/tests/test_straylight_step.py +++ b/jwst/straylight/tests/test_straylight_step.py @@ -26,7 +26,7 @@ def miri_mrs_short_tso(): return image -def test_call_straylight_mrsshort_tso(_jail, miri_mrs_short_tso): +def test_call_straylight_mrsshort_tso(function_jail, miri_mrs_short_tso): """Test step is skipped for MRS IFUSHORT TSO data""" result = StraylightStep.call(miri_mrs_short_tso) assert result.meta.cal_step.straylight == 'SKIPPED' diff --git a/jwst/tests/test_infrastructure.py b/jwst/tests/test_infrastructure.py index 7f3615277e..f19c240fe6 100644 --- a/jwst/tests/test_infrastructure.py +++ b/jwst/tests/test_infrastructure.py @@ -36,7 +36,7 @@ def test_word_precision_check(): ('*.fits', 0) ], ids=['all', 'txt', 'fits'] ) -def test_data_glob_local(glob_filter, nfiles, _jail): +def test_data_glob_local(glob_filter, nfiles, function_jail): """Test working of local globbing Parameters diff --git a/jwst/wfs_combine/tests/test_wfs_combine.py b/jwst/wfs_combine/tests/test_wfs_combine.py index 6ff1c9f1cd..683919dd97 100644 --- a/jwst/wfs_combine/tests/test_wfs_combine.py +++ b/jwst/wfs_combine/tests/test_wfs_combine.py @@ -101,7 +101,7 @@ def wfs_association(tmp_path_factory): (1, 3, SATURATED, SATURATED, 2, SATURATED), ] ) -def test_create_combined(_jail, wfs_association, +def test_create_combined(function_jail, wfs_association, data1, data2, dq1, dq2, result_data, result_dq): path_asn, path1, path2 = wfs_association From c6ffe445a231b3a720a4a25e38aff7a1d3b5ed75 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Wed, 6 Mar 2024 17:19:50 -0500 Subject: [PATCH 06/16] revert change to ci-watson dependency --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index bb8005093d..188c0c9d76 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -129,7 +129,7 @@ sdp = [ "pysiaf>=0.13.0", ] test = [ - "git+https://github.com/spacetelescope/ci_watson.git@main", + "ci-watson>=0.5.0", "colorama>=0.4.1", "readchar>=3.0", "ruff", From 9d3291d23200bf37e2e02a6f98880bbd7360e92c Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Wed, 6 Mar 2024 17:42:05 -0500 Subject: [PATCH 07/16] missed one instance of _jail --- jwst/extract_1d/tests/test_apply_apcorr_ifu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py index 4c13b37e13..a6836bfb1f 100644 --- a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py +++ b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py @@ -140,7 +140,7 @@ def test_table_type_miri(function_jail, dummy_miri_ref, miri_cube): assert np.all(table.wavelength == dummy_wave) -def test_table_type_nirspec(_jail, dummy_nirspec_ref, nirspec_cube): +def test_table_type_nirspec(function_jail, dummy_nirspec_ref, nirspec_cube): dummy_wave = np.zeros(100) + 0.5 with NrsIfuApcorrModel(dummy_nirspec_ref) as apcorr_model: table = apcorr_model.apcorr_table From ff3cd85dd9ce6dfd44ff8b9c74232b87c17bad46 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Thu, 7 Mar 2024 09:11:22 -0500 Subject: [PATCH 08/16] replace function_jail with tmp_cwd --- CHANGES.rst | 5 ++-- jwst/associations/lib/tests/test_diff.py | 2 +- jwst/associations/tests/test_main.py | 2 +- jwst/background/tests/test_background.py | 6 ++--- jwst/conftest.py | 23 ++++++++----------- jwst/cube_build/tests/test_configuration.py | 10 ++++---- jwst/cube_build/tests/test_cube_build_step.py | 4 ++-- jwst/cube_build/tests/test_miri_cubepars.py | 6 ++--- .../cube_build/tests/test_nirspec_cubepars.py | 2 +- jwst/exp_to_source/tests/test_main.py | 2 +- .../extract_1d/tests/test_apply_apcorr_ifu.py | 4 ++-- .../tests/test_master_background.py | 4 ++-- .../mrs_imatch/tests/test_apply_background.py | 2 +- jwst/mrs_imatch/tests/test_configuration.py | 6 ++--- .../tests/test_outlier_detection.py | 12 +++++----- jwst/regtest/conftest.py | 4 ++-- jwst/regtest/test_miri_dark.py | 4 ++-- jwst/regtest/test_miri_setpointing.py | 2 +- jwst/regtest/test_miri_spectral_leak.py | 2 +- jwst/regtest/test_nircam_tsgrism.py | 2 +- jwst/regtest/test_nircam_tsimg.py | 2 +- jwst/regtest/test_nirspec_exceptions.py | 10 ++++---- jwst/regtest/test_nirspec_image2.py | 2 +- jwst/resample/tests/test_resample_step.py | 2 +- .../tests/test_configuration.py | 4 ++-- jwst/stpipe/tests/test_asdf_parameters.py | 2 +- jwst/stpipe/tests/test_pipeline.py | 10 ++++---- jwst/stpipe/tests/test_step.py | 2 +- jwst/straylight/tests/test_straylight_step.py | 2 +- jwst/tests/test_infrastructure.py | 2 +- jwst/wfs_combine/tests/test_wfs_combine.py | 2 +- 31 files changed, 70 insertions(+), 74 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 33863f9bc2..115d47c508 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -123,9 +123,8 @@ general - Replaced all instances of pytest ``tmpdir`` and ``tmpdir_factory`` fixtures with ``tmp_path`` and ``tmp_path_factory``. [#8327] -- Replaced the ``_jail`` fixture from ``ci_watson`` with a local copy - of the fixture named ``function_jail`` to enforce ``no:legacypath`` - in the CI tests. [#8327] +- Replaced the ``_jail`` fixture from ``ci_watson`` with custom + ``tmp_cwd`` to enforce ``no:legacypath`` in the CI tests. [#8327] jump ---- diff --git a/jwst/associations/lib/tests/test_diff.py b/jwst/associations/lib/tests/test_diff.py index 7a2c5c9606..c1063c857e 100644 --- a/jwst/associations/lib/tests/test_diff.py +++ b/jwst/associations/lib/tests/test_diff.py @@ -311,7 +311,7 @@ def test_fails(mismatched, standard=standard_asn): asn_diff.compare_asn_lists(left_asns, right_asns) -@pytest.mark.usefixtures('function_jail') +@pytest.mark.usefixtures('tmp_cwd') def test_fromfiles(): """Test from files diff --git a/jwst/associations/tests/test_main.py b/jwst/associations/tests/test_main.py index 410b91aa1b..e2751c34ee 100644 --- a/jwst/associations/tests/test_main.py +++ b/jwst/associations/tests/test_main.py @@ -44,7 +44,7 @@ def test_asn_candidates(pool, all_candidates, case): (['nosuchpool.csv'], 1), ] ) -def test_cmdline_status(args, expected, function_jail): +def test_cmdline_status(args, expected, tmp_cwd): """Ensure command line status are as expected.""" full_args = ['asn_generate'] + args status = subprocess.run(full_args) diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index 978b4278f3..94998222bc 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -84,7 +84,7 @@ def science_image(): return image -def test_nirspec_gwa(function_jail, background, science_image): +def test_nirspec_gwa(tmp_cwd, background, science_image): """Verify NIRSPEC GWA logic for in the science and background""" # open the background to read in the GWA values @@ -106,7 +106,7 @@ def test_nirspec_gwa(function_jail, background, science_image): back_image.close() -def test_nirspec_gwa_xtilt(function_jail, background, science_image): +def test_nirspec_gwa_xtilt(tmp_cwd, background, science_image): """Verify NIRSPEC GWA Xtilt must be the same in the science and background image""" # open the background to read in the GWA values @@ -128,7 +128,7 @@ def test_nirspec_gwa_xtilt(function_jail, background, science_image): back_image.close() -def test_nirspec_gwa_ytilt(function_jail, background, science_image): +def test_nirspec_gwa_ytilt(tmp_cwd, background, science_image): """Verify NIRSPEC GWA Ytilt must be the same in the science and background image""" # open the background to read in the GWA values diff --git a/jwst/conftest.py b/jwst/conftest.py index 16546c9610..7cd1ba5fd2 100644 --- a/jwst/conftest.py +++ b/jwst/conftest.py @@ -3,6 +3,7 @@ import tempfile import pytest import inspect +from pathlib import Path from jwst.associations import (AssociationRegistry, AssociationPool) from jwst.associations.tests.helpers import t_path @@ -69,19 +70,15 @@ def jail(request, tmp_path_factory): os.chdir(old_dir) -@pytest.fixture(scope="function") -def function_jail(request, tmp_path_factory): - """ - Run test in a pristine temporary working directory, scoped to function. - """ - old_dir = os.getcwd() - path = request.module.__name__.split('.')[-1] - if request._parent_request.fixturename is not None: - path = path + "_" + request._parent_request.fixturename - newpath = tmp_path_factory.mktemp(path) - os.chdir(str(newpath)) - yield newpath - os.chdir(old_dir) +@pytest.fixture +def tmp_cwd(tmp_path): + """Perform test in a pristine temporary working directory.""" + old_dir = Path.cwd() + os.chdir(tmp_path) + try: + yield tmp_path + finally: + os.chdir(old_dir) @pytest.hookimpl(trylast=True) diff --git a/jwst/cube_build/tests/test_configuration.py b/jwst/cube_build/tests/test_configuration.py index 33e7b2f962..e3783c1ca8 100644 --- a/jwst/cube_build/tests/test_configuration.py +++ b/jwst/cube_build/tests/test_configuration.py @@ -202,7 +202,7 @@ def nirspec_medium_coverage(): return input_models -def test_calspec2_config(function_jail, miri_ifushort_short): +def test_calspec2_config(tmp_cwd, miri_ifushort_short): """ Determine cube based on calspec2 setup """ pars_input = {} @@ -249,7 +249,7 @@ def test_calspec2_config(function_jail, miri_ifushort_short): assert cube_pars['1']['par2'] == ['short', 'short'] -def test_calspec3_config_miri(function_jail, miri_full_coverage): +def test_calspec3_config_miri(tmp_cwd, miri_full_coverage): """ Test CalSpec3 MIRI configuration default band cubes""" pars_input = {} @@ -322,7 +322,7 @@ def test_calspec3_config_miri(function_jail, miri_full_coverage): assert cube_pars['12']['par2'] == ['long'] -def test_calspec3_config_miri_multi(function_jail, miri_full_coverage): +def test_calspec3_config_miri_multi(tmp_cwd, miri_full_coverage): """ Test CalSpec3 MIRI configuration default band cubes""" pars_input = {} @@ -376,7 +376,7 @@ def test_calspec3_config_miri_multi(function_jail, miri_full_coverage): 'short', 'medium', 'long'] -def test_calspec3_config_nirspec(function_jail, nirspec_medium_coverage): +def test_calspec3_config_nirspec(tmp_cwd, nirspec_medium_coverage): """ Test CalSpec3 configuration for NIRSpec - default band cubes""" pars_input = {} @@ -424,7 +424,7 @@ def test_calspec3_config_nirspec(function_jail, nirspec_medium_coverage): assert cube_pars['2']['par2'] == ['f170lp'] -def test_calspec3_config_nirspec_multi(function_jail, nirspec_medium_coverage): +def test_calspec3_config_nirspec_multi(tmp_cwd, nirspec_medium_coverage): """ Test CalSpec3 configuration for NIRSpec - Multiband cubes""" pars_input = {} diff --git a/jwst/cube_build/tests/test_cube_build_step.py b/jwst/cube_build/tests/test_cube_build_step.py index 6e414694b1..77bc98d524 100644 --- a/jwst/cube_build/tests/test_cube_build_step.py +++ b/jwst/cube_build/tests/test_cube_build_step.py @@ -104,7 +104,7 @@ def miri_image(): @pytest.mark.parametrize("as_filename", [True, False]) -def test_call_cube_build(function_jail, miri_cube_pars, miri_image, tmp_path, as_filename): +def test_call_cube_build(tmp_cwd, miri_cube_pars, miri_image, tmp_path, as_filename): """ test defaults of step are set up and user input are defined correctly """ if as_filename: fn = tmp_path / 'miri.fits' @@ -181,7 +181,7 @@ def nirspec_data(): @pytest.mark.parametrize("as_filename", [True, False]) -def test_call_cube_build_nirspec(function_jail, nirspec_data, tmp_path, as_filename): +def test_call_cube_build_nirspec(tmp_cwd, nirspec_data, tmp_path, as_filename): if as_filename: fn = tmp_path / 'test_nirspec.fits' nirspec_data.save(fn) diff --git a/jwst/cube_build/tests/test_miri_cubepars.py b/jwst/cube_build/tests/test_miri_cubepars.py index e9b2a7f258..757c8672ff 100644 --- a/jwst/cube_build/tests/test_miri_cubepars.py +++ b/jwst/cube_build/tests/test_miri_cubepars.py @@ -87,7 +87,7 @@ def miri_cube_pars(tmp_path_factory): return filename -def test_miri_use_cubepars(function_jail, miri_cube_pars): +def test_miri_use_cubepars(tmp_cwd, miri_cube_pars): """ Test reading in the miri cube pars file """ instrument_info = instrument_defaults.InstrumentInfo() @@ -183,7 +183,7 @@ def test_miri_use_cubepars(function_jail, miri_cube_pars): assert math.isclose(this_cube.spatial_size, 0.13, abs_tol=0.00001) -def test_miri_cubepars_user_defaults(function_jail, miri_cube_pars): +def test_miri_cubepars_user_defaults(tmp_cwd, miri_cube_pars): """ Read in the miri cube pars file and override some defaults """ instrument_info = instrument_defaults.InstrumentInfo() @@ -326,7 +326,7 @@ def test_miri_cubepars_user_defaults(function_jail, miri_cube_pars): assert math.isclose(this_cube.rois, user_rois, abs_tol=0.00001) -def test_miri_cubepars_multiple_bands(function_jail, miri_cube_pars): +def test_miri_cubepars_multiple_bands(tmp_cwd, miri_cube_pars): """Read in the miri cube pars file. Test cube has correct values when multiple bands are used """ diff --git a/jwst/cube_build/tests/test_nirspec_cubepars.py b/jwst/cube_build/tests/test_nirspec_cubepars.py index a37bfb6e39..9409763ac9 100644 --- a/jwst/cube_build/tests/test_nirspec_cubepars.py +++ b/jwst/cube_build/tests/test_nirspec_cubepars.py @@ -116,7 +116,7 @@ def nirspec_cube_pars(tmp_path_factory): return filename -def test_nirspec_cubepars(function_jail, nirspec_cube_pars): +def test_nirspec_cubepars(tmp_cwd, nirspec_cube_pars): """ Read in the nirspec cube pars file """ instrument_info = instrument_defaults.InstrumentInfo() diff --git a/jwst/exp_to_source/tests/test_main.py b/jwst/exp_to_source/tests/test_main.py index 6104d672c3..2bdb50c6bf 100644 --- a/jwst/exp_to_source/tests/test_main.py +++ b/jwst/exp_to_source/tests/test_main.py @@ -24,7 +24,7 @@ def test_default_run(tmp_path, capsys): assert len(files) == 5 -def test_dry_run(function_jail, capsys): +def test_dry_run(tmp_cwd, capsys): no_files = glob('*.fits') assert len(no_files) == 0 diff --git a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py index a6836bfb1f..760e6e7457 100644 --- a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py +++ b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py @@ -130,7 +130,7 @@ def test_select_apcorr_nirspec(nirspec_cube): assert apcorr_cls == ApCorrRadial -def test_table_type_miri(function_jail, dummy_miri_ref, miri_cube): +def test_table_type_miri(tmp_cwd, dummy_miri_ref, miri_cube): dummy_wave = np.zeros(100) + 0.5 with MirMrsApcorrModel(dummy_miri_ref) as apcorr_model: table = apcorr_model.apcorr_table @@ -140,7 +140,7 @@ def test_table_type_miri(function_jail, dummy_miri_ref, miri_cube): assert np.all(table.wavelength == dummy_wave) -def test_table_type_nirspec(function_jail, dummy_nirspec_ref, nirspec_cube): +def test_table_type_nirspec(tmp_cwd, dummy_nirspec_ref, nirspec_cube): dummy_wave = np.zeros(100) + 0.5 with NrsIfuApcorrModel(dummy_nirspec_ref) as apcorr_model: table = apcorr_model.apcorr_table diff --git a/jwst/master_background/tests/test_master_background.py b/jwst/master_background/tests/test_master_background.py index 1d0bcc5922..443a431cb3 100644 --- a/jwst/master_background/tests/test_master_background.py +++ b/jwst/master_background/tests/test_master_background.py @@ -53,7 +53,7 @@ def science_image(): return image -def test_master_background_userbg(function_jail, user_background, science_image): +def test_master_background_userbg(tmp_cwd, user_background, science_image): """Verify data can run through the step with a user-supplied background""" # Run with a user-supplied background and verify this is recorded in header @@ -68,7 +68,7 @@ def test_master_background_userbg(function_jail, user_background, science_image) assert result.meta.background.master_background_file == 'user_background.fits' -def test_master_background_logic(function_jail, user_background, science_image): +def test_master_background_logic(tmp_cwd, user_background, science_image): """Verify if calspec 2 background step was run the master background step will be skipped""" # the background step in calspec2 was done diff --git a/jwst/mrs_imatch/tests/test_apply_background.py b/jwst/mrs_imatch/tests/test_apply_background.py index 9bef74f20c..ff26907bd7 100644 --- a/jwst/mrs_imatch/tests/test_apply_background.py +++ b/jwst/mrs_imatch/tests/test_apply_background.py @@ -88,7 +88,7 @@ def miri_dither_ch12(): return input_models -def test_apply_background_2d(function_jail, miri_dither_ch12): +def test_apply_background_2d(tmp_cwd, miri_dither_ch12): """ Test if background polynomial is set it is subtracted correctly""" all_models = ModelContainer(miri_dither_ch12) diff --git a/jwst/mrs_imatch/tests/test_configuration.py b/jwst/mrs_imatch/tests/test_configuration.py index 9177db8c06..39dbe5cabe 100644 --- a/jwst/mrs_imatch/tests/test_configuration.py +++ b/jwst/mrs_imatch/tests/test_configuration.py @@ -57,7 +57,7 @@ def miri_dither_ch12(): return input_models -def test_imatch_background_subtracted(function_jail, miri_dither_ch12): +def test_imatch_background_subtracted(tmp_cwd, miri_dither_ch12): """ Test if data is already background subtracted - raise error""" all_models = ModelContainer(miri_dither_ch12) @@ -73,7 +73,7 @@ def test_imatch_background_subtracted(function_jail, miri_dither_ch12): step.run(new_container) -def test_imatch_background_reset(function_jail, miri_dither_ch12): +def test_imatch_background_reset(tmp_cwd, miri_dither_ch12): """ Test if background polynomial is already determined - reset it""" all_models = ModelContainer(miri_dither_ch12) @@ -107,7 +107,7 @@ def test_imatch_background_reset(function_jail, miri_dither_ch12): assert test == 0 -def test_find_channel_index(function_jail, miri_dither_ch12): +def test_find_channel_index(tmp_cwd, miri_dither_ch12): """ Test if correct channel index is returned """ # channel 1 - model only has 1 background polynomial diff --git a/jwst/outlier_detection/tests/test_outlier_detection.py b/jwst/outlier_detection/tests/test_outlier_detection.py index fc34d211ce..354ce57895 100644 --- a/jwst/outlier_detection/tests/test_outlier_detection.py +++ b/jwst/outlier_detection/tests/test_outlier_detection.py @@ -160,7 +160,7 @@ def we_three_sci(): return we_many_sci(numsci=3) -def test_outlier_step_no_outliers(we_three_sci, function_jail): +def test_outlier_step_no_outliers(we_three_sci, tmp_cwd): """Test whole step, no outliers""" container = ModelContainer(list(we_three_sci)) pristine = container.copy() @@ -177,7 +177,7 @@ def test_outlier_step_no_outliers(we_three_sci, function_jail): np.testing.assert_allclose(image.dq, corrected.dq) -def test_outlier_step(we_three_sci, function_jail): +def test_outlier_step(we_three_sci, tmp_cwd): """Test whole step with an outlier including saving intermediate and results files""" container = ModelContainer(list(we_three_sci)) @@ -200,7 +200,7 @@ def test_outlier_step(we_three_sci, function_jail): assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE -def test_outlier_step_on_disk(we_three_sci, function_jail): +def test_outlier_step_on_disk(we_three_sci, tmp_cwd): """Test whole step with an outlier including saving intermediate and results files""" for model in we_three_sci: @@ -230,7 +230,7 @@ def test_outlier_step_on_disk(we_three_sci, function_jail): assert result[0].dq[12, 12] == OUTLIER_DO_NOT_USE -def test_outlier_step_square_source_no_outliers(we_three_sci, function_jail): +def test_outlier_step_square_source_no_outliers(we_three_sci, tmp_cwd): """Test whole step with square source with sharp edges, no outliers""" container = ModelContainer(list(we_three_sci)) @@ -256,7 +256,7 @@ def test_outlier_step_square_source_no_outliers(we_three_sci, function_jail): @pytest.mark.parametrize("exptype", IMAGE_MODES) -def test_outlier_step_image_weak_CR_dither(exptype, function_jail): +def test_outlier_step_image_weak_CR_dither(exptype, tmp_cwd): """Test whole step with an outlier for imaging modes""" bkg = 1.5 sig = 0.02 @@ -283,7 +283,7 @@ def test_outlier_step_image_weak_CR_dither(exptype, function_jail): @pytest.mark.parametrize("exptype, tsovisit", exptypes_tso + exptypes_coron) -def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, function_jail): +def test_outlier_step_image_weak_CR_nodither(exptype, tsovisit, tmp_cwd): """Test whole step with an outlier for TSO & coronagraphic modes""" bkg = 1.5 sig = 0.02 diff --git a/jwst/regtest/conftest.py b/jwst/regtest/conftest.py index 6448d24150..4a06f0cbb5 100644 --- a/jwst/regtest/conftest.py +++ b/jwst/regtest/conftest.py @@ -104,7 +104,7 @@ def artifactory_result_path(): postmortem(request, 'sdpdata_module') if rtdata: try: - # The function_jail fixture sets tmp_path + # The tmp_cwd fixture sets tmp_path cwd = str(request.node.funcargs['tmp_path']) except KeyError: # The jail fixture (module-scoped) returns the path @@ -210,7 +210,7 @@ def _rtdata_fixture_implementation(artifactory_repos, envopt, request): @pytest.fixture(scope='function') -def rtdata(artifactory_repos, envopt, request, function_jail): +def rtdata(artifactory_repos, envopt, request, tmp_cwd): return _rtdata_fixture_implementation(artifactory_repos, envopt, request) diff --git a/jwst/regtest/test_miri_dark.py b/jwst/regtest/test_miri_dark.py index 0a17657cc5..82a1c4c0f1 100644 --- a/jwst/regtest/test_miri_dark.py +++ b/jwst/regtest/test_miri_dark.py @@ -9,7 +9,7 @@ 'exposure', ['jw00001001001_01101_00001_mirimage', 'jw02201001001_01101_00001_MIRIMAGE'] ) -def test_miri_dark_pipeline(exposure, function_jail, rtdata, fitsdiff_default_kwargs): +def test_miri_dark_pipeline(exposure, tmp_cwd, rtdata, fitsdiff_default_kwargs): """Test the DarkPipeline on MIRI dark exposures""" rtdata.get_data(f"miri/image/{exposure}_uncal.fits") @@ -28,7 +28,7 @@ def test_miri_dark_pipeline(exposure, function_jail, rtdata, fitsdiff_default_kw 'exposure', ['jw01033005001_04103_00001-seg003_mirimage'] ) -def test_miri_segmented_dark(exposure, function_jail, rtdata, fitsdiff_default_kwargs): +def test_miri_segmented_dark(exposure, tmp_cwd, rtdata, fitsdiff_default_kwargs): """Test the dark_current step on MIRI segmented exposures""" rtdata.get_data(f"miri/image/{exposure}_linearity.fits") diff --git a/jwst/regtest/test_miri_setpointing.py b/jwst/regtest/test_miri_setpointing.py index 4cd316024e..427e3ba42d 100644 --- a/jwst/regtest/test_miri_setpointing.py +++ b/jwst/regtest/test_miri_setpointing.py @@ -12,7 +12,7 @@ @pytest.mark.bigdata -def test_miri_setpointing(function_jail, rtdata, engdb, fitsdiff_default_kwargs): +def test_miri_setpointing(tmp_cwd, rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b MIRI image. """ diff --git a/jwst/regtest/test_miri_spectral_leak.py b/jwst/regtest/test_miri_spectral_leak.py index 77bd73575f..b167fe33f3 100644 --- a/jwst/regtest/test_miri_spectral_leak.py +++ b/jwst/regtest/test_miri_spectral_leak.py @@ -8,7 +8,7 @@ 'output', ['test_spectral_leak_asn_0_spectralleakstep.fits', 'test_spectral_leak_asn_1_spectralleakstep.fits'] ) -def test_miri_spectral_leak(output, function_jail, rtdata, fitsdiff_default_kwargs): +def test_miri_spectral_leak(output, tmp_cwd, rtdata, fitsdiff_default_kwargs): """Run cube_build on single file using coord system = ifu_align""" rtdata.get_asn("miri/mrs/test_spectral_leak_asn.json") diff --git a/jwst/regtest/test_nircam_tsgrism.py b/jwst/regtest/test_nircam_tsgrism.py index bc2b32b801..bca7ebcd9f 100644 --- a/jwst/regtest/test_nircam_tsgrism.py +++ b/jwst/regtest/test_nircam_tsgrism.py @@ -71,7 +71,7 @@ def test_nircam_tsgrism_stage3_whtlt(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsgrism(function_jail, rtdata, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsgrism(tmp_cwd, rtdata, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam file. """ diff --git a/jwst/regtest/test_nircam_tsimg.py b/jwst/regtest/test_nircam_tsimg.py index 88f35ef469..56a96a50b3 100644 --- a/jwst/regtest/test_nircam_tsimg.py +++ b/jwst/regtest/test_nircam_tsimg.py @@ -65,7 +65,7 @@ def test_nircam_tsimage_stage3_phot(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsimg(function_jail, rtdata, engdb, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsimg(tmp_cwd, rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam TSO imaging file. diff --git a/jwst/regtest/test_nirspec_exceptions.py b/jwst/regtest/test_nirspec_exceptions.py index 07e354c871..168745de8b 100644 --- a/jwst/regtest/test_nirspec_exceptions.py +++ b/jwst/regtest/test_nirspec_exceptions.py @@ -7,7 +7,7 @@ @pytest.mark.bigdata -def test_nirspec_missing_msa_fail(function_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_fail(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should be raised. @@ -26,7 +26,7 @@ def test_nirspec_missing_msa_fail(function_jail, rtdata, fitsdiff_default_kwargs @pytest.mark.bigdata -def test_nirspec_missing_msa_nofail(function_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_nofail(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should NOT be raised. @@ -46,7 +46,7 @@ def test_nirspec_missing_msa_nofail(function_jail, rtdata, fitsdiff_default_kwar @pytest.mark.bigdata -def test_nirspec_assignwcs_skip(function_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_assignwcs_skip(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure with the AssignWcs step skipped. The pipeline should abort. @@ -66,7 +66,7 @@ def test_nirspec_assignwcs_skip(function_jail, rtdata, fitsdiff_default_kwargs, @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_api(function_jail, rtdata, fitsdiff_default_kwargs): +def test_nirspec_nrs2_nodata_api(tmp_cwd, rtdata, fitsdiff_default_kwargs): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on @@ -85,7 +85,7 @@ def test_nirspec_nrs2_nodata_api(function_jail, rtdata, fitsdiff_default_kwargs) @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_strun(function_jail, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_nrs2_nodata_strun(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on diff --git a/jwst/regtest/test_nirspec_image2.py b/jwst/regtest/test_nirspec_image2.py index 8061d9cd36..153f4a2c17 100644 --- a/jwst/regtest/test_nirspec_image2.py +++ b/jwst/regtest/test_nirspec_image2.py @@ -10,7 +10,7 @@ @pytest.mark.bigdata -def test_nirspec_image2(function_jail, rtdata, fitsdiff_default_kwargs): +def test_nirspec_image2(tmp_cwd, rtdata, fitsdiff_default_kwargs): rtdata.get_data("nirspec/imaging/jw84600010001_02102_00001_nrs2_rate.fits") args = ["calwebb_image2", rtdata.input] diff --git a/jwst/resample/tests/test_resample_step.py b/jwst/resample/tests/test_resample_step.py index 2c3dde3fe4..08e1fd436b 100644 --- a/jwst/resample/tests/test_resample_step.py +++ b/jwst/resample/tests/test_resample_step.py @@ -293,7 +293,7 @@ def test_pixel_scale_ratio_imaging(nircam_rate, ratio): assert result2.meta.resample.pixel_scale_ratio == ratio -def test_weight_type(nircam_rate, function_jail): +def test_weight_type(nircam_rate, tmp_cwd): """Check that weight_type of exptime and ivm work""" im1 = AssignWcsStep.call(nircam_rate, sip_approx=False) _set_photom_kwd(im1) diff --git a/jwst/residual_fringe/tests/test_configuration.py b/jwst/residual_fringe/tests/test_configuration.py index 817a19cc0b..d0253333bb 100644 --- a/jwst/residual_fringe/tests/test_configuration.py +++ b/jwst/residual_fringe/tests/test_configuration.py @@ -25,7 +25,7 @@ def miri_image(): return image -def test_call_residual_fringe(function_jail, miri_image): +def test_call_residual_fringe(tmp_cwd, miri_image): """ test defaults of step are set up and user input are defined correctly """ # testing the ignore_regions_min @@ -42,7 +42,7 @@ def test_call_residual_fringe(function_jail, miri_image): step.run(miri_image) -def test_fringe_flat_applied(function_jail, miri_image): +def test_fringe_flat_applied(tmp_cwd, miri_image): miri_image.meta.cal_step.fringe = 'SKIP' residual_fringe_reference_file = None diff --git a/jwst/stpipe/tests/test_asdf_parameters.py b/jwst/stpipe/tests/test_asdf_parameters.py index f26f2d9ad4..ee87b14c1f 100644 --- a/jwst/stpipe/tests/test_asdf_parameters.py +++ b/jwst/stpipe/tests/test_asdf_parameters.py @@ -13,7 +13,7 @@ DEFAULT_RESULT = [DEFAULT_PAR1, DEFAULT_PAR2, False] -def test_asdf_roundtrip_pipeline(function_jail): +def test_asdf_roundtrip_pipeline(tmp_cwd): """Save a Pipeline pars and re-instantiate with the save parameters""" # Save the parameters diff --git a/jwst/stpipe/tests/test_pipeline.py b/jwst/stpipe/tests/test_pipeline.py index 96b277e83d..96b17a20f7 100644 --- a/jwst/stpipe/tests/test_pipeline.py +++ b/jwst/stpipe/tests/test_pipeline.py @@ -104,7 +104,7 @@ def process(self, *args): return dm -def test_pipeline_from_config_file(function_jail): +def test_pipeline_from_config_file(tmp_cwd): config_file_path = join(dirname(__file__), 'steps', 'python_pipeline.cfg') pipe = Pipeline.from_config_file(config_file_path) @@ -114,7 +114,7 @@ def test_pipeline_from_config_file(function_jail): pipe.run() -def test_pipeline_python(function_jail): +def test_pipeline_python(tmp_cwd): steps = { 'flat_field': {'threshold': 42.0} } @@ -132,7 +132,7 @@ def test_pipeline_python(function_jail): pipe.run() -def test_prefetch(function_jail, monkeypatch): +def test_prefetch(tmp_cwd, monkeypatch): """Test prefetching""" # Setup mock to crds to flag if the call was made. @@ -172,7 +172,7 @@ def mock(self, parameters, reference_file_types, observatory): assert not mock_get_ref.called -def test_pipeline_from_cmdline_cfg(function_jail): +def test_pipeline_from_cmdline_cfg(tmp_cwd): args = [ join(dirname(__file__), 'steps', 'python_pipeline.cfg'), '--steps.flat_field.threshold=47', @@ -186,7 +186,7 @@ def test_pipeline_from_cmdline_cfg(function_jail): pipe.run() -def test_pipeline_from_cmdline_class(function_jail): +def test_pipeline_from_cmdline_class(tmp_cwd): args = [ 'jwst.stpipe.tests.test_pipeline.MyPipeline', f"--science_filename={join(dirname(__file__), 'data', 'science.fits')}", diff --git a/jwst/stpipe/tests/test_step.py b/jwst/stpipe/tests/test_step.py index 177c9cc34e..8053e8cf19 100644 --- a/jwst/stpipe/tests/test_step.py +++ b/jwst/stpipe/tests/test_step.py @@ -597,7 +597,7 @@ def test_print_configspec(): step.print_configspec() -def test_call_with_config(caplog, function_jail): +def test_call_with_config(caplog, tmp_cwd): """Test call using a config file with substeps In particular, from JP-1482, there was a case where a substep parameter diff --git a/jwst/straylight/tests/test_straylight_step.py b/jwst/straylight/tests/test_straylight_step.py index 3a78e1861e..b011a458c3 100644 --- a/jwst/straylight/tests/test_straylight_step.py +++ b/jwst/straylight/tests/test_straylight_step.py @@ -26,7 +26,7 @@ def miri_mrs_short_tso(): return image -def test_call_straylight_mrsshort_tso(function_jail, miri_mrs_short_tso): +def test_call_straylight_mrsshort_tso(tmp_cwd, miri_mrs_short_tso): """Test step is skipped for MRS IFUSHORT TSO data""" result = StraylightStep.call(miri_mrs_short_tso) assert result.meta.cal_step.straylight == 'SKIPPED' diff --git a/jwst/tests/test_infrastructure.py b/jwst/tests/test_infrastructure.py index f19c240fe6..b81c57ff44 100644 --- a/jwst/tests/test_infrastructure.py +++ b/jwst/tests/test_infrastructure.py @@ -36,7 +36,7 @@ def test_word_precision_check(): ('*.fits', 0) ], ids=['all', 'txt', 'fits'] ) -def test_data_glob_local(glob_filter, nfiles, function_jail): +def test_data_glob_local(glob_filter, nfiles, tmp_cwd): """Test working of local globbing Parameters diff --git a/jwst/wfs_combine/tests/test_wfs_combine.py b/jwst/wfs_combine/tests/test_wfs_combine.py index 683919dd97..dac3a753d0 100644 --- a/jwst/wfs_combine/tests/test_wfs_combine.py +++ b/jwst/wfs_combine/tests/test_wfs_combine.py @@ -101,7 +101,7 @@ def wfs_association(tmp_path_factory): (1, 3, SATURATED, SATURATED, 2, SATURATED), ] ) -def test_create_combined(function_jail, wfs_association, +def test_create_combined(tmp_cwd, wfs_association, data1, data2, dq1, dq2, result_data, result_dq): path_asn, path1, path2 = wfs_association From 4a8806c0cbdf94ae71e85becd7caa3f11ba9f90d Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Mon, 11 Mar 2024 18:29:54 -0400 Subject: [PATCH 09/16] changed os.path.join to /, intermediate commit with known failures --- CHANGES.rst | 2 ++ jwst/assign_wcs/tests/test_schemas.py | 2 +- jwst/assign_wcs/tests/test_wcs.py | 5 ++--- jwst/associations/tests/test_asn_from_list.py | 12 ++++++------ jwst/associations/tests/test_pool.py | 2 +- jwst/background/tests/test_background.py | 4 ++-- jwst/cube_build/tests/test_cube_build_step.py | 3 +-- jwst/cube_build/tests/test_miri_cubepars.py | 3 +-- .../cube_build/tests/test_nirspec_cubepars.py | 3 +-- .../exp_to_source/tests/test_exp_to_source.py | 4 +--- jwst/exp_to_source/tests/test_main.py | 3 +-- .../extract_1d/tests/test_apply_apcorr_ifu.py | 5 ++--- jwst/jump/tests/test_jump_step.py | 9 ++++----- jwst/lib/tests/test_velocity_aberration.py | 3 +-- .../tests/test_master_background.py | 3 +-- jwst/ramp_fitting/tests/test_ramp_fit_step.py | 5 ++--- jwst/regtest/regtestdata.py | 3 ++- jwst/regtest/test_infrastructure.py | 12 ++++++------ jwst/skymatch/skyimage.py | 4 ++-- jwst/skymatch/tests/test_skymatch.py | 19 +++++++++---------- 20 files changed, 48 insertions(+), 58 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 115d47c508..2ad7f5d4d9 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -126,6 +126,8 @@ general - Replaced the ``_jail`` fixture from ``ci_watson`` with custom ``tmp_cwd`` to enforce ``no:legacypath`` in the CI tests. [#8327] +- Renamed the ``jail`` fixture with ``tmp_cwd_module``. [#8327] + jump ---- diff --git a/jwst/assign_wcs/tests/test_schemas.py b/jwst/assign_wcs/tests/test_schemas.py index bb49f0f6ed..50a26f2a73 100644 --- a/jwst/assign_wcs/tests/test_schemas.py +++ b/jwst/assign_wcs/tests/test_schemas.py @@ -50,7 +50,7 @@ def distortion_model(): def test_distortion_schema(distortion_model, tmp_path): """Make sure DistortionModel roundtrips""" - path = os.path.join(tmp_path, "test_dist.asdf") + path = tmp_path / "test_dist.asdf" dist = distortion_model dist.save(path) diff --git a/jwst/assign_wcs/tests/test_wcs.py b/jwst/assign_wcs/tests/test_wcs.py index 8a9fea4987..7f057263b4 100644 --- a/jwst/assign_wcs/tests/test_wcs.py +++ b/jwst/assign_wcs/tests/test_wcs.py @@ -1,5 +1,4 @@ import pytest -import os from numpy import zeros from numpy.testing import assert_allclose @@ -180,7 +179,7 @@ def test_create_fitswcs(tmp_path, create_model_3d): w3d = pointing.create_fitswcs(im) gra, gdec, glam = w3d(1, 1, 1) - path = os.path.join(tmp_path, "fitswcs.fits") + path = tmp_path / "fitswcs.fits" im.save(path) with fits.open(path) as hdulist: hdu = hdulist["SCI"] @@ -275,7 +274,7 @@ def test_sip_approx(tmp_path): assert_allclose(fitswcs_res.dec.deg, gwcs_dec, atol=1.5e-6) # now write the file out, read it back in, and check that the fit values are preserved - path = os.path.join(tmp_path, "tmp_sip_wcs.fits") + path = tmp_path / "tmp_sip_wcs.fits" result.write(path) with open(path) as result_read: diff --git a/jwst/associations/tests/test_asn_from_list.py b/jwst/associations/tests/test_asn_from_list.py index dbc9eefe9a..d61b33a7f6 100644 --- a/jwst/associations/tests/test_asn_from_list.py +++ b/jwst/associations/tests/test_asn_from_list.py @@ -68,10 +68,10 @@ def test_file_ext(): def test_level2_from_cmdline(tmp_path): """Create a level2 association from the command line""" rule = 'DMSLevel2bBase' - path = os.path.join(tmp_path, 'test_asn.json') + path = tmp_path / 'test_asn.json' inlist = ['a', 'b', 'c'] args = [ - '-o', path, + '-o', str(path), '-r', rule, ] args = args + inlist @@ -199,11 +199,11 @@ def test_cmdline_fails(): ) def test_cmdline_success(format, tmp_path): """Create Level3 associations in different formats""" - path = os.path.join(tmp_path, 'test_asn.json') + path = tmp_path / 'test_asn.json' product_name = 'test_product' inlist = ['a', 'b', 'c'] args = [ - '-o', path, + '-o', str(path), '--product-name', product_name, '--format', format ] @@ -224,10 +224,10 @@ def test_cmdline_success(format, tmp_path): def test_cmdline_change_rules(tmp_path): """Command line change the rule""" rule = 'Association' - path = os.path.join(tmp_path, 'test_asn.json') + path = tmp_path / 'test_asn.json' inlist = ['a', 'b', 'c'] args = [ - '-o', path, + '-o', str(path), '-r', rule, ] args = args + inlist diff --git a/jwst/associations/tests/test_pool.py b/jwst/associations/tests/test_pool.py index f666f69f45..91f12571df 100644 --- a/jwst/associations/tests/test_pool.py +++ b/jwst/associations/tests/test_pool.py @@ -10,7 +10,7 @@ def test_pool(tmp_path_factory): assert len(pool) == 636 tmp_path = tmp_path_factory.mktemp(__name__) - tmp_pool = os.path.join(tmp_path, 'tmp_pool.csv') + tmp_pool = tmp_path / 'tmp_pool.csv' pool.write(tmp_pool) roundtrip = AssociationPool.read(tmp_pool) diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index 94998222bc..8a28af1dea 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -22,7 +22,7 @@ def get_file_path(filename): """Construct an absolute path.""" - return os.path.join(data_path, filename) + return data_path / filename @pytest.fixture(scope='module') @@ -30,7 +30,7 @@ def background(tmp_path_factory): """Generate a background image to feed to background step""" filename = tmp_path_factory.mktemp('background_input') - filename = os.path.join(filename, 'background.fits') + filename = filename / 'background.fits' with datamodels.IFUImageModel((10, 10)) as image: image.data[:, :] = 10 image.meta.instrument.name = 'NIRSPEC' diff --git a/jwst/cube_build/tests/test_cube_build_step.py b/jwst/cube_build/tests/test_cube_build_step.py index 77bc98d524..d93c11e43d 100644 --- a/jwst/cube_build/tests/test_cube_build_step.py +++ b/jwst/cube_build/tests/test_cube_build_step.py @@ -5,7 +5,6 @@ import numpy as np import pytest from astropy.io import fits -import os from gwcs import WCS from stdatamodels.jwst.datamodels import IFUImageModel @@ -21,7 +20,7 @@ def miri_cube_pars(tmp_path_factory): """ Set up the miri cube pars reference file """ filename = tmp_path_factory.mktemp('cube_pars') - filename = os.path.join(filename, 'miri_cube_pars.fits') + filename = filename / 'miri_cube_pars.fits' hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'MIRI' diff --git a/jwst/cube_build/tests/test_miri_cubepars.py b/jwst/cube_build/tests/test_miri_cubepars.py index 757c8672ff..b51f8d919c 100644 --- a/jwst/cube_build/tests/test_miri_cubepars.py +++ b/jwst/cube_build/tests/test_miri_cubepars.py @@ -5,7 +5,6 @@ import numpy as np import pytest import math -import os from astropy.io import fits from jwst.cube_build import ifu_cube from jwst.cube_build import cube_build_io_util @@ -17,7 +16,7 @@ def miri_cube_pars(tmp_path_factory): """ Set up the miri cube pars reference file """ filename = tmp_path_factory.mktemp('cube_pars') - filename = os.path.join(filename, 'miri_cube_pars.fits') + filename = filename / 'miri_cube_pars.fits' hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'MIRI' diff --git a/jwst/cube_build/tests/test_nirspec_cubepars.py b/jwst/cube_build/tests/test_nirspec_cubepars.py index 9409763ac9..40a38b2933 100644 --- a/jwst/cube_build/tests/test_nirspec_cubepars.py +++ b/jwst/cube_build/tests/test_nirspec_cubepars.py @@ -9,7 +9,6 @@ from jwst.cube_build import ifu_cube from jwst.cube_build import cube_build_io_util from jwst.cube_build import instrument_defaults -import os @pytest.fixture(scope='module') @@ -17,7 +16,7 @@ def nirspec_cube_pars(tmp_path_factory): """ Set up the nirspec cube pars reference file """ filename = tmp_path_factory.mktemp('cube_pars') - filename = os.path.join(filename, 'nirspec_cube_pars.fits') + filename = filename / 'nirspec_cube_pars.fits' hdu0 = fits.PrimaryHDU() hdu0.header['REFTYPE'] = 'CUBEPAR' hdu0.header['INSTRUME'] = 'NIRSPEC' diff --git a/jwst/exp_to_source/tests/test_exp_to_source.py b/jwst/exp_to_source/tests/test_exp_to_source.py index b3f4060dee..0216140027 100644 --- a/jwst/exp_to_source/tests/test_exp_to_source.py +++ b/jwst/exp_to_source/tests/test_exp_to_source.py @@ -1,4 +1,3 @@ -import os import pytest import numpy as np @@ -37,9 +36,8 @@ def test_model_structure(run_exp_to_source): def test_model_roundtrip(tmp_path, run_exp_to_source): inputs, outputs = run_exp_to_source files = [] - path = str(tmp_path) for output in outputs: - file_path = os.path.join(path, output) + '.fits' + file_path = tmp_path / (output + '.fits') outputs[output].save(file_path) files.append(file_path) for file_path in files: diff --git a/jwst/exp_to_source/tests/test_main.py b/jwst/exp_to_source/tests/test_main.py index 2bdb50c6bf..67e3cd89a2 100644 --- a/jwst/exp_to_source/tests/test_main.py +++ b/jwst/exp_to_source/tests/test_main.py @@ -1,5 +1,4 @@ from glob import glob -import os from jwst.exp_to_source.tests import helpers from jwst.exp_to_source.main import Main @@ -20,7 +19,7 @@ def test_default_run(tmp_path, capsys): args.extend(helpers.INPUT_FILES) result = Main(args) assert len(result.sources) == 5 - files = glob(os.path.join(path, '*.fits')) + files = glob(tmp_path / '*.fits') assert len(files) == 5 diff --git a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py index 760e6e7457..0503855e7a 100644 --- a/jwst/extract_1d/tests/test_apply_apcorr_ifu.py +++ b/jwst/extract_1d/tests/test_apply_apcorr_ifu.py @@ -1,7 +1,6 @@ import pytest import numpy as np from asdf import AsdfFile -import os from stdatamodels.jwst.datamodels import IFUCubeModel, NrsIfuApcorrModel, MirMrsApcorrModel @@ -12,7 +11,7 @@ def dummy_nirspec_ref(tmp_path_factory): """ Generate a dummy apcorr ref file """ filename = tmp_path_factory.mktemp('dummy_apcorr') - filename = os.path.join(filename, 'dummy_nirspec_apcorr.asdf') + filename = filename / 'dummy_nirspec_apcorr.asdf' refap = {} refap['meta'] = {} @@ -55,7 +54,7 @@ def dummy_nirspec_ref(tmp_path_factory): def dummy_miri_ref(tmp_path_factory): """ Generate a dummy apcorr ref file """ filename = tmp_path_factory.mktemp('dummy_apcorr') - filename = os.path.join(filename, 'dummy_miri_apcorr.asdf') + filename = filename / 'dummy_miri_apcorr.asdf' refap = {} refap['meta'] = {} diff --git a/jwst/jump/tests/test_jump_step.py b/jwst/jump/tests/test_jump_step.py index 6e76007fcd..e0d64b36f6 100644 --- a/jwst/jump/tests/test_jump_step.py +++ b/jwst/jump/tests/test_jump_step.py @@ -2,7 +2,6 @@ import numpy as np import pytest -import os from stdatamodels.jwst.datamodels import GainModel, ReadnoiseModel, RampModel @@ -16,8 +15,8 @@ def generate_miri_reffiles(tmp_path_factory): def _generate_miri_reffiles(xsize=103, ysize=102, ingain=6): - gainfile = os.path.join(tmp_path_factory.mktemp("data"), "gain.fits") - readnoisefile = os.path.join(tmp_path_factory.mktemp("data"), 'readnoise.fits') + gainfile = tmp_path_factory.mktemp("data") / "gain.fits" + readnoisefile = tmp_path_factory.mktemp("data") / 'readnoise.fits' ingain = ingain xsize = xsize @@ -53,8 +52,8 @@ def _generate_miri_reffiles(xsize=103, ysize=102, ingain=6): def generate_nircam_reffiles(tmp_path_factory): def _generate_nircam_reffiles(xsize=20, ysize=20, ingain=6): - gainfile = os.path.join(tmp_path_factory.mktemp("ndata"), "gain.fits") - readnoisefile = os.path.join(tmp_path_factory.mktemp("ndata"), 'readnoise.fits') + gainfile = tmp_path_factory.mktemp("ndata") / "gain.fits" + readnoisefile = tmp_path_factory.mktemp("ndata") / 'readnoise.fits' ingain = ingain xsize = xsize diff --git a/jwst/lib/tests/test_velocity_aberration.py b/jwst/lib/tests/test_velocity_aberration.py index 3c921fb2e3..99f4726781 100644 --- a/jwst/lib/tests/test_velocity_aberration.py +++ b/jwst/lib/tests/test_velocity_aberration.py @@ -2,7 +2,6 @@ Test script for set_velocity_aberration.py """ import subprocess -import os from numpy import isclose from astropy.io import fits @@ -34,7 +33,7 @@ def test_compute_va_effects_zero_velocity(): def test_velocity_aberration_script(tmp_path): """Test the whole script on a FITS file""" - path = os.path.join(tmp_path, "velocity_aberration_tmpfile.fits") + path = tmp_path / "velocity_aberration_tmpfile.fits" model = dm.ImageModel() model.meta.ephemeris.velocity_x_bary = GOOD_VELOCITY[0] model.meta.ephemeris.velocity_y_bary = GOOD_VELOCITY[1] diff --git a/jwst/master_background/tests/test_master_background.py b/jwst/master_background/tests/test_master_background.py index 443a431cb3..16f65fa49c 100644 --- a/jwst/master_background/tests/test_master_background.py +++ b/jwst/master_background/tests/test_master_background.py @@ -4,7 +4,6 @@ import numpy as np import pytest import json -import os from stdatamodels.jwst import datamodels @@ -22,7 +21,7 @@ def user_background(tmp_path_factory): """Generate a user background spectrum""" filename = tmp_path_factory.mktemp('master_background_user_input') - filename = os.path.join(filename, 'user_background.fits') + filename = filename / 'user_background.fits' wavelength = np.linspace(0.5, 25, num=100) flux = np.linspace(2.0, 2.2, num=100) data = create_background(wavelength, flux) diff --git a/jwst/ramp_fitting/tests/test_ramp_fit_step.py b/jwst/ramp_fitting/tests/test_ramp_fit_step.py index 6e31e49e2a..92cc622c9a 100644 --- a/jwst/ramp_fitting/tests/test_ramp_fit_step.py +++ b/jwst/ramp_fitting/tests/test_ramp_fit_step.py @@ -1,6 +1,5 @@ import pytest import numpy as np -import os from stdatamodels.jwst.datamodels import dqflags, RampModel, GainModel, ReadnoiseModel @@ -182,8 +181,8 @@ def test_ramp_fit_step(generate_miri_reffiles, setup_inputs, max_cores): def test_subarray_5groups(tmp_path_factory): # all pixel values are zero. So slope should be zero - gainfile = os.path.join(tmp_path_factory.mktemp("data"), "gain.fits") - readnoisefile = os.path.join(tmp_path_factory.mktemp("data"), 'readnoise.fits') + gainfile = tmp_path_factory.mktemp("data") / "gain.fits" + readnoisefile = tmp_path_factory.mktemp("data") / 'readnoise.fits' model1, gdq, rnModel, pixdq, err, gain = setup_subarray_inputs( ngroups=5, subxstart=10, subystart=20, subxsize=5, subysize=15, readnoise=50) diff --git a/jwst/regtest/regtestdata.py b/jwst/regtest/regtestdata.py index 34f53dbda2..7eaa91243f 100644 --- a/jwst/regtest/regtestdata.py +++ b/jwst/regtest/regtestdata.py @@ -419,7 +419,8 @@ def text_diff(from_path, to_path): with open(to_path) as fh: to_lines = fh.readlines() - diffs = unified_diff(from_lines, to_lines, from_path, to_path) + # convert path objects to strings because difflib requires strings + diffs = unified_diff(from_lines, to_lines, str(from_path), str(to_path)) diff = list(diffs) if len(diff) > 0: diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index 0f44d3dfe5..a2b0276fdf 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -13,7 +13,7 @@ def test_regtestdata_get_data(rtdata): rtdata.get_data("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_cal.fits" - assert rtdata.input == os.path.join(os.getcwd(), "file1_rate.fits") + assert rtdata.input == os.getcwd() / "file1_rate.fits" @pytest.mark.bigdata @@ -21,7 +21,7 @@ def test_regtestdata_get_truth(rtdata): rtdata.get_truth("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_rate.fits" - assert rtdata.truth == os.path.join(os.getcwd(), "truth", "file1_rate.fits") + assert rtdata.truth == os.getcwd() / "truth" / "file1_rate.fits" @pytest.mark.bigdata @@ -41,8 +41,8 @@ def test_fitsdiff_defaults(fitsdiff_default_kwargs): @pytest.fixture def two_tables(tmp_path): """Return identical astropy tables written to 2 .ecsv file paths""" - path1 = os.path.join(tmp_path, "catalog1.ecsv") - path2 = os.path.join(tmp_path, "catalog2.ecsv") + path1 = tmp_path / "catalog1.ecsv" + path2 = tmp_path / "catalog2.ecsv" a = np.array([1, 4, 5], dtype=float) b = [2.0, 5.0, 8.5] c = ['x', 'y', 'z'] @@ -134,8 +134,8 @@ def test_diff_astropy_tables_all_equal(diff_astropy_tables, two_tables): def test_text_diff(tmp_path): - path1 = os.path.join(tmp_path, "test1.txt") - path2 = os.path.join(tmp_path, "test2.txt") + path1 = tmp_path / "test1.txt" + path2 = tmp_path / "test2.txt" with open(path1, "w") as text_file: print("foo", file=text_file) with open(path2, "w") as text_file: diff --git a/jwst/skymatch/skyimage.py b/jwst/skymatch/skyimage.py index a8911b106a..65bc943bec 100644 --- a/jwst/skymatch/skyimage.py +++ b/jwst/skymatch/skyimage.py @@ -70,14 +70,14 @@ def get_data_shape(self): class NDArrayMappedAccessor(DataAccessor): """ Data accessor for arrays stored in temporary files. """ def __init__(self, data, tmpfile=None, prefix='tmp_skymatch_', - suffix='.npy', tmp_path=''): + suffix='.npy', tmpdir=''): super().__init__() if tmpfile is None: self._close = True self._tmp = tempfile.NamedTemporaryFile( prefix=prefix, suffix=suffix, - dir=tmp_path + dir=tmpdir ) if not self._tmp: raise RuntimeError("Unable to create temporary file.") diff --git a/jwst/skymatch/tests/test_skymatch.py b/jwst/skymatch/tests/test_skymatch.py index f83d3db815..774b04e2b7 100644 --- a/jwst/skymatch/tests/test_skymatch.py +++ b/jwst/skymatch/tests/test_skymatch.py @@ -363,7 +363,7 @@ def test_skymatch_overlap(nircam_rate, skymethod, subtract, skystat): assert abs(np.mean(im.data[dq_mask]) - lev) < 0.01 -def test_asn_input(nircam_rate, tmp_path): +def test_asn_input(tmp_cwd, nircam_rate, tmp_path): # This is the same test as 'test_skymatch_overlap' with # skymethod='match', subtract=True, skystat='mean' and with memory saving # feature enabled (data loaded from files as needed). @@ -393,9 +393,9 @@ def test_asn_input(nircam_rate, tmp_path): for im, lev in zip(container, levels): im.data += np.random.normal(loc=lev, scale=0.1, size=im.data.shape) - im1_path = str(tmp_path / "skymatch_im1.fits") - im2_path = str(tmp_path / "skymatch_im2.fits") - im3_path = str(tmp_path / "skymatch_im3.fits") + im1_path = "skymatch_im1.fits" + im2_path = "skymatch_im2.fits" + im3_path = "skymatch_im3.fits" im1.write(im1_path) im2.write(im2_path) @@ -407,7 +407,7 @@ def test_asn_input(nircam_rate, tmp_path): product_name='skymatch' ) asn_out_fname, out_serialized = assoc_out.dump(format='json') - asn_out_fname = str(tmp_path / asn_out_fname) + asn_out_fname = asn_out_fname with open(asn_out_fname, "w") as asn_out: asn_out.write(out_serialized) @@ -454,7 +454,7 @@ def test_asn_input(nircam_rate, tmp_path): ) ) ) -def test_skymatch_2x(nircam_rate, tmp_path, skymethod, subtract): +def test_skymatch_2x(tmp_cwd, nircam_rate, tmp_path, skymethod, subtract): # Test that repetitive applications of skymatch produce the same results np.random.seed(1) im1 = nircam_rate.copy() @@ -477,9 +477,9 @@ def test_skymatch_2x(nircam_rate, tmp_path, skymethod, subtract): for im, lev in zip(container, levels): im.data += np.random.normal(loc=lev, scale=0.1, size=im.data.shape) - im1_path = str(tmp_path / "skymatch_im1.fits") - im2_path = str(tmp_path / "skymatch_im2.fits") - im3_path = str(tmp_path / "skymatch_im3.fits") + im1_path = "skymatch_im1.fits" + im2_path = "skymatch_im2.fits" + im3_path = "skymatch_im3.fits" im1.write(im1_path) im2.write(im2_path) @@ -491,7 +491,6 @@ def test_skymatch_2x(nircam_rate, tmp_path, skymethod, subtract): product_name='skymatch' ) asn_out_fname, out_serialized = assoc_out.dump(format='json') - asn_out_fname = str(tmp_path / asn_out_fname) with open(asn_out_fname, "w") as asn_out: asn_out.write(out_serialized) From 0384d83f9b66b885ebb9b062a92eb080a704f1c8 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Tue, 12 Mar 2024 10:55:57 -0400 Subject: [PATCH 10/16] replaced jail with tmp_cwd_module, attempted fix Path validation errors --- jwst/assign_wcs/tests/test_schemas.py | 1 - jwst/background/tests/test_background.py | 18 +++++++----------- jwst/conftest.py | 11 +++++------ jwst/exp_to_source/tests/test_main.py | 5 ++--- jwst/jump/tests/test_jump_step.py | 4 ++-- jwst/lib/tests/test_pointing_summary.py | 2 +- .../tests/test_master_background.py | 3 ++- jwst/ramp_fitting/tests/test_ramp_fit_step.py | 2 +- jwst/regtest/conftest.py | 8 ++++---- jwst/regtest/test_fgs_guider.py | 2 +- jwst/regtest/test_miri_coron3.py | 2 +- jwst/regtest/test_miri_coron_image2.py | 2 +- jwst/regtest/test_miri_lrs_dedicated_mbkg.py | 2 +- jwst/regtest/test_miri_lrs_masterbg_user.py | 2 +- jwst/regtest/test_miri_lrs_nod_masterbg.py | 2 +- jwst/regtest/test_miri_lrs_slit_spec2.py | 2 +- jwst/regtest/test_miri_lrs_slit_spec3.py | 2 +- jwst/regtest/test_miri_lrs_slitless.py | 4 ++-- jwst/regtest/test_miri_mrs_dedicated_mbkg.py | 2 +- jwst/regtest/test_miri_mrs_nod_masterbg.py | 2 +- jwst/regtest/test_miri_mrs_spec2.py | 2 +- jwst/regtest/test_miri_mrs_spec3.py | 8 ++++---- .../test_miri_mrs_spec3_moving_target.py | 2 +- jwst/regtest/test_miri_mrs_tso.py | 2 +- jwst/regtest/test_nircam_align_to_gaia.py | 2 +- jwst/regtest/test_nircam_coron3.py | 2 +- jwst/regtest/test_nircam_image.py | 8 ++++---- jwst/regtest/test_nircam_subarray_4amp.py | 2 +- jwst/regtest/test_nircam_tsgrism.py | 2 +- jwst/regtest/test_nircam_tsimg.py | 2 +- jwst/regtest/test_nircam_wfs.py | 2 +- jwst/regtest/test_nircam_wfss_contam.py | 2 +- jwst/regtest/test_niriss_ami3.py | 2 +- jwst/regtest/test_niriss_soss.py | 10 +++++----- jwst/regtest/test_niriss_wfss.py | 4 ++-- jwst/regtest/test_nirspec_brightobj.py | 2 +- jwst/regtest/test_nirspec_fs_spec2.py | 2 +- jwst/regtest/test_nirspec_fs_spec3.py | 2 +- jwst/regtest/test_nirspec_ifu_spec2.py | 6 +++--- jwst/regtest/test_nirspec_ifu_spec3.py | 2 +- jwst/regtest/test_nirspec_ifu_spec3_emsm.py | 2 +- jwst/regtest/test_nirspec_imprint.py | 2 +- jwst/regtest/test_nirspec_irs2_detector1.py | 2 +- jwst/regtest/test_nirspec_masterbackground.py | 4 ++-- jwst/regtest/test_nirspec_mos_spec3.py | 2 +- jwst/regtest/test_nirspec_subarray.py | 2 +- jwst/regtest/test_schema_editor.py | 10 +++++----- 47 files changed, 81 insertions(+), 87 deletions(-) diff --git a/jwst/assign_wcs/tests/test_schemas.py b/jwst/assign_wcs/tests/test_schemas.py index 50a26f2a73..7a91bfd22a 100644 --- a/jwst/assign_wcs/tests/test_schemas.py +++ b/jwst/assign_wcs/tests/test_schemas.py @@ -1,6 +1,5 @@ import inspect import sys -import os import warnings from astropy.modeling import models diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index 8a28af1dea..be759bebf7 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -1,7 +1,7 @@ """ Unit tests for background subtraction """ -import os +import pathlib from astropy.stats import sigma_clipped_stats import pytest @@ -12,17 +12,13 @@ from jwst.assign_wcs import AssignWcsStep from jwst.background import BackgroundStep -from jwst.background.tests import data as data_directory from jwst.stpipe import Step from jwst.background.background_sub import robust_mean, mask_from_source_cat, no_NaN -data_path = os.path.split(os.path.abspath(data_directory.__file__))[0] - - -def get_file_path(filename): - """Construct an absolute path.""" - return data_path / filename +@pytest.fixture(scope="module") +def data_path(): + return pathlib.Path(__file__).parents[0] / "data" @pytest.fixture(scope='module') @@ -152,7 +148,7 @@ def test_nirspec_gwa_ytilt(tmp_cwd, background, science_image): @pytest.fixture(scope='module') -def make_wfss_datamodel(): +def make_wfss_datamodel(data_path): """Generate WFSS Observation""" wcsinfo = { 'dec_ref': -27.79156387419731, @@ -201,7 +197,7 @@ def make_wfss_datamodel(): image.meta.subarray._instance.update(subarray) image.meta.exposure._instance.update(exposure) image.data = np.random.rand(2048, 2048) - image.meta.source_catalog = get_file_path('test_cat.ecsv') + image.meta.source_catalog = str(data_path / "test_cat.ecsv") return image @@ -213,7 +209,7 @@ def make_wfss_datamodel(): @pytest.mark.parametrize("pupils", ['GRISMC', 'GRISMR']) @pytest.mark.parametrize("filters", filter_list) @pytest.mark.parametrize("detectors", ['NRCALONG', 'NRCBLONG']) -def test_nrc_wfss_background(filters, pupils, detectors, make_wfss_datamodel): +def test_nrc_wfss_background(tmp_cwd, filters, pupils, detectors, make_wfss_datamodel): """Test background subtraction for NIRCAM WFSS modes.""" data = make_wfss_datamodel diff --git a/jwst/conftest.py b/jwst/conftest.py index 7cd1ba5fd2..e46d8f335e 100644 --- a/jwst/conftest.py +++ b/jwst/conftest.py @@ -53,11 +53,10 @@ def slow(request): @pytest.fixture(scope="module") -def jail(request, tmp_path_factory): - """Run test in a pristine temporary working directory, scoped to module. - - This fixture is the same as _jail in ci_watson, but scoped to module - instead of function. This allows a fixture using it to produce files in a +def tmp_cwd_module(request, tmp_path_factory): + """ + Run test in a pristine temporary working directory, scoped to module. + This allows a fixture using it to produce files in a temporary directory, and then have the tests access them. """ old_dir = os.getcwd() @@ -72,7 +71,7 @@ def jail(request, tmp_path_factory): @pytest.fixture def tmp_cwd(tmp_path): - """Perform test in a pristine temporary working directory.""" + """Perform test in a pristine temporary working directory, scoped to function.""" old_dir = Path.cwd() os.chdir(tmp_path) try: diff --git a/jwst/exp_to_source/tests/test_main.py b/jwst/exp_to_source/tests/test_main.py index 67e3cd89a2..9ed3321bc3 100644 --- a/jwst/exp_to_source/tests/test_main.py +++ b/jwst/exp_to_source/tests/test_main.py @@ -11,15 +11,14 @@ def test_help(capsys): def test_default_run(tmp_path, capsys): - path = str(tmp_path) args = [ '-o', - path + str(tmp_path) ] args.extend(helpers.INPUT_FILES) result = Main(args) assert len(result.sources) == 5 - files = glob(tmp_path / '*.fits') + files = glob(str(tmp_path / '*.fits')) assert len(files) == 5 diff --git a/jwst/jump/tests/test_jump_step.py b/jwst/jump/tests/test_jump_step.py index e0d64b36f6..3ff600e900 100644 --- a/jwst/jump/tests/test_jump_step.py +++ b/jwst/jump/tests/test_jump_step.py @@ -43,7 +43,7 @@ def _generate_miri_reffiles(xsize=103, ysize=102, ingain=6): readnoise_model.save(readnoisefile) readnoise_model.close() - return gainfile, readnoisefile + return str(gainfile), str(readnoisefile) return _generate_miri_reffiles @@ -80,7 +80,7 @@ def _generate_nircam_reffiles(xsize=20, ysize=20, ingain=6): readnoise_model.save(readnoisefile) readnoise_model.close() - return gainfile, readnoisefile + return str(gainfile), str(readnoisefile) return _generate_nircam_reffiles diff --git a/jwst/lib/tests/test_pointing_summary.py b/jwst/lib/tests/test_pointing_summary.py index 072557e9f2..b7665e1292 100644 --- a/jwst/lib/tests/test_pointing_summary.py +++ b/jwst/lib/tests/test_pointing_summary.py @@ -29,7 +29,7 @@ def engdb(): @pytest.fixture(scope='module') -def data_path(jail): +def data_path(tmp_cwd_module): """Create data file with needed header parameters""" model = ImageModel() diff --git a/jwst/master_background/tests/test_master_background.py b/jwst/master_background/tests/test_master_background.py index 16f65fa49c..bf3fb2e136 100644 --- a/jwst/master_background/tests/test_master_background.py +++ b/jwst/master_background/tests/test_master_background.py @@ -26,7 +26,8 @@ def user_background(tmp_path_factory): flux = np.linspace(2.0, 2.2, num=100) data = create_background(wavelength, flux) data.save(filename) - return filename + # filename must be string not Path to validate with current stpipe version + return str(filename) @pytest.fixture(scope='function') diff --git a/jwst/ramp_fitting/tests/test_ramp_fit_step.py b/jwst/ramp_fitting/tests/test_ramp_fit_step.py index 92cc622c9a..381996e978 100644 --- a/jwst/ramp_fitting/tests/test_ramp_fit_step.py +++ b/jwst/ramp_fitting/tests/test_ramp_fit_step.py @@ -198,7 +198,7 @@ def test_subarray_5groups(tmp_path_factory): # Call ramp fit through the step class slopes, cube_model = RampFitStep.call( - model1, override_gain=gainfile, override_readnoise=readnoisefile, + model1, override_gain=str(gainfile), override_readnoise=str(readnoisefile), maximum_cores="none", save_opt=True) assert slopes is not None diff --git a/jwst/regtest/conftest.py b/jwst/regtest/conftest.py index 4a06f0cbb5..856309bed1 100644 --- a/jwst/regtest/conftest.py +++ b/jwst/regtest/conftest.py @@ -107,8 +107,8 @@ def artifactory_result_path(): # The tmp_cwd fixture sets tmp_path cwd = str(request.node.funcargs['tmp_path']) except KeyError: - # The jail fixture (module-scoped) returns the path - cwd = str(request.node.funcargs['jail']) + # The tmp_cwd_module fixture (module-scoped) returns the path + cwd = str(request.node.funcargs['tmp_cwd_module']) rtdata.remote_results_path = artifactory_result_path() rtdata.test_name = request.node.name # Dump the failed test traceback into rtdata @@ -215,7 +215,7 @@ def rtdata(artifactory_repos, envopt, request, tmp_cwd): @pytest.fixture(scope='module') -def rtdata_module(artifactory_repos, envopt, request, jail): +def rtdata_module(artifactory_repos, envopt, request, tmp_cwd_module): return _rtdata_fixture_implementation(artifactory_repos, envopt, request) @@ -227,7 +227,7 @@ def _sdpdata_fixture_implementation(artifactory_repos, envopt, request): @pytest.fixture(scope='module') -def sdpdata_module(artifactory_repos, envopt, request, jail): +def sdpdata_module(artifactory_repos, envopt, request, tmp_cwd_module): return _sdpdata_fixture_implementation(artifactory_repos, envopt, request) diff --git a/jwst/regtest/test_fgs_guider.py b/jwst/regtest/test_fgs_guider.py index a722d15b9e..7cc870dab4 100644 --- a/jwst/regtest/test_fgs_guider.py +++ b/jwst/regtest/test_fgs_guider.py @@ -11,7 +11,7 @@ @pytest.fixture(scope='module', params=file_roots, ids=file_roots) -def run_guider_pipelines(jail, rtdata_module, request): +def run_guider_pipelines(tmp_cwd_module, rtdata_module, request): """Run pipeline for guider data""" rtdata = rtdata_module rtdata.get_data('fgs/level1b/' + request.param + '_uncal.fits') diff --git a/jwst/regtest/test_miri_coron3.py b/jwst/regtest/test_miri_coron3.py index a6c9280b71..b7c85926b0 100644 --- a/jwst/regtest/test_miri_coron3.py +++ b/jwst/regtest/test_miri_coron3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_coron3 on MIRI 4QPM coronographic data.""" rtdata = rtdata_module rtdata.get_asn("miri/coron/jw01386-c1002_20230109t015044_coron3_00001_asn.json") diff --git a/jwst/regtest/test_miri_coron_image2.py b/jwst/regtest/test_miri_coron_image2.py index e5143c1bc0..7032958f92 100644 --- a/jwst/regtest/test_miri_coron_image2.py +++ b/jwst/regtest/test_miri_coron_image2.py @@ -7,7 +7,7 @@ from jwst.stpipe import Step @pytest.fixture(scope='module') -def run_image2(jail, rtdata_module): +def run_image2(tmp_cwd_module, rtdata_module): """Run the calwebb_image2 pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_dedicated_mbkg.py b/jwst/regtest/test_miri_lrs_dedicated_mbkg.py index 47e48d5fe0..f36fddb224 100644 --- a/jwst/regtest/test_miri_lrs_dedicated_mbkg.py +++ b/jwst/regtest/test_miri_lrs_dedicated_mbkg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_masterbg_user.py b/jwst/regtest/test_miri_lrs_masterbg_user.py index b9991768de..06e90da9fe 100644 --- a/jwst/regtest/test_miri_lrs_masterbg_user.py +++ b/jwst/regtest/test_miri_lrs_masterbg_user.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_nod_masterbg.py b/jwst/regtest/test_miri_lrs_nod_masterbg.py index 592099a23e..c1563d2ebe 100644 --- a/jwst/regtest/test_miri_lrs_nod_masterbg.py +++ b/jwst/regtest/test_miri_lrs_nod_masterbg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_slit_spec2.py b/jwst/regtest/test_miri_lrs_slit_spec2.py index aaf631fb4f..0452107ff8 100644 --- a/jwst/regtest/test_miri_lrs_slit_spec2.py +++ b/jwst/regtest/test_miri_lrs_slit_spec2.py @@ -10,7 +10,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run the calwebb_spec2 pipeline on an ASN of nodded MIRI LRS fixedslit exposures.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_slit_spec3.py b/jwst/regtest/test_miri_lrs_slit_spec3.py index 68410757db..91953f1d29 100644 --- a/jwst/regtest/test_miri_lrs_slit_spec3.py +++ b/jwst/regtest/test_miri_lrs_slit_spec3.py @@ -13,7 +13,7 @@ scope="module", params=["default_wcs", "user_wcs", "user_wcs+shape", "user_wcs+shape1"] ) -def run_pipeline(jail, rtdata_module, request): +def run_pipeline(tmp_cwd_module, rtdata_module, request): """ Run the calwebb_spec3 pipeline on an ASN of nodded MIRI LRS fixed-slit exposures using different options for the WCS and output diff --git a/jwst/regtest/test_miri_lrs_slitless.py b/jwst/regtest/test_miri_lrs_slitless.py index d39b08f296..724af78d9b 100644 --- a/jwst/regtest/test_miri_lrs_slitless.py +++ b/jwst/regtest/test_miri_lrs_slitless.py @@ -15,7 +15,7 @@ @pytest.fixture(scope="module") -def run_tso1_pipeline(jail, rtdata_module): +def run_tso1_pipeline(tmp_cwd_module, rtdata_module): """Run the calwebb_tso1 pipeline on a MIRI LRS slitless exposure.""" rtdata = rtdata_module rtdata.get_data(f"miri/lrs/{DATASET1_ID}_uncal.fits") @@ -34,7 +34,7 @@ def run_tso1_pipeline(jail, rtdata_module): @pytest.fixture(scope="module") -def run_tso_spec2_pipeline(run_tso1_pipeline, jail, rtdata_module): +def run_tso_spec2_pipeline(run_tso1_pipeline, tmp_cwd_module, rtdata_module): """Run the calwebb_tso-spec2 pipeline on a MIRI LRS slitless exposure.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_dedicated_mbkg.py b/jwst/regtest/test_miri_mrs_dedicated_mbkg.py index d01d52a8fb..75deea4a59 100644 --- a/jwst/regtest/test_miri_mrs_dedicated_mbkg.py +++ b/jwst/regtest/test_miri_mrs_dedicated_mbkg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_nod_masterbg.py b/jwst/regtest/test_miri_mrs_nod_masterbg.py index 7a3449c544..03d52d9214 100644 --- a/jwst/regtest/test_miri_mrs_nod_masterbg.py +++ b/jwst/regtest/test_miri_mrs_nod_masterbg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_spec2.py b/jwst/regtest/test_miri_mrs_spec2.py index 5149f4e068..bf08c0195e 100644 --- a/jwst/regtest/test_miri_mrs_spec2.py +++ b/jwst/regtest/test_miri_mrs_spec2.py @@ -16,7 +16,7 @@ @pytest.fixture(scope='module') -def run_spec2(jail, rtdata_module): +def run_spec2(tmp_cwd_module, rtdata_module): """Run the Spec2Pipeline on a single exposure""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_spec3.py b/jwst/regtest/test_miri_mrs_spec3.py index 017eb942ff..592af322d7 100644 --- a/jwst/regtest/test_miri_mrs_spec3.py +++ b/jwst/regtest/test_miri_mrs_spec3.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_ifushort(jail, rtdata_module): +def run_spec3_ifushort(tmp_cwd_module, rtdata_module): """Run the Spec3Pipeline on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT @@ -30,7 +30,7 @@ def run_spec3_ifushort(jail, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifulong(jail, rtdata_module): +def run_spec3_ifulong(tmp_cwd_module, rtdata_module): """Run the Spec3Pipeline dithered flight data """ # Test has bands medium and long for IFULONG @@ -50,7 +50,7 @@ def run_spec3_ifulong(jail, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifushort_emsm(jail, rtdata_module): +def run_spec3_ifushort_emsm(tmp_cwd_module, rtdata_module): """Run the Spec3Pipeline (cube_build using weighting emsm) on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT @@ -72,7 +72,7 @@ def run_spec3_ifushort_emsm(jail, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifushort_extract1d(jail, rtdata_module): +def run_spec3_ifushort_extract1d(tmp_cwd_module, rtdata_module): """Run the Spec3Pipeline on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT diff --git a/jwst/regtest/test_miri_mrs_spec3_moving_target.py b/jwst/regtest/test_miri_mrs_spec3_moving_target.py index 9794f788c2..73e3e69234 100644 --- a/jwst/regtest/test_miri_mrs_spec3_moving_target.py +++ b/jwst/regtest/test_miri_mrs_spec3_moving_target.py @@ -10,7 +10,7 @@ @pytest.fixture(scope='module') -def run_spec3_moving_target(jail, rtdata_module): +def run_spec3_moving_target(tmp_cwd_module, rtdata_module): """Run the Spec3Pipeline dithered flight data """ # Association has 2 exposures from IFUSHORT diff --git a/jwst/regtest/test_miri_mrs_tso.py b/jwst/regtest/test_miri_mrs_tso.py index a4efa7f1c4..1f459ef432 100644 --- a/jwst/regtest/test_miri_mrs_tso.py +++ b/jwst/regtest/test_miri_mrs_tso.py @@ -10,7 +10,7 @@ @pytest.fixture(scope='module') -def run_spec2(jail, rtdata_module): +def run_spec2(tmp_cwd_module, rtdata_module): """Run the Spec2Pipeline on a single exposure""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nircam_align_to_gaia.py b/jwst/regtest/test_nircam_align_to_gaia.py index 6eac063cb1..24167e96a0 100644 --- a/jwst/regtest/test_nircam_align_to_gaia.py +++ b/jwst/regtest/test_nircam_align_to_gaia.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_image3pipeline(rtdata_module, jail): +def run_image3pipeline(rtdata_module, tmp_cwd_module): ''' Run calwebb_image3 on NIRCam imaging and align to gaia ''' rtdata = rtdata_module diff --git a/jwst/regtest/test_nircam_coron3.py b/jwst/regtest/test_nircam_coron3.py index 73dc117456..2d7b14fcdf 100644 --- a/jwst/regtest/test_nircam_coron3.py +++ b/jwst/regtest/test_nircam_coron3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_coron3 on coronographic data.""" rtdata = rtdata_module rtdata.get_asn("nircam/coron/jw01386-c1020_20220909t073458_coron3_002a_asn.json") diff --git a/jwst/regtest/test_nircam_image.py b/jwst/regtest/test_nircam_image.py index ed65f3d351..42402be67d 100644 --- a/jwst/regtest/test_nircam_image.py +++ b/jwst/regtest/test_nircam_image.py @@ -11,7 +11,7 @@ @pytest.fixture(scope="module") -def run_detector1pipeline(jail, rtdata_module): +def run_detector1pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_detector1 on NIRCam imaging long data""" rtdata = rtdata_module rtdata.get_data("nircam/image/jw01538046001_03105_00001_nrcalong_uncal.fits") @@ -31,7 +31,7 @@ def run_detector1pipeline(jail, rtdata_module): @pytest.fixture(scope="module") -def run_image2pipeline(run_detector1pipeline, jail, rtdata_module): +def run_image2pipeline(run_detector1pipeline, tmp_cwd_module, rtdata_module): """Run calwebb_image2 on NIRCam imaging long data""" rtdata = rtdata_module rtdata.input = "jw01538046001_03105_00001_nrcalong_rate.fits" @@ -43,7 +43,7 @@ def run_image2pipeline(run_detector1pipeline, jail, rtdata_module): @pytest.fixture(scope="module") -def run_image3pipeline(run_image2pipeline, rtdata_module, jail): +def run_image3pipeline(run_image2pipeline, rtdata_module, tmp_cwd_module): """Run calwebb_image3 on NIRCam imaging long data""" rtdata = rtdata_module # Grab rest of _rate files for the asn and run image2 pipeline on each to @@ -170,7 +170,7 @@ def test_nircam_image_stage3_segm(run_image3pipeline, rtdata_module, fitsdiff_de @pytest.fixture() -def run_image3_closedfile(rtdata, jail): +def run_image3_closedfile(rtdata, tmp_cwd_module): """Run calwebb_image3 on NIRCam imaging with data that had a closed file issue.""" rtdata.get_asn("nircam/image/fail_short_image3_asn.json") diff --git a/jwst/regtest/test_nircam_subarray_4amp.py b/jwst/regtest/test_nircam_subarray_4amp.py index 8a0b5ed099..f555b9f822 100644 --- a/jwst/regtest/test_nircam_subarray_4amp.py +++ b/jwst/regtest/test_nircam_subarray_4amp.py @@ -14,7 +14,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_detector1 pipeline on NIRCAM subarray data.""" rtdata = rtdata_module rtdata.get_data("nircam/subarray/jw00617196001_02102_00001_nrca4_uncal.fits") diff --git a/jwst/regtest/test_nircam_tsgrism.py b/jwst/regtest/test_nircam_tsgrism.py index bca7ebcd9f..4ceb3467bb 100644 --- a/jwst/regtest/test_nircam_tsgrism.py +++ b/jwst/regtest/test_nircam_tsgrism.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipelines(jail, rtdata_module): +def run_pipelines(tmp_cwd_module, rtdata_module): """Run stage 2-3 tso pipelines on NIRCAM TSO grism data.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nircam_tsimg.py b/jwst/regtest/test_nircam_tsimg.py index 56a96a50b3..6b70921d19 100644 --- a/jwst/regtest/test_nircam_tsimg.py +++ b/jwst/regtest/test_nircam_tsimg.py @@ -11,7 +11,7 @@ @pytest.fixture(scope="module") -def run_pipelines(jail, rtdata_module): +def run_pipelines(tmp_cwd_module, rtdata_module): """Run stage 2 and 3 pipelines on NIRCam TSO image data.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nircam_wfs.py b/jwst/regtest/test_nircam_wfs.py index 4505333457..9390cfc762 100644 --- a/jwst/regtest/test_nircam_wfs.py +++ b/jwst/regtest/test_nircam_wfs.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipelines(jail, rtdata_module): +def run_pipelines(tmp_cwd_module, rtdata_module): """Run the calwebb_wfs-image2 and calwebb_wfs-image3 pipelines on NIRCam WFS&C images. The calwebb_wfs-image3 pipeline is run twice: once with default params and a second time with diff --git a/jwst/regtest/test_nircam_wfss_contam.py b/jwst/regtest/test_nircam_wfss_contam.py index b0d3faf19a..999f3ee151 100644 --- a/jwst/regtest/test_nircam_wfss_contam.py +++ b/jwst/regtest/test_nircam_wfss_contam.py @@ -5,7 +5,7 @@ @pytest.fixture(scope='module') -def run_wfss_contam(jail, rtdata_module): +def run_wfss_contam(tmp_cwd_module, rtdata_module): """Run the wfss_contam step""" rtdata = rtdata_module diff --git a/jwst/regtest/test_niriss_ami3.py b/jwst/regtest/test_niriss_ami3.py index 8e44cef950..0a1344425f 100644 --- a/jwst/regtest/test_niriss_ami3.py +++ b/jwst/regtest/test_niriss_ami3.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_ami3 on NIRISS AMI data.""" rtdata = rtdata_module rtdata.get_asn("niriss/ami/jw01093-c1000_20221110t003218_ami3_002_asn.json") diff --git a/jwst/regtest/test_niriss_soss.py b/jwst/regtest/test_niriss_soss.py index efb2253194..9b28a8edfe 100644 --- a/jwst/regtest/test_niriss_soss.py +++ b/jwst/regtest/test_niriss_soss.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_tso_spec2(jail, rtdata_module): +def run_tso_spec2(tmp_cwd_module, rtdata_module): """Run stage 2 pipeline on NIRISS SOSS data.""" rtdata = rtdata_module @@ -28,7 +28,7 @@ def run_tso_spec2(jail, rtdata_module): @pytest.fixture(scope="module") -def run_tso_spec3(jail, rtdata_module, run_tso_spec2): +def run_tso_spec3(tmp_cwd_module, rtdata_module, run_tso_spec2): """Run stage 3 pipeline on NIRISS SOSS data.""" rtdata = rtdata_module # Get the level3 association json file (though not its members) and run @@ -41,7 +41,7 @@ def run_tso_spec3(jail, rtdata_module, run_tso_spec2): @pytest.fixture(scope="module") -def run_atoca_extras(jail, rtdata_module): +def run_atoca_extras(tmp_cwd_module, rtdata_module): """Run stage 2 pipeline on NIRISS SOSS data using enhanced modes via parameter settings.""" rtdata = rtdata_module @@ -127,7 +127,7 @@ def test_niriss_soss_extras(rtdata_module, run_atoca_extras, fitsdiff_default_kw @pytest.fixture(scope='module') -def run_extract1d_spsolve_failure(jail, rtdata_module): +def run_extract1d_spsolve_failure(tmp_cwd_module, rtdata_module): """ Test coverage for fix to error thrown when spsolve fails to find a good solution in ATOCA and needs to be replaced with a least- @@ -145,7 +145,7 @@ def run_extract1d_spsolve_failure(jail, rtdata_module): @pytest.fixture(scope='module') -def run_extract1d_null_order2(jail, rtdata_module): +def run_extract1d_null_order2(tmp_cwd_module, rtdata_module): """ Test coverage for fix to error thrown when all of the pixels in order 2 are flagged as bad. Ensure graceful handling of the diff --git a/jwst/regtest/test_niriss_wfss.py b/jwst/regtest/test_niriss_wfss.py index 6a530273d4..a5b67b76a1 100644 --- a/jwst/regtest/test_niriss_wfss.py +++ b/jwst/regtest/test_niriss_wfss.py @@ -6,7 +6,7 @@ @pytest.fixture(scope='module') -def run_nis_wfss_spec2(jail, rtdata_module): +def run_nis_wfss_spec2(tmp_cwd_module, rtdata_module): """Run the calwebb_spec2 pipeline on NIRISS WFSS exposures""" rtdata = rtdata_module @@ -60,7 +60,7 @@ def test_nis_wfss_spec2(run_nis_wfss_spec2, rtdata_module, fitsdiff_default_kwar @pytest.fixture(scope='module') -def run_nis_wfss_spec3(run_nis_wfss_spec2, rtdata_module, jail): +def run_nis_wfss_spec3(run_nis_wfss_spec2, rtdata_module, tmp_cwd_module): """Run the calwebb_spec3 pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_brightobj.py b/jwst/regtest/test_nirspec_brightobj.py index 3d5bd65eb0..a437babac4 100644 --- a/jwst/regtest/test_nirspec_brightobj.py +++ b/jwst/regtest/test_nirspec_brightobj.py @@ -12,7 +12,7 @@ @pytest.fixture(scope="module") -def run_tso_spec2_pipeline(jail, rtdata_module, request): +def run_tso_spec2_pipeline(tmp_cwd_module, rtdata_module, request): """Run the calwebb_spec2 pipeline performed on NIRSpec fixed-slit data that uses the NRS_BRIGHTOBJ mode (S1600A1 slit) """ diff --git a/jwst/regtest/test_nirspec_fs_spec2.py b/jwst/regtest/test_nirspec_fs_spec2.py index 3b3f14ebf1..1c499d2602 100644 --- a/jwst/regtest/test_nirspec_fs_spec2.py +++ b/jwst/regtest/test_nirspec_fs_spec2.py @@ -35,7 +35,7 @@ @pytest.fixture(scope="module", params=file_roots) # ids=ids) -def run_pipeline(jail, rtdata_module, request): +def run_pipeline(tmp_cwd_module, rtdata_module, request): """Run the calwebb_spec2 pipeline on NIRSpec Fixed-Slit exposures. We currently test the following types of inputs: 1) Full-frame exposure (all slits will be extracted) diff --git a/jwst/regtest/test_nirspec_fs_spec3.py b/jwst/regtest/test_nirspec_fs_spec3.py index c6d9d828e9..07f0a5a84b 100644 --- a/jwst/regtest/test_nirspec_fs_spec3.py +++ b/jwst/regtest/test_nirspec_fs_spec3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """ Run the calwebb_spec3 pipeline on NIRSpec Fixed-Slit exposures. """ diff --git a/jwst/regtest/test_nirspec_ifu_spec2.py b/jwst/regtest/test_nirspec_ifu_spec2.py index 5eeb8516a3..18788ef158 100644 --- a/jwst/regtest/test_nirspec_ifu_spec2.py +++ b/jwst/regtest/test_nirspec_ifu_spec2.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec2(jail, rtdata_module): +def run_spec2(tmp_cwd_module, rtdata_module): """Run the Spec2Pipeline on a spec2 ASN containing a single exposure""" rtdata = rtdata_module @@ -50,7 +50,7 @@ def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix): @pytest.fixture() -def run_photom(jail, rtdata): +def run_photom(tmp_cwd_module, rtdata): """Run the photom step on an NRS IFU exposure with SRCTYPE=POINT""" # Setup the inputs @@ -76,7 +76,7 @@ def test_photom(run_photom, fitsdiff_default_kwargs): @pytest.fixture() -def run_extract1d(jail, rtdata): +def run_extract1d(tmp_cwd_module, rtdata): """Run the extract_1d step on an NRS IFU cube with SRCTYPE=POINT""" # Setup the inputs diff --git a/jwst/regtest/test_nirspec_ifu_spec3.py b/jwst/regtest/test_nirspec_ifu_spec3.py index ec31756bd2..81c1589a42 100644 --- a/jwst/regtest/test_nirspec_ifu_spec3.py +++ b/jwst/regtest/test_nirspec_ifu_spec3.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_multi(jail, rtdata_module): +def run_spec3_multi(tmp_cwd_module, rtdata_module): """Run Spec3Pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_ifu_spec3_emsm.py b/jwst/regtest/test_nirspec_ifu_spec3_emsm.py index d653fa4963..7616ccfc0a 100644 --- a/jwst/regtest/test_nirspec_ifu_spec3_emsm.py +++ b/jwst/regtest/test_nirspec_ifu_spec3_emsm.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_multi_emsm(jail, rtdata_module): +def run_spec3_multi_emsm(tmp_cwd_module, rtdata_module): """Run Spec3Pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_imprint.py b/jwst/regtest/test_nirspec_imprint.py index c4c9be6e60..5925415e3a 100644 --- a/jwst/regtest/test_nirspec_imprint.py +++ b/jwst/regtest/test_nirspec_imprint.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec2(jail, rtdata_module): +def run_spec2(tmp_cwd_module, rtdata_module): """Run the Spec2Pipeline on a spec2 ASN containing a single exposure with multiple imprint exposures""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_irs2_detector1.py b/jwst/regtest/test_nirspec_irs2_detector1.py index 0fba41cec0..caa81396c7 100644 --- a/jwst/regtest/test_nirspec_irs2_detector1.py +++ b/jwst/regtest/test_nirspec_irs2_detector1.py @@ -9,7 +9,7 @@ @pytest.fixture(scope="module") -def run_detector1pipeline(rtdata_module, jail): +def run_detector1pipeline(rtdata_module, tmp_cwd_module): """Run calwebb_detector1 pipeline on NIRSpec data with IRS2 readout mode.""" rtdata = rtdata_module rtdata.get_data("nirspec/irs2/jw0010010_11010_nrs1_chimera_uncal.fits") diff --git a/jwst/regtest/test_nirspec_masterbackground.py b/jwst/regtest/test_nirspec_masterbackground.py index c706dc7fd6..adde5b7ec3 100644 --- a/jwst/regtest/test_nirspec_masterbackground.py +++ b/jwst/regtest/test_nirspec_masterbackground.py @@ -13,7 +13,7 @@ @pytest.fixture(scope='module') -def run_spec2_mbkg(jail, rtdata_module): +def run_spec2_mbkg(tmp_cwd_module, rtdata_module): """Run Spec2 on MSA data with background slits""" rtdata = rtdata_module @@ -34,7 +34,7 @@ def run_spec2_mbkg(jail, rtdata_module): @pytest.fixture(scope='module') -def run_spec2_mbkg_user(jail, rtdata_module): +def run_spec2_mbkg_user(tmp_cwd_module, rtdata_module): """Run Spec2 on MSA data with a user-supplied master bkg spectrum""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_mos_spec3.py b/jwst/regtest/test_nirspec_mos_spec3.py index 86b7e60bd7..20209422eb 100644 --- a/jwst/regtest/test_nirspec_mos_spec3.py +++ b/jwst/regtest/test_nirspec_mos_spec3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_spec3 on NIRSpec MOS data.""" rtdata = rtdata_module rtdata.get_asn("nirspec/mos/jw00626-o030_20191210t193826_spec3_001_asn.json") diff --git a/jwst/regtest/test_nirspec_subarray.py b/jwst/regtest/test_nirspec_subarray.py index a8d4bfcd67..9ad005e223 100644 --- a/jwst/regtest/test_nirspec_subarray.py +++ b/jwst/regtest/test_nirspec_subarray.py @@ -13,7 +13,7 @@ @pytest.fixture(scope="module") -def run_pipeline(jail, rtdata_module): +def run_pipeline(tmp_cwd_module, rtdata_module): """Run calwebb_detector1 pipeline on NIRSpec subarray data.""" rtdata = rtdata_module rtdata.get_data("nirspec/fs/nrs1_group_subarray.fits") diff --git a/jwst/regtest/test_schema_editor.py b/jwst/regtest/test_schema_editor.py index a9d3dce74c..bd3924ed39 100644 --- a/jwst/regtest/test_schema_editor.py +++ b/jwst/regtest/test_schema_editor.py @@ -23,7 +23,7 @@ @pytest.fixture(scope='module') -def keyword_db(jail, rtdata_module): +def keyword_db(tmp_cwd_module, rtdata_module): """Define the keyword database""" rt = rtdata_module @@ -45,7 +45,7 @@ def model_db(): @pytest.fixture(scope='module') -def run_editor_full(jail, keyword_db): +def run_editor_full(tmp_cwd_module, keyword_db): """Just run the editor""" editor = se.Schema_editor( @@ -60,7 +60,7 @@ def run_editor_full(jail, keyword_db): @pytest.mark.bigdata -def test_limit_datamodels_from_file(jail, model_db, keyword_db, rtdata_module): +def test_limit_datamodels_from_file(tmp_cwd_module, model_db, keyword_db, rtdata_module): """Test limiting datamodels from Schema_editor""" # Create the exclusion file. @@ -99,7 +99,7 @@ def test_limit_datamodels(model_db): 'slitmeta.schema.yaml', 'wcsinfo.schema.yaml', ] ) -def test_full_run(jail, schema, run_editor_full, rtdata_module): +def test_full_run(tmp_cwd_module, schema, run_editor_full, rtdata_module): """Check fixed schema files""" rt = rtdata_module rt.output = os.path.join(run_editor_full, schema) @@ -109,7 +109,7 @@ def test_full_run(jail, schema, run_editor_full, rtdata_module): @pytest.mark.bigdata -def test_no_option_warning(jail, keyword_db): +def test_no_option_warning(tmp_cwd_module, keyword_db): """If no operations is given, raise an error""" editor = se.Schema_editor( input=keyword_db From 2c06ff6e468933be8589de4755fd168b99145b06 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Tue, 12 Mar 2024 16:23:27 -0400 Subject: [PATCH 11/16] fixing regtest failure in test_infrastructure --- jwst/regtest/test_infrastructure.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index a2b0276fdf..d66fd1560b 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -1,5 +1,6 @@ from glob import glob import os +import pathlib import pytest from astropy.table import Table @@ -9,19 +10,19 @@ @pytest.mark.bigdata -def test_regtestdata_get_data(rtdata): +def test_regtestdata_get_data(tmp_cwd, rtdata): rtdata.get_data("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_cal.fits" - assert rtdata.input == os.getcwd() / "file1_rate.fits" + assert rtdata.input == str(tmp_cwd / "file1_rate.fits") @pytest.mark.bigdata -def test_regtestdata_get_truth(rtdata): +def test_regtestdata_get_truth(tmp_cwd, rtdata): rtdata.get_truth("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_rate.fits" - assert rtdata.truth == os.getcwd() / "truth" / "file1_rate.fits" + assert rtdata.truth == str(tmp_cwd / "truth" / "file1_rate.fits") @pytest.mark.bigdata From b6e5c1ad331440e010a0d99283120fe9ede100f7 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Tue, 12 Mar 2024 16:26:05 -0400 Subject: [PATCH 12/16] forgot a style check --- jwst/regtest/test_infrastructure.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index d66fd1560b..b1e22e1d47 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -1,6 +1,5 @@ from glob import glob import os -import pathlib import pytest from astropy.table import Table From 0949102af7dd29854f21871b07e76657e708f7fd Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Wed, 13 Mar 2024 12:44:01 -0400 Subject: [PATCH 13/16] fixes based on @jdavies-st comments, incl remove all passes of tmp_cwd and rtdata together --- jwst/background/tests/test_background.py | 2 +- jwst/regtest/test_fgs_guider.py | 2 +- jwst/regtest/test_infrastructure.py | 4 ++-- jwst/regtest/test_miri_coron3.py | 2 +- jwst/regtest/test_miri_coron_image2.py | 2 +- jwst/regtest/test_miri_dark.py | 4 ++-- jwst/regtest/test_miri_lrs_dedicated_mbkg.py | 2 +- jwst/regtest/test_miri_lrs_masterbg_user.py | 2 +- jwst/regtest/test_miri_lrs_nod_masterbg.py | 2 +- jwst/regtest/test_miri_lrs_slit_spec2.py | 2 +- jwst/regtest/test_miri_lrs_slit_spec3.py | 2 +- jwst/regtest/test_miri_lrs_slitless.py | 4 ++-- jwst/regtest/test_miri_mrs_dedicated_mbkg.py | 2 +- jwst/regtest/test_miri_mrs_nod_masterbg.py | 2 +- jwst/regtest/test_miri_mrs_spec2.py | 2 +- jwst/regtest/test_miri_mrs_spec3.py | 8 ++++---- jwst/regtest/test_miri_mrs_spec3_moving_target.py | 2 +- jwst/regtest/test_miri_mrs_tso.py | 2 +- jwst/regtest/test_miri_setpointing.py | 2 +- jwst/regtest/test_miri_spectral_leak.py | 2 +- jwst/regtest/test_nircam_align_to_gaia.py | 2 +- jwst/regtest/test_nircam_coron3.py | 2 +- jwst/regtest/test_nircam_image.py | 9 +++++---- jwst/regtest/test_nircam_subarray_4amp.py | 2 +- jwst/regtest/test_nircam_tsgrism.py | 4 ++-- jwst/regtest/test_nircam_tsimg.py | 4 ++-- jwst/regtest/test_nircam_wfs.py | 2 +- jwst/regtest/test_nircam_wfss_contam.py | 2 +- jwst/regtest/test_niriss_ami3.py | 2 +- jwst/regtest/test_niriss_soss.py | 10 +++++----- jwst/regtest/test_niriss_wfss.py | 4 ++-- jwst/regtest/test_nirspec_brightobj.py | 2 +- jwst/regtest/test_nirspec_exceptions.py | 10 +++++----- jwst/regtest/test_nirspec_fs_spec2.py | 2 +- jwst/regtest/test_nirspec_fs_spec3.py | 2 +- jwst/regtest/test_nirspec_ifu_spec2.py | 10 +++++++--- jwst/regtest/test_nirspec_ifu_spec3.py | 2 +- jwst/regtest/test_nirspec_ifu_spec3_emsm.py | 2 +- jwst/regtest/test_nirspec_image2.py | 2 +- jwst/regtest/test_nirspec_imprint.py | 2 +- jwst/regtest/test_nirspec_irs2_detector1.py | 2 +- jwst/regtest/test_nirspec_masterbackground.py | 4 ++-- jwst/regtest/test_nirspec_mos_spec3.py | 2 +- jwst/regtest/test_nirspec_subarray.py | 2 +- jwst/regtest/test_schema_editor.py | 2 +- 45 files changed, 73 insertions(+), 68 deletions(-) diff --git a/jwst/background/tests/test_background.py b/jwst/background/tests/test_background.py index be759bebf7..04eeba15b5 100644 --- a/jwst/background/tests/test_background.py +++ b/jwst/background/tests/test_background.py @@ -18,7 +18,7 @@ @pytest.fixture(scope="module") def data_path(): - return pathlib.Path(__file__).parents[0] / "data" + return pathlib.Path(__file__).parent / "data" @pytest.fixture(scope='module') diff --git a/jwst/regtest/test_fgs_guider.py b/jwst/regtest/test_fgs_guider.py index 7cc870dab4..af1e2b2a90 100644 --- a/jwst/regtest/test_fgs_guider.py +++ b/jwst/regtest/test_fgs_guider.py @@ -11,7 +11,7 @@ @pytest.fixture(scope='module', params=file_roots, ids=file_roots) -def run_guider_pipelines(tmp_cwd_module, rtdata_module, request): +def run_guider_pipelines(rtdata_module, request): """Run pipeline for guider data""" rtdata = rtdata_module rtdata.get_data('fgs/level1b/' + request.param + '_uncal.fits') diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index b1e22e1d47..c60e3fefb0 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -9,7 +9,7 @@ @pytest.mark.bigdata -def test_regtestdata_get_data(tmp_cwd, rtdata): +def test_regtestdata_get_data(rtdata): rtdata.get_data("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_cal.fits" @@ -17,7 +17,7 @@ def test_regtestdata_get_data(tmp_cwd, rtdata): @pytest.mark.bigdata -def test_regtestdata_get_truth(tmp_cwd, rtdata): +def test_regtestdata_get_truth(rtdata): rtdata.get_truth("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_rate.fits" diff --git a/jwst/regtest/test_miri_coron3.py b/jwst/regtest/test_miri_coron3.py index b7c85926b0..d10af9e65d 100644 --- a/jwst/regtest/test_miri_coron3.py +++ b/jwst/regtest/test_miri_coron3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_coron3 on MIRI 4QPM coronographic data.""" rtdata = rtdata_module rtdata.get_asn("miri/coron/jw01386-c1002_20230109t015044_coron3_00001_asn.json") diff --git a/jwst/regtest/test_miri_coron_image2.py b/jwst/regtest/test_miri_coron_image2.py index 7032958f92..c43dea38d9 100644 --- a/jwst/regtest/test_miri_coron_image2.py +++ b/jwst/regtest/test_miri_coron_image2.py @@ -7,7 +7,7 @@ from jwst.stpipe import Step @pytest.fixture(scope='module') -def run_image2(tmp_cwd_module, rtdata_module): +def run_image2(rtdata_module): """Run the calwebb_image2 pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_dark.py b/jwst/regtest/test_miri_dark.py index 82a1c4c0f1..61aeb1f9d0 100644 --- a/jwst/regtest/test_miri_dark.py +++ b/jwst/regtest/test_miri_dark.py @@ -9,7 +9,7 @@ 'exposure', ['jw00001001001_01101_00001_mirimage', 'jw02201001001_01101_00001_MIRIMAGE'] ) -def test_miri_dark_pipeline(exposure, tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_miri_dark_pipeline(exposure, rtdata, fitsdiff_default_kwargs): """Test the DarkPipeline on MIRI dark exposures""" rtdata.get_data(f"miri/image/{exposure}_uncal.fits") @@ -28,7 +28,7 @@ def test_miri_dark_pipeline(exposure, tmp_cwd, rtdata, fitsdiff_default_kwargs): 'exposure', ['jw01033005001_04103_00001-seg003_mirimage'] ) -def test_miri_segmented_dark(exposure, tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_miri_segmented_dark(exposure, rtdata, fitsdiff_default_kwargs): """Test the dark_current step on MIRI segmented exposures""" rtdata.get_data(f"miri/image/{exposure}_linearity.fits") diff --git a/jwst/regtest/test_miri_lrs_dedicated_mbkg.py b/jwst/regtest/test_miri_lrs_dedicated_mbkg.py index f36fddb224..50ef78cb5c 100644 --- a/jwst/regtest/test_miri_lrs_dedicated_mbkg.py +++ b/jwst/regtest/test_miri_lrs_dedicated_mbkg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_masterbg_user.py b/jwst/regtest/test_miri_lrs_masterbg_user.py index 06e90da9fe..e57570bdbc 100644 --- a/jwst/regtest/test_miri_lrs_masterbg_user.py +++ b/jwst/regtest/test_miri_lrs_masterbg_user.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_nod_masterbg.py b/jwst/regtest/test_miri_lrs_nod_masterbg.py index c1563d2ebe..0a3b2ba203 100644 --- a/jwst/regtest/test_miri_lrs_nod_masterbg.py +++ b/jwst/regtest/test_miri_lrs_nod_masterbg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_slit_spec2.py b/jwst/regtest/test_miri_lrs_slit_spec2.py index 0452107ff8..7340a0b0c5 100644 --- a/jwst/regtest/test_miri_lrs_slit_spec2.py +++ b/jwst/regtest/test_miri_lrs_slit_spec2.py @@ -10,7 +10,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run the calwebb_spec2 pipeline on an ASN of nodded MIRI LRS fixedslit exposures.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_lrs_slit_spec3.py b/jwst/regtest/test_miri_lrs_slit_spec3.py index 91953f1d29..9ea82fb64a 100644 --- a/jwst/regtest/test_miri_lrs_slit_spec3.py +++ b/jwst/regtest/test_miri_lrs_slit_spec3.py @@ -13,7 +13,7 @@ scope="module", params=["default_wcs", "user_wcs", "user_wcs+shape", "user_wcs+shape1"] ) -def run_pipeline(tmp_cwd_module, rtdata_module, request): +def run_pipeline(rtdata_module, request): """ Run the calwebb_spec3 pipeline on an ASN of nodded MIRI LRS fixed-slit exposures using different options for the WCS and output diff --git a/jwst/regtest/test_miri_lrs_slitless.py b/jwst/regtest/test_miri_lrs_slitless.py index 724af78d9b..de4733050f 100644 --- a/jwst/regtest/test_miri_lrs_slitless.py +++ b/jwst/regtest/test_miri_lrs_slitless.py @@ -15,7 +15,7 @@ @pytest.fixture(scope="module") -def run_tso1_pipeline(tmp_cwd_module, rtdata_module): +def run_tso1_pipeline(rtdata_module): """Run the calwebb_tso1 pipeline on a MIRI LRS slitless exposure.""" rtdata = rtdata_module rtdata.get_data(f"miri/lrs/{DATASET1_ID}_uncal.fits") @@ -34,7 +34,7 @@ def run_tso1_pipeline(tmp_cwd_module, rtdata_module): @pytest.fixture(scope="module") -def run_tso_spec2_pipeline(run_tso1_pipeline, tmp_cwd_module, rtdata_module): +def run_tso_spec2_pipeline(run_tso1_pipeline, rtdata_module): """Run the calwebb_tso-spec2 pipeline on a MIRI LRS slitless exposure.""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_dedicated_mbkg.py b/jwst/regtest/test_miri_mrs_dedicated_mbkg.py index 75deea4a59..93e5bcdba3 100644 --- a/jwst/regtest/test_miri_mrs_dedicated_mbkg.py +++ b/jwst/regtest/test_miri_mrs_dedicated_mbkg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_nod_masterbg.py b/jwst/regtest/test_miri_mrs_nod_masterbg.py index 03d52d9214..d12a3bae20 100644 --- a/jwst/regtest/test_miri_mrs_nod_masterbg.py +++ b/jwst/regtest/test_miri_mrs_nod_masterbg.py @@ -6,7 +6,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_spec2.py b/jwst/regtest/test_miri_mrs_spec2.py index bf08c0195e..3e4a23cb9f 100644 --- a/jwst/regtest/test_miri_mrs_spec2.py +++ b/jwst/regtest/test_miri_mrs_spec2.py @@ -16,7 +16,7 @@ @pytest.fixture(scope='module') -def run_spec2(tmp_cwd_module, rtdata_module): +def run_spec2(rtdata_module): """Run the Spec2Pipeline on a single exposure""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_mrs_spec3.py b/jwst/regtest/test_miri_mrs_spec3.py index 592af322d7..1b71a4c984 100644 --- a/jwst/regtest/test_miri_mrs_spec3.py +++ b/jwst/regtest/test_miri_mrs_spec3.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_ifushort(tmp_cwd_module, rtdata_module): +def run_spec3_ifushort(rtdata_module): """Run the Spec3Pipeline on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT @@ -30,7 +30,7 @@ def run_spec3_ifushort(tmp_cwd_module, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifulong(tmp_cwd_module, rtdata_module): +def run_spec3_ifulong(rtdata_module): """Run the Spec3Pipeline dithered flight data """ # Test has bands medium and long for IFULONG @@ -50,7 +50,7 @@ def run_spec3_ifulong(tmp_cwd_module, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifushort_emsm(tmp_cwd_module, rtdata_module): +def run_spec3_ifushort_emsm(rtdata_module): """Run the Spec3Pipeline (cube_build using weighting emsm) on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT @@ -72,7 +72,7 @@ def run_spec3_ifushort_emsm(tmp_cwd_module, rtdata_module): @pytest.fixture(scope='module') -def run_spec3_ifushort_extract1d(tmp_cwd_module, rtdata_module): +def run_spec3_ifushort_extract1d(rtdata_module): """Run the Spec3Pipeline on association with 2 bands on IFUSHORT""" # Test has bands medium and long for IFUSHORT diff --git a/jwst/regtest/test_miri_mrs_spec3_moving_target.py b/jwst/regtest/test_miri_mrs_spec3_moving_target.py index 73e3e69234..1cd7c97de9 100644 --- a/jwst/regtest/test_miri_mrs_spec3_moving_target.py +++ b/jwst/regtest/test_miri_mrs_spec3_moving_target.py @@ -10,7 +10,7 @@ @pytest.fixture(scope='module') -def run_spec3_moving_target(tmp_cwd_module, rtdata_module): +def run_spec3_moving_target(rtdata_module): """Run the Spec3Pipeline dithered flight data """ # Association has 2 exposures from IFUSHORT diff --git a/jwst/regtest/test_miri_mrs_tso.py b/jwst/regtest/test_miri_mrs_tso.py index 1f459ef432..434a3cbaf9 100644 --- a/jwst/regtest/test_miri_mrs_tso.py +++ b/jwst/regtest/test_miri_mrs_tso.py @@ -10,7 +10,7 @@ @pytest.fixture(scope='module') -def run_spec2(tmp_cwd_module, rtdata_module): +def run_spec2(rtdata_module): """Run the Spec2Pipeline on a single exposure""" rtdata = rtdata_module diff --git a/jwst/regtest/test_miri_setpointing.py b/jwst/regtest/test_miri_setpointing.py index 427e3ba42d..9582cb01d7 100644 --- a/jwst/regtest/test_miri_setpointing.py +++ b/jwst/regtest/test_miri_setpointing.py @@ -12,7 +12,7 @@ @pytest.mark.bigdata -def test_miri_setpointing(tmp_cwd, rtdata, engdb, fitsdiff_default_kwargs): +def test_miri_setpointing(rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b MIRI image. """ diff --git a/jwst/regtest/test_miri_spectral_leak.py b/jwst/regtest/test_miri_spectral_leak.py index b167fe33f3..4fc2aceffb 100644 --- a/jwst/regtest/test_miri_spectral_leak.py +++ b/jwst/regtest/test_miri_spectral_leak.py @@ -8,7 +8,7 @@ 'output', ['test_spectral_leak_asn_0_spectralleakstep.fits', 'test_spectral_leak_asn_1_spectralleakstep.fits'] ) -def test_miri_spectral_leak(output, tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_miri_spectral_leak(output, rtdata, fitsdiff_default_kwargs): """Run cube_build on single file using coord system = ifu_align""" rtdata.get_asn("miri/mrs/test_spectral_leak_asn.json") diff --git a/jwst/regtest/test_nircam_align_to_gaia.py b/jwst/regtest/test_nircam_align_to_gaia.py index 24167e96a0..c91e647207 100644 --- a/jwst/regtest/test_nircam_align_to_gaia.py +++ b/jwst/regtest/test_nircam_align_to_gaia.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_image3pipeline(rtdata_module, tmp_cwd_module): +def run_image3pipeline(rtdata_module): ''' Run calwebb_image3 on NIRCam imaging and align to gaia ''' rtdata = rtdata_module diff --git a/jwst/regtest/test_nircam_coron3.py b/jwst/regtest/test_nircam_coron3.py index 2d7b14fcdf..f66c8cac11 100644 --- a/jwst/regtest/test_nircam_coron3.py +++ b/jwst/regtest/test_nircam_coron3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_coron3 on coronographic data.""" rtdata = rtdata_module rtdata.get_asn("nircam/coron/jw01386-c1020_20220909t073458_coron3_002a_asn.json") diff --git a/jwst/regtest/test_nircam_image.py b/jwst/regtest/test_nircam_image.py index 42402be67d..eed2226a78 100644 --- a/jwst/regtest/test_nircam_image.py +++ b/jwst/regtest/test_nircam_image.py @@ -11,7 +11,7 @@ @pytest.fixture(scope="module") -def run_detector1pipeline(tmp_cwd_module, rtdata_module): +def run_detector1pipeline(rtdata_module): """Run calwebb_detector1 on NIRCam imaging long data""" rtdata = rtdata_module rtdata.get_data("nircam/image/jw01538046001_03105_00001_nrcalong_uncal.fits") @@ -31,7 +31,7 @@ def run_detector1pipeline(tmp_cwd_module, rtdata_module): @pytest.fixture(scope="module") -def run_image2pipeline(run_detector1pipeline, tmp_cwd_module, rtdata_module): +def run_image2pipeline(run_detector1pipeline, rtdata_module): """Run calwebb_image2 on NIRCam imaging long data""" rtdata = rtdata_module rtdata.input = "jw01538046001_03105_00001_nrcalong_rate.fits" @@ -43,7 +43,7 @@ def run_image2pipeline(run_detector1pipeline, tmp_cwd_module, rtdata_module): @pytest.fixture(scope="module") -def run_image3pipeline(run_image2pipeline, rtdata_module, tmp_cwd_module): +def run_image3pipeline(run_image2pipeline, rtdata_module): """Run calwebb_image3 on NIRCam imaging long data""" rtdata = rtdata_module # Grab rest of _rate files for the asn and run image2 pipeline on each to @@ -170,8 +170,9 @@ def test_nircam_image_stage3_segm(run_image3pipeline, rtdata_module, fitsdiff_de @pytest.fixture() -def run_image3_closedfile(rtdata, tmp_cwd_module): +def run_image3_closedfile(rtdata_module): """Run calwebb_image3 on NIRCam imaging with data that had a closed file issue.""" + rtdata = rtdata_module rtdata.get_asn("nircam/image/fail_short_image3_asn.json") args = ["calwebb_image3", rtdata.input] diff --git a/jwst/regtest/test_nircam_subarray_4amp.py b/jwst/regtest/test_nircam_subarray_4amp.py index f555b9f822..c0d7a77bb5 100644 --- a/jwst/regtest/test_nircam_subarray_4amp.py +++ b/jwst/regtest/test_nircam_subarray_4amp.py @@ -14,7 +14,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_detector1 pipeline on NIRCAM subarray data.""" rtdata = rtdata_module rtdata.get_data("nircam/subarray/jw00617196001_02102_00001_nrca4_uncal.fits") diff --git a/jwst/regtest/test_nircam_tsgrism.py b/jwst/regtest/test_nircam_tsgrism.py index 4ceb3467bb..efd09185c6 100644 --- a/jwst/regtest/test_nircam_tsgrism.py +++ b/jwst/regtest/test_nircam_tsgrism.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipelines(tmp_cwd_module, rtdata_module): +def run_pipelines(rtdata_module): """Run stage 2-3 tso pipelines on NIRCAM TSO grism data.""" rtdata = rtdata_module @@ -71,7 +71,7 @@ def test_nircam_tsgrism_stage3_whtlt(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsgrism(tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsgrism(rtdata, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam file. """ diff --git a/jwst/regtest/test_nircam_tsimg.py b/jwst/regtest/test_nircam_tsimg.py index 6b70921d19..05684588c4 100644 --- a/jwst/regtest/test_nircam_tsimg.py +++ b/jwst/regtest/test_nircam_tsimg.py @@ -11,7 +11,7 @@ @pytest.fixture(scope="module") -def run_pipelines(tmp_cwd_module, rtdata_module): +def run_pipelines(rtdata_module): """Run stage 2 and 3 pipelines on NIRCam TSO image data.""" rtdata = rtdata_module @@ -65,7 +65,7 @@ def test_nircam_tsimage_stage3_phot(run_pipelines): @pytest.mark.bigdata -def test_nircam_setpointing_tsimg(tmp_cwd, rtdata, engdb, fitsdiff_default_kwargs): +def test_nircam_setpointing_tsimg(rtdata, engdb, fitsdiff_default_kwargs): """ Regression test of the set_telescope_pointing script on a level-1b NIRCam TSO imaging file. diff --git a/jwst/regtest/test_nircam_wfs.py b/jwst/regtest/test_nircam_wfs.py index 9390cfc762..3b4a0a6262 100644 --- a/jwst/regtest/test_nircam_wfs.py +++ b/jwst/regtest/test_nircam_wfs.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipelines(tmp_cwd_module, rtdata_module): +def run_pipelines(rtdata_module): """Run the calwebb_wfs-image2 and calwebb_wfs-image3 pipelines on NIRCam WFS&C images. The calwebb_wfs-image3 pipeline is run twice: once with default params and a second time with diff --git a/jwst/regtest/test_nircam_wfss_contam.py b/jwst/regtest/test_nircam_wfss_contam.py index 999f3ee151..0b50b4935f 100644 --- a/jwst/regtest/test_nircam_wfss_contam.py +++ b/jwst/regtest/test_nircam_wfss_contam.py @@ -5,7 +5,7 @@ @pytest.fixture(scope='module') -def run_wfss_contam(tmp_cwd_module, rtdata_module): +def run_wfss_contam(rtdata_module): """Run the wfss_contam step""" rtdata = rtdata_module diff --git a/jwst/regtest/test_niriss_ami3.py b/jwst/regtest/test_niriss_ami3.py index 0a1344425f..ce59cfd78c 100644 --- a/jwst/regtest/test_niriss_ami3.py +++ b/jwst/regtest/test_niriss_ami3.py @@ -7,7 +7,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_ami3 on NIRISS AMI data.""" rtdata = rtdata_module rtdata.get_asn("niriss/ami/jw01093-c1000_20221110t003218_ami3_002_asn.json") diff --git a/jwst/regtest/test_niriss_soss.py b/jwst/regtest/test_niriss_soss.py index 9b28a8edfe..ef9796d4fa 100644 --- a/jwst/regtest/test_niriss_soss.py +++ b/jwst/regtest/test_niriss_soss.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_tso_spec2(tmp_cwd_module, rtdata_module): +def run_tso_spec2(rtdata_module): """Run stage 2 pipeline on NIRISS SOSS data.""" rtdata = rtdata_module @@ -28,7 +28,7 @@ def run_tso_spec2(tmp_cwd_module, rtdata_module): @pytest.fixture(scope="module") -def run_tso_spec3(tmp_cwd_module, rtdata_module, run_tso_spec2): +def run_tso_spec3(rtdata_module, run_tso_spec2): """Run stage 3 pipeline on NIRISS SOSS data.""" rtdata = rtdata_module # Get the level3 association json file (though not its members) and run @@ -41,7 +41,7 @@ def run_tso_spec3(tmp_cwd_module, rtdata_module, run_tso_spec2): @pytest.fixture(scope="module") -def run_atoca_extras(tmp_cwd_module, rtdata_module): +def run_atoca_extras(rtdata_module): """Run stage 2 pipeline on NIRISS SOSS data using enhanced modes via parameter settings.""" rtdata = rtdata_module @@ -127,7 +127,7 @@ def test_niriss_soss_extras(rtdata_module, run_atoca_extras, fitsdiff_default_kw @pytest.fixture(scope='module') -def run_extract1d_spsolve_failure(tmp_cwd_module, rtdata_module): +def run_extract1d_spsolve_failure(rtdata_module): """ Test coverage for fix to error thrown when spsolve fails to find a good solution in ATOCA and needs to be replaced with a least- @@ -145,7 +145,7 @@ def run_extract1d_spsolve_failure(tmp_cwd_module, rtdata_module): @pytest.fixture(scope='module') -def run_extract1d_null_order2(tmp_cwd_module, rtdata_module): +def run_extract1d_null_order2(rtdata_module): """ Test coverage for fix to error thrown when all of the pixels in order 2 are flagged as bad. Ensure graceful handling of the diff --git a/jwst/regtest/test_niriss_wfss.py b/jwst/regtest/test_niriss_wfss.py index a5b67b76a1..b723690a2f 100644 --- a/jwst/regtest/test_niriss_wfss.py +++ b/jwst/regtest/test_niriss_wfss.py @@ -6,7 +6,7 @@ @pytest.fixture(scope='module') -def run_nis_wfss_spec2(tmp_cwd_module, rtdata_module): +def run_nis_wfss_spec2(rtdata_module): """Run the calwebb_spec2 pipeline on NIRISS WFSS exposures""" rtdata = rtdata_module @@ -60,7 +60,7 @@ def test_nis_wfss_spec2(run_nis_wfss_spec2, rtdata_module, fitsdiff_default_kwar @pytest.fixture(scope='module') -def run_nis_wfss_spec3(run_nis_wfss_spec2, rtdata_module, tmp_cwd_module): +def run_nis_wfss_spec3(run_nis_wfss_spec2, rtdata_module): """Run the calwebb_spec3 pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_brightobj.py b/jwst/regtest/test_nirspec_brightobj.py index a437babac4..cc5fedb94b 100644 --- a/jwst/regtest/test_nirspec_brightobj.py +++ b/jwst/regtest/test_nirspec_brightobj.py @@ -12,7 +12,7 @@ @pytest.fixture(scope="module") -def run_tso_spec2_pipeline(tmp_cwd_module, rtdata_module, request): +def run_tso_spec2_pipeline(rtdata_module, request): """Run the calwebb_spec2 pipeline performed on NIRSpec fixed-slit data that uses the NRS_BRIGHTOBJ mode (S1600A1 slit) """ diff --git a/jwst/regtest/test_nirspec_exceptions.py b/jwst/regtest/test_nirspec_exceptions.py index 168745de8b..73a0c70981 100644 --- a/jwst/regtest/test_nirspec_exceptions.py +++ b/jwst/regtest/test_nirspec_exceptions.py @@ -7,7 +7,7 @@ @pytest.mark.bigdata -def test_nirspec_missing_msa_fail(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_fail(rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should be raised. @@ -26,7 +26,7 @@ def test_nirspec_missing_msa_fail(tmp_cwd, rtdata, fitsdiff_default_kwargs, capl @pytest.mark.bigdata -def test_nirspec_missing_msa_nofail(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_missing_msa_nofail(rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure that's missing an MSAMETFL. Exception should NOT be raised. @@ -46,7 +46,7 @@ def test_nirspec_missing_msa_nofail(tmp_cwd, rtdata, fitsdiff_default_kwargs, ca @pytest.mark.bigdata -def test_nirspec_assignwcs_skip(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_assignwcs_skip(rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec MSA exposure with the AssignWcs step skipped. The pipeline should abort. @@ -66,7 +66,7 @@ def test_nirspec_assignwcs_skip(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_api(tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_nirspec_nrs2_nodata_api(rtdata, fitsdiff_default_kwargs): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on @@ -85,7 +85,7 @@ def test_nirspec_nrs2_nodata_api(tmp_cwd, rtdata, fitsdiff_default_kwargs): @pytest.mark.bigdata -def test_nirspec_nrs2_nodata_strun(tmp_cwd, rtdata, fitsdiff_default_kwargs, caplog): +def test_nirspec_nrs2_nodata_strun(rtdata, fitsdiff_default_kwargs, caplog): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on diff --git a/jwst/regtest/test_nirspec_fs_spec2.py b/jwst/regtest/test_nirspec_fs_spec2.py index 1c499d2602..9b03914620 100644 --- a/jwst/regtest/test_nirspec_fs_spec2.py +++ b/jwst/regtest/test_nirspec_fs_spec2.py @@ -35,7 +35,7 @@ @pytest.fixture(scope="module", params=file_roots) # ids=ids) -def run_pipeline(tmp_cwd_module, rtdata_module, request): +def run_pipeline(rtdata_module, request): """Run the calwebb_spec2 pipeline on NIRSpec Fixed-Slit exposures. We currently test the following types of inputs: 1) Full-frame exposure (all slits will be extracted) diff --git a/jwst/regtest/test_nirspec_fs_spec3.py b/jwst/regtest/test_nirspec_fs_spec3.py index 07f0a5a84b..10e205e870 100644 --- a/jwst/regtest/test_nirspec_fs_spec3.py +++ b/jwst/regtest/test_nirspec_fs_spec3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """ Run the calwebb_spec3 pipeline on NIRSpec Fixed-Slit exposures. """ diff --git a/jwst/regtest/test_nirspec_ifu_spec2.py b/jwst/regtest/test_nirspec_ifu_spec2.py index 18788ef158..4445e69131 100644 --- a/jwst/regtest/test_nirspec_ifu_spec2.py +++ b/jwst/regtest/test_nirspec_ifu_spec2.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec2(tmp_cwd_module, rtdata_module): +def run_spec2(rtdata_module): """Run the Spec2Pipeline on a spec2 ASN containing a single exposure""" rtdata = rtdata_module @@ -50,9 +50,11 @@ def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix): @pytest.fixture() -def run_photom(tmp_cwd_module, rtdata): +def run_photom(rtdata_module): """Run the photom step on an NRS IFU exposure with SRCTYPE=POINT""" + rtdata = rtdata_module + # Setup the inputs rate_name = 'jw01251004001_03107_00002_nrs1_pathloss.fits' rate_path = INPUT_PATH + '/' + rate_name @@ -76,9 +78,11 @@ def test_photom(run_photom, fitsdiff_default_kwargs): @pytest.fixture() -def run_extract1d(tmp_cwd_module, rtdata): +def run_extract1d(rtdata_module): """Run the extract_1d step on an NRS IFU cube with SRCTYPE=POINT""" + rtdata = rtdata_module + # Setup the inputs cube_name = 'jw01251004001_03107_00002_nrs1_s3d.fits' cube_path = INPUT_PATH + '/' + cube_name diff --git a/jwst/regtest/test_nirspec_ifu_spec3.py b/jwst/regtest/test_nirspec_ifu_spec3.py index 81c1589a42..a2584d4470 100644 --- a/jwst/regtest/test_nirspec_ifu_spec3.py +++ b/jwst/regtest/test_nirspec_ifu_spec3.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_multi(tmp_cwd_module, rtdata_module): +def run_spec3_multi(rtdata_module): """Run Spec3Pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_ifu_spec3_emsm.py b/jwst/regtest/test_nirspec_ifu_spec3_emsm.py index 7616ccfc0a..b4316cf43d 100644 --- a/jwst/regtest/test_nirspec_ifu_spec3_emsm.py +++ b/jwst/regtest/test_nirspec_ifu_spec3_emsm.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec3_multi_emsm(tmp_cwd_module, rtdata_module): +def run_spec3_multi_emsm(rtdata_module): """Run Spec3Pipeline""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_image2.py b/jwst/regtest/test_nirspec_image2.py index 153f4a2c17..5bb46cd75a 100644 --- a/jwst/regtest/test_nirspec_image2.py +++ b/jwst/regtest/test_nirspec_image2.py @@ -10,7 +10,7 @@ @pytest.mark.bigdata -def test_nirspec_image2(tmp_cwd, rtdata, fitsdiff_default_kwargs): +def test_nirspec_image2(rtdata, fitsdiff_default_kwargs): rtdata.get_data("nirspec/imaging/jw84600010001_02102_00001_nrs2_rate.fits") args = ["calwebb_image2", rtdata.input] diff --git a/jwst/regtest/test_nirspec_imprint.py b/jwst/regtest/test_nirspec_imprint.py index 5925415e3a..c2c4db14d1 100644 --- a/jwst/regtest/test_nirspec_imprint.py +++ b/jwst/regtest/test_nirspec_imprint.py @@ -9,7 +9,7 @@ @pytest.fixture(scope='module') -def run_spec2(tmp_cwd_module, rtdata_module): +def run_spec2(rtdata_module): """Run the Spec2Pipeline on a spec2 ASN containing a single exposure with multiple imprint exposures""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_irs2_detector1.py b/jwst/regtest/test_nirspec_irs2_detector1.py index caa81396c7..8af8bfbcee 100644 --- a/jwst/regtest/test_nirspec_irs2_detector1.py +++ b/jwst/regtest/test_nirspec_irs2_detector1.py @@ -9,7 +9,7 @@ @pytest.fixture(scope="module") -def run_detector1pipeline(rtdata_module, tmp_cwd_module): +def run_detector1pipeline(rtdata_module): """Run calwebb_detector1 pipeline on NIRSpec data with IRS2 readout mode.""" rtdata = rtdata_module rtdata.get_data("nirspec/irs2/jw0010010_11010_nrs1_chimera_uncal.fits") diff --git a/jwst/regtest/test_nirspec_masterbackground.py b/jwst/regtest/test_nirspec_masterbackground.py index adde5b7ec3..5c45d41265 100644 --- a/jwst/regtest/test_nirspec_masterbackground.py +++ b/jwst/regtest/test_nirspec_masterbackground.py @@ -13,7 +13,7 @@ @pytest.fixture(scope='module') -def run_spec2_mbkg(tmp_cwd_module, rtdata_module): +def run_spec2_mbkg(rtdata_module): """Run Spec2 on MSA data with background slits""" rtdata = rtdata_module @@ -34,7 +34,7 @@ def run_spec2_mbkg(tmp_cwd_module, rtdata_module): @pytest.fixture(scope='module') -def run_spec2_mbkg_user(tmp_cwd_module, rtdata_module): +def run_spec2_mbkg_user(rtdata_module): """Run Spec2 on MSA data with a user-supplied master bkg spectrum""" rtdata = rtdata_module diff --git a/jwst/regtest/test_nirspec_mos_spec3.py b/jwst/regtest/test_nirspec_mos_spec3.py index 20209422eb..59d9049837 100644 --- a/jwst/regtest/test_nirspec_mos_spec3.py +++ b/jwst/regtest/test_nirspec_mos_spec3.py @@ -5,7 +5,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_spec3 on NIRSpec MOS data.""" rtdata = rtdata_module rtdata.get_asn("nirspec/mos/jw00626-o030_20191210t193826_spec3_001_asn.json") diff --git a/jwst/regtest/test_nirspec_subarray.py b/jwst/regtest/test_nirspec_subarray.py index 9ad005e223..1114086d05 100644 --- a/jwst/regtest/test_nirspec_subarray.py +++ b/jwst/regtest/test_nirspec_subarray.py @@ -13,7 +13,7 @@ @pytest.fixture(scope="module") -def run_pipeline(tmp_cwd_module, rtdata_module): +def run_pipeline(rtdata_module): """Run calwebb_detector1 pipeline on NIRSpec subarray data.""" rtdata = rtdata_module rtdata.get_data("nirspec/fs/nrs1_group_subarray.fits") diff --git a/jwst/regtest/test_schema_editor.py b/jwst/regtest/test_schema_editor.py index bd3924ed39..bc111133a6 100644 --- a/jwst/regtest/test_schema_editor.py +++ b/jwst/regtest/test_schema_editor.py @@ -23,7 +23,7 @@ @pytest.fixture(scope='module') -def keyword_db(tmp_cwd_module, rtdata_module): +def keyword_db(rtdata_module): """Define the keyword database""" rt = rtdata_module From 39f50e734513d6ec37f1cd8354155a3d6ee159d6 Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Wed, 13 Mar 2024 12:46:51 -0400 Subject: [PATCH 14/16] revert duplicate rtdata, tmp_cwd in test_infrastructure because their sameness is what is being tested --- jwst/regtest/test_infrastructure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jwst/regtest/test_infrastructure.py b/jwst/regtest/test_infrastructure.py index c60e3fefb0..7cbe03c4aa 100644 --- a/jwst/regtest/test_infrastructure.py +++ b/jwst/regtest/test_infrastructure.py @@ -9,7 +9,7 @@ @pytest.mark.bigdata -def test_regtestdata_get_data(rtdata): +def test_regtestdata_get_data(rtdata, tmp_cwd): rtdata.get_data("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_cal.fits" @@ -17,7 +17,7 @@ def test_regtestdata_get_data(rtdata): @pytest.mark.bigdata -def test_regtestdata_get_truth(rtdata): +def test_regtestdata_get_truth(rtdata, tmp_cwd): rtdata.get_truth("infrastructure/test_regtestdata/file1_rate.fits") rtdata.output = "file1_rate.fits" From 42f5ed903781e501d1b118003356482f822e1eba Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Thu, 14 Mar 2024 09:34:13 -0400 Subject: [PATCH 15/16] attempted solve regtest failures in nirspec_ifu_spec2 --- jwst/regtest/test_nirspec_ifu_spec2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jwst/regtest/test_nirspec_ifu_spec2.py b/jwst/regtest/test_nirspec_ifu_spec2.py index 4445e69131..5971f70340 100644 --- a/jwst/regtest/test_nirspec_ifu_spec2.py +++ b/jwst/regtest/test_nirspec_ifu_spec2.py @@ -49,7 +49,7 @@ def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix): truth_path=TRUTH_PATH) -@pytest.fixture() +@pytest.fixture(scope="module") def run_photom(rtdata_module): """Run the photom step on an NRS IFU exposure with SRCTYPE=POINT""" @@ -77,7 +77,7 @@ def test_photom(run_photom, fitsdiff_default_kwargs): truth_path=TRUTH_PATH) -@pytest.fixture() +@pytest.fixture(scope="module") def run_extract1d(rtdata_module): """Run the extract_1d step on an NRS IFU cube with SRCTYPE=POINT""" From 06b073158ba7dccad35ad250340744167592d47b Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Thu, 14 Mar 2024 15:52:02 -0400 Subject: [PATCH 16/16] made run_photom and run_extract1d function scoped --- jwst/regtest/test_nirspec_ifu_spec2.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/jwst/regtest/test_nirspec_ifu_spec2.py b/jwst/regtest/test_nirspec_ifu_spec2.py index 5971f70340..14c42ba740 100644 --- a/jwst/regtest/test_nirspec_ifu_spec2.py +++ b/jwst/regtest/test_nirspec_ifu_spec2.py @@ -49,12 +49,10 @@ def test_spec2(run_spec2, fitsdiff_default_kwargs, suffix): truth_path=TRUTH_PATH) -@pytest.fixture(scope="module") -def run_photom(rtdata_module): +@pytest.fixture +def run_photom(rtdata): """Run the photom step on an NRS IFU exposure with SRCTYPE=POINT""" - rtdata = rtdata_module - # Setup the inputs rate_name = 'jw01251004001_03107_00002_nrs1_pathloss.fits' rate_path = INPUT_PATH + '/' + rate_name @@ -77,12 +75,10 @@ def test_photom(run_photom, fitsdiff_default_kwargs): truth_path=TRUTH_PATH) -@pytest.fixture(scope="module") -def run_extract1d(rtdata_module): +@pytest.fixture +def run_extract1d(rtdata): """Run the extract_1d step on an NRS IFU cube with SRCTYPE=POINT""" - rtdata = rtdata_module - # Setup the inputs cube_name = 'jw01251004001_03107_00002_nrs1_s3d.fits' cube_path = INPUT_PATH + '/' + cube_name