Test md5/sha1 hash calculations.
(tmp_path)
| 76 | |
| 77 | |
| 78 | def test_hashfunc(tmp_path): |
| 79 | """Test md5/sha1 hash calculations.""" |
| 80 | fname1 = tmp_path / "foo" |
| 81 | fname2 = tmp_path / "bar" |
| 82 | with open(fname1, "wb") as fid: |
| 83 | fid.write(b"abcd") |
| 84 | with open(fname2, "wb") as fid: |
| 85 | fid.write(b"efgh") |
| 86 | |
| 87 | for hash_type in ("md5", "sha1"): |
| 88 | hash1 = hashfunc(fname1, hash_type=hash_type) |
| 89 | hash1_ = hashfunc(fname1, 1, hash_type=hash_type) |
| 90 | |
| 91 | hash2 = hashfunc(fname2, hash_type=hash_type) |
| 92 | hash2_ = hashfunc(fname2, 1024, hash_type=hash_type) |
| 93 | |
| 94 | assert hash1 == hash1_ |
| 95 | assert hash2 == hash2_ |
| 96 | assert hash1 != hash2 |
| 97 | |
| 98 | |
| 99 | def test_sum_squared(): |