Files
linuxcncWebWASM/scripts/test_motion_state_report.py

29 lines
927 B
Python

import hashlib
import json
import subprocess
import unittest
from pathlib import Path
import generate_motion_state_report
ROOT = Path(__file__).resolve().parents[1]
class MotionStateReportTests(unittest.TestCase):
def test_worker_motion_matrix(self):
result = subprocess.run(["node", "web/worker/test_motion_state.mjs"], cwd=ROOT, check=False)
self.assertEqual(result.returncode, 0)
def test_report_self_hash(self):
report = json.loads((ROOT / "coverage/motion-state.report.json").read_text(encoding="utf-8"))
self.assertEqual(report["schema"], "motion-state-report.v1")
self.assertEqual(report["status"], "verified")
unsigned = dict(report)
actual = unsigned.pop("report_sha256")
self.assertEqual(actual, hashlib.sha256(generate_motion_state_report.canonical(unsigned).encode("utf-8")).hexdigest())
if __name__ == "__main__":
unittest.main()