Skip to content

Commit

Permalink
hash repeatability test
Browse files Browse the repository at this point in the history
  • Loading branch information
aloosley committed Dec 17, 2024
1 parent b08967e commit 090a929
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def test_tracked_persistable_dependencies(self, tmp_path: Path) -> None:
a=1, b="hello", dummy_persistable=dict(a=1, b="hello")
)

def test_persist_filepath_determined_by_both_params_tree_and_payload_name(self, tmp_path: Path) -> None:
def test_persist_hash_and_filepath_determined_by_both_params_tree_and_payload_name(self, tmp_path: Path) -> None:
# GIVEN some persistable instances
data_dir = tmp_path
params = DummyPersistableParams()
Expand All @@ -116,10 +116,12 @@ def test_persist_filepath_determined_by_both_params_tree_and_payload_name(self,
data_dir=data_dir, params=params_2, tracked_persistable_dependencies=None
)

# WHEN and THEN
initial_expected_hash = "6a0f2e637a47f02428f19726be8541a1"

# THEN
assert dummy_persistable.params_tree == params.to_dict()
assert dummy_persistable.persist_hash == "6a0f2e637a47f02428f19726be8541a1"
assert dummy_persistable.persist_filepath == data_dir / "dummy_persistable(6a0f2e637a47f02428f19726be8541a1)"
assert dummy_persistable.persist_hash == initial_expected_hash
assert dummy_persistable.persist_filepath == data_dir / f"dummy_persistable({initial_expected_hash})"

# WHEN payload_name changed
dummy_persistable.payload_name = "another"
Expand Down Expand Up @@ -147,6 +149,26 @@ def test_persist_filepath_determined_by_both_params_tree_and_payload_name(self,
}
assert dummy_persistable.persist_hash == "e1815602bc39616f5378f6305ef2d8ee"
assert dummy_persistable.persist_filepath == data_dir / "another(e1815602bc39616f5378f6305ef2d8ee)"
assert dummy_persistable.persist_hash == "e1815602bc39616f5378f6305ef2d8ee"

# WHEN the params and persistable name are returned to their original values
dummy_persistable.payload_name = "dummy_persistable"
dummy_persistable.params = DummyPersistableParams()
dummy_persistable.tracked_persistable_dependencies = []

# THEN the hash and filepath do as well
assert dummy_persistable.persist_hash == initial_expected_hash
assert dummy_persistable.persist_filepath == data_dir / f"dummy_persistable({initial_expected_hash})"

# WHEN a new persistable is created
params = DummyPersistableParams()
new_dummy_persistable = DummyPersistable(
data_dir=data_dir, params=params, tracked_persistable_dependencies=None
)

# THEN the has is still the same as above
assert new_dummy_persistable.persist_hash == initial_expected_hash
assert new_dummy_persistable.persist_filepath == data_dir / f"dummy_persistable({initial_expected_hash})"

def test_multilevel_params_tree(self, tmp_path: Path) -> None:
# GIVEN some persistable instances that depend on each other
Expand Down Expand Up @@ -194,7 +216,7 @@ def test_payload_validation(self, tmp_path: Path) -> None:
dummy_persistable.validate_payload()
dummy_persistable.validate_payload(payload=valid_payload)
with pytest.raises(InvalidPayloadError):
dummy_persistable.validate_payload(payload=invalid_payload)
dummy_persistable.validate_payload(payload=invalid_payload) # type: ignore

def test_validate_payload_on_load(self, tmp_path: Path) -> None:
# GIVEN persistable
Expand Down

0 comments on commit 090a929

Please sign in to comment.