| 123456789101112131415161718192021222324252627282930313233343536 |
- from importlib.util import module_from_spec, spec_from_file_location
- from pathlib import Path
- ROOT = Path(__file__).resolve().parents[2]
- SPEC = spec_from_file_location("hex_gui", ROOT / "tools/6400_hex_gui.py")
- assert SPEC and SPEC.loader
- GUI = module_from_spec(SPEC)
- SPEC.loader.exec_module(GUI)
- def test_gui_uses_generated_contract_and_golden_vectors() -> None:
- assert GUI.CONTRACT["contract_sha256"] == GUI.GOLDEN["contract_sha256"]
- safe_frame = GUI.set_all([0] * 24 + [20] * 8)
- assert GUI.frame_hex(safe_frame).replace(" ", "").startswith("A55A0120")
- get_frame = GUI.encode(2)
- assert GUI.frame_hex(get_frame).replace(" ", "") == "A55A02006D7B"
- def test_gui_parses_unified_ack_and_rejects_bad_crc() -> None:
- ack = bytes.fromhex("A55A8100A635")
- assert "SET_ACK" in GUI.describe(ack)
- damaged = ack[:-1] + bytes((ack[-1] ^ 1,))
- try:
- GUI.decode(damaged)
- except ValueError as exc:
- assert "CRC mismatch" in str(exc)
- else:
- raise AssertionError("bad CRC accepted")
- def test_gui_has_no_serial_access_path() -> None:
- source = (ROOT / "tools/6400_hex_gui.py").read_text(encoding="utf-8")
- assert "import serial" not in source
- assert "Serial(" not in source
- assert "pyserial" not in source.lower()
|