Files
seismo-relay/tests/test_micromate_write_fixtures.py

49 lines
1.9 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"]
assert doc["firmware_line"] in {"blastware", "thor"} # measured from response flags
assert doc["firmware_version"] # the 09-30 audits' "11.0CB"
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}"