From 622b58a67910f3d26c35313ad024d67cbc3af06c Mon Sep 17 00:00:00 2001 From: Ned Molter Date: Tue, 8 Oct 2024 13:39:36 -0400 Subject: [PATCH] added simple tests of skip --- tests/test_step.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/test_step.py b/tests/test_step.py index dade4b5e..9693698b 100644 --- a/tests/test_step.py +++ b/tests/test_step.py @@ -423,12 +423,11 @@ class StepWithModel(Step): output_ext = string(default='simplestep') save_results = boolean(default=True) """ - # spec = """ - # - # skip = bool(default=False) - # """ def process(self, input_model): + # make a change to ensure step skip is working + # without having to define SimpleDataModel.meta.stepname + input_model.stepstatus = "COMPLETED" return input_model @@ -439,17 +438,12 @@ class SimpleDataModel(AbstractDataModel): def crds_observatory(self): return "jwst" - # @property - # def meta(self): - # return {"filename": "test.fits"} - def get_crds_parameters(self): return {"test": "none"} def save(self, path, dir_path=None, *args, **kwargs): saveid = getattr(self, "saveid", None) if saveid is not None: - print(f"here {saveid}") fname = saveid+"-saved.txt" with open(fname, "w") as f: f.write(f"{path}") @@ -466,6 +460,15 @@ def test_save(tmp_cwd): assert (tmp_cwd / "test-saved.txt").exists() +def test_skip(): + model = SimpleDataModel() + step = StepWithModel() + step.skip = True + out = step.run(model) + assert not hasattr(out, "stepstatus") + assert out is model + + @pytest.fixture(scope="function") def model_list(): model = SimpleDataModel() @@ -527,6 +530,16 @@ def test_save_container(tmp_cwd, model_list): assert (tmp_cwd / f"test{i}-saved.txt").exists() +def test_skip_container(tmp_cwd, model_list): + step = StepWithModel() + step.skip = True + out = step.run(model_list) + assert not hasattr(out, "stepstatus") + for i, model in enumerate(out): + assert not hasattr(model, "stepstatus") + assert model_list[i] is model + + def test_save_container_with_save_method(tmp_cwd, model_list): """ensure list-like save still works for non-list sequence""" container = SimpleContainerWithSave(model_list)