Skip to content

Commit

Permalink
added simple tests of skip
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Oct 8, 2024
1 parent 83bbea0 commit 622b58a
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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}")
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 622b58a

Please sign in to comment.