30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import hashlib
|
|
import json
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
try:
|
|
import generate_posemath_report
|
|
except ModuleNotFoundError: # Supports both discovery and direct module execution.
|
|
from scripts import generate_posemath_report
|
|
|
|
|
|
class PosemathReportTests(unittest.TestCase):
|
|
def test_report_is_deterministic(self):
|
|
root = Path(__file__).resolve().parents[1]
|
|
with tempfile.TemporaryDirectory() as directory:
|
|
report_path = Path(directory) / "report.json"
|
|
first = generate_posemath_report.generate(root, report_path)
|
|
first_bytes = report_path.read_bytes()
|
|
second = generate_posemath_report.generate(root, report_path)
|
|
self.assertEqual(first, second)
|
|
self.assertEqual(first_bytes, report_path.read_bytes())
|
|
self.assertEqual(hashlib.sha256(first_bytes).hexdigest(), hashlib.sha256(report_path.read_bytes()).hexdigest())
|
|
self.assertGreater(first["inputs"]["file_count"], 0)
|
|
self.assertEqual(first["outputs"]["file_count"], len(generate_posemath_report.OUTPUTS))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|