Newer
Older
import tempfile
from pathlib import Path
from bitia.common import sha256sum
_common_hashes = {
"1": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b",
"123": "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3",
"abcdxyz": "bc5c610196f15a7e0d21a3af77b0e1740a4415a44d8a7ad4905d877825574bf9",
}
def test_filehash():
tempdir = tempfile.gettempdir()
f1 = Path(tempdir) / "a.txt"
f2 = Path(tempdir) / "b.txt"
for _c, _h in _common_hashes.items():
f1.write_text(_c)
assert f1.read_text() == _c
print(f"Computing hash of {f1}, content: {_c}")
assert sha256sum(f1) == _h
t1 = "ls -ltrh /"
f1.write_text(t1)
f2.write_text(t1)
assert sha256sum(f1) == sha256sum(f2)