| 1 | from __future__ import annotations
|
| 2 |
|
| 3 | import hashlib
|
| 4 | import sys
|
| 5 | import tempfile
|
| 6 | import unittest
|
| 7 | from pathlib import Path
|
| 8 |
|
| 9 | sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
| 10 |
|
| 11 | from oakbench.subjects import binary_sha256
|
| 12 |
|
| 13 |
|
| 14 | class SubjectFingerprintTest(unittest.TestCase):
|
| 15 | def test_binary_sha256_hashes_existing_file(self) -> None:
|
| 16 | with tempfile.TemporaryDirectory() as tmp:
|
| 17 | path = Path(tmp) / "bin"
|
| 18 | path.write_bytes(b"oak")
|
| 19 | self.assertEqual(binary_sha256(path), hashlib.sha256(b"oak").hexdigest())
|
| 20 |
|
| 21 | def test_binary_sha256_missing_is_none(self) -> None:
|
| 22 | self.assertIsNone(binary_sha256(Path("/definitely/not/here/oak")))
|
| 23 |
|
| 24 |
|
| 25 | if __name__ == "__main__":
|
| 26 | unittest.main()
|