Skip to content

Commit d5aff78

Browse files
committed
Split up hash tests
1 parent 3ce4215 commit d5aff78

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

tests/test_abstract_model.py

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ def test_write_and_read(store_calc):
255255
), f"{key}'s value does not match"
256256

257257

258+
def test_hash_update():
259+
"""Test hash can be updated after initialisation."""
260+
hasher_1 = Hasher()
261+
262+
init_hash = hasher_1()
263+
hasher_1.update("Test value")
264+
assert hasher_1() != init_hash
265+
266+
258267
@pytest.mark.parametrize(
259268
"data",
260269
[
@@ -267,25 +276,46 @@ def test_write_and_read(store_calc):
267276
b"test",
268277
],
269278
)
270-
def test_hasher(data):
271-
"""Test hash calculated correctly."""
279+
def test_hash_data_types(data):
280+
"""Test updating hash for different data types."""
272281
hasher_1 = Hasher()
273-
274-
# Test hash updated
275-
init_hash = hasher_1()
276282
hasher_1.update("Test value")
277283
updated_hash = hasher_1()
278-
assert updated_hash != init_hash
279284

280-
# Test updating hash for different data types
281285
hasher_1.update(data)
282286
assert updated_hash != hasher_1()
283287

284-
# Test newer hasher reset correctly
288+
289+
def test_second_hash_init():
290+
"""Test second hash is initialised correctly."""
291+
hasher_1 = Hasher()
292+
293+
init_hash = hasher_1()
294+
hasher_1.update("Test value")
295+
285296
hasher_2 = Hasher()
286297
assert hasher_2() == init_hash
287298

288-
# Test hashes match after same data added
299+
300+
@pytest.mark.parametrize(
301+
"data",
302+
[
303+
1296,
304+
3.14,
305+
[1, 2, 3],
306+
(4, 5, 6),
307+
{"a": "value"},
308+
datetime.datetime.now(datetime.timezone.utc),
309+
b"test",
310+
],
311+
)
312+
def test_consistent_hash(data):
313+
"""Test two hashers agree with same data."""
314+
hasher_1 = Hasher()
315+
hasher_1.update("Test value")
316+
hasher_1.update(data)
317+
318+
hasher_2 = Hasher()
289319
hasher_2.update("Test value")
290320
hasher_2.update(data)
291321
assert hasher_1() == hasher_2()

0 commit comments

Comments
 (0)