Skip to content

Commit

Permalink
added unit test for ModelContainer with custom save method
Browse files Browse the repository at this point in the history
  • Loading branch information
emolter committed Oct 8, 2024
1 parent 30888d4 commit 83bbea0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,15 @@ def pop(self, index=-1):
self._models.pop(index)


class SimpleContainerWithSave(SimpleContainer):

def save(self, path, dir_path=None, *args, **kwargs):
for model in self._models[1:]:
# skip the first model to test that the save method is called
# rather than just looping over all models like in the without-save case
model.save(path, dir_path, *args, **kwargs)


def test_save_container(tmp_cwd, model_list):
"""ensure list-like save still works for non-list sequence"""
container = SimpleContainer(model_list)
Expand All @@ -518,6 +527,16 @@ def test_save_container(tmp_cwd, model_list):
assert (tmp_cwd / f"test{i}-saved.txt").exists()


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)
step = StepWithModel()
step.run(container)
assert not (tmp_cwd / "test0-saved.txt").exists()
assert (tmp_cwd / "test1-saved.txt").exists()
assert (tmp_cwd / "test2-saved.txt").exists()


def test_save_tuple_with_nested_list(tmp_cwd, model_list):
"""
in rare cases, multiple outputs are returned from step as tuple.
Expand Down

0 comments on commit 83bbea0

Please sign in to comment.