Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SyJ2ip3Krb6dtdv2cXua44
47 lines
1.7 KiB
Python
47 lines
1.7 KiB
Python
"""The write-session fixtures are what they claim to be: THOR's own frames, paired."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from micromate.framing import request_sub, unstuff # noqa: E402
|
|
|
|
FIX = Path(__file__).parent / "fixtures" / "micromate-writes"
|
|
ALL = sorted(FIX.glob("*.json"))
|
|
|
|
|
|
def test_all_seven_sessions_are_present():
|
|
assert {p.stem for p in ALL} == {
|
|
"setup-push-new-test1", "setup-push-overwrite-test1", "setup-push-read-scheduler",
|
|
"setup-push-pull-schedule", "setup-push-multiday", "call-home-enable-disable",
|
|
"monitor-start-stop"}
|
|
|
|
|
|
@pytest.mark.parametrize("path", ALL, ids=lambda p: p.stem)
|
|
def test_every_request_is_a_valid_frame_and_every_response_answers_it(path):
|
|
doc = json.loads(path.read_text())
|
|
assert doc["source_sha256"]["bw"] and doc["exchanges"]
|
|
for ex in doc["exchanges"]:
|
|
wire = bytes.fromhex(ex["request"])
|
|
assert request_sub(wire) == ex["sub"]
|
|
body = unstuff(wire[2:-1])
|
|
assert body[-1] == sum(body[:-1]) & 0xFF # plain SUM8
|
|
assert ex["response_sub"] == 0xFF - ex["sub"]
|
|
|
|
|
|
@pytest.mark.parametrize("slug,subs", [
|
|
("setup-push-new-test1", [0x41, 0x08, 0x2E, 0x1A, 0xDA, 0x68, 0x73, 0x82, 0x83, 0x71, 0x72]),
|
|
("call-home-enable-disable", [0x2C, 0x7E, 0x7F]),
|
|
("monitor-start-stop", [0x96, 0x97]),
|
|
])
|
|
def test_each_session_holds_the_frames_its_tests_need(slug, subs):
|
|
seen = [ex["sub"] for ex in json.loads((FIX / f"{slug}.json").read_text())["exchanges"]]
|
|
for s in subs:
|
|
assert s in seen, f"{slug}: no SUB 0x{s:02X}"
|