Phase 0: test scaffolding + golden fixtures
- ruff config, offscreen smoke tests for all 7 GUI apps/panels - golden v6 .sras fixtures (complete + 4 truncation variants) generated by the pre-refactor writer, with expected header/frontier JSON - golden geometry fixtures from the pre-refactor _build_scan_params - consistency tests proving current code reproduces the goldens Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
"""Golden-fixture consistency tests.
|
||||
|
||||
Phase 0: assert the pre-refactor implementations reproduce the committed
|
||||
fixtures. Phase 2 migrates these assertions onto core.sras_format /
|
||||
core.scan_geometry; the fixtures themselves never change.
|
||||
"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import sc3_aui_app as app
|
||||
from gen_goldens import (
|
||||
BACKGROUND, PREAMBLES, SAMPLE_RATE, SPF, _fake_window, _synthetic_frame,
|
||||
)
|
||||
|
||||
GOLDEN = Path(__file__).parent / "golden"
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def geometry():
|
||||
with open(GOLDEN / "geometry.json") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def sras_expected():
|
||||
with open(GOLDEN / "sras_expected.json") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def test_geometry_cases_match(geometry):
|
||||
for label, case in geometry["cases"].items():
|
||||
inputs = case["inputs"]
|
||||
params = app.MainWindow._build_scan_params(_fake_window(*inputs.values()))
|
||||
assert params == case["params"], f"geometry mismatch for case {label}"
|
||||
|
||||
|
||||
def test_geometry_error_cases_raise(geometry):
|
||||
for label, case in geometry["error_cases"].items():
|
||||
with pytest.raises(ValueError):
|
||||
app.MainWindow._build_scan_params(_fake_window(*case["inputs"].values()))
|
||||
|
||||
|
||||
def test_writer_output_byte_identical(tmp_path, sras_expected):
|
||||
params = app.MainWindow._build_scan_params(
|
||||
_fake_window("1.0", "1.0", "0.02", "0.02", "2", "0.01"))
|
||||
per_angle = params["per_angle"]
|
||||
angles = [pa["angle"] for pa in per_angle]
|
||||
|
||||
out = tmp_path / "rewrite.sras"
|
||||
f = app._open_scan_file(
|
||||
out, angles, per_angle,
|
||||
params["x_start_nominal"], params["y_start_nominal"],
|
||||
params["x_delta_nominal"], params["y_delta_nominal"],
|
||||
params["row_spacing"],
|
||||
app.SCAN_VELOCITY_MM_S, app.LASER_FREQ_HZ,
|
||||
SPF, SAMPLE_RATE, PREAMBLES, BACKGROUND,
|
||||
)
|
||||
try:
|
||||
for ai, pa in enumerate(per_angle):
|
||||
for ri in range(pa["n_rows"]):
|
||||
for ci in range(len(app.SCAN_CHANNELS)):
|
||||
for fi in range(pa["n_frames"]):
|
||||
f.write(_synthetic_frame(ai, ri, ci, fi))
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
assert out.read_bytes() == (GOLDEN / "complete.sras").read_bytes()
|
||||
|
||||
|
||||
def test_header_parse_matches(sras_expected):
|
||||
info = app._read_sras_header(GOLDEN / "complete.sras")
|
||||
assert info == sras_expected["header"]
|
||||
|
||||
|
||||
def test_angle_status_all_variants(sras_expected):
|
||||
info = app._read_sras_header(GOLDEN / "complete.sras")
|
||||
for name, expected in sras_expected["statuses"].items():
|
||||
statuses = app._compute_angle_status(GOLDEN / name, info)
|
||||
assert statuses == expected, f"status mismatch for {name}"
|
||||
Reference in New Issue
Block a user