Files
scanengine-3/tests/test_scan_resume.py
T
Thomas K Ales [MSE] 880b05fe86 working state commit
2026-09-25 08:13:03 -05:00

95 lines
3.5 KiB
Python
Executable File

"""core.scan_resume: the frontier contiguity rule, over real fixture files."""
from pathlib import Path
from core.scan_resume import is_compatible, plan_resume
from core.sras_format import SrasFile
from golden_util import write_v7
GOLDEN = Path(__file__).parent / "golden"
def _statuses(name):
return SrasFile(GOLDEN / name).angle_status()
def test_complete_file_frontier_is_past_the_end():
st = _statuses("complete.sras")
plan = plan_resume(st, selected={0})
assert plan.frontier_idx == len(st)
assert [t.angle_idx for t in plan.targets] == [0]
assert plan.auto_added == []
def test_selecting_past_frontier_backfills_the_gap():
# angle 0 complete, angle 1 truncated → frontier = 1
st = _statuses("trunc_rowboundary_a1.sras")
assert st[0].complete and not st[1].complete
plan = plan_resume(st, selected={1})
assert plan.frontier_idx == 1
assert [t.angle_idx for t in plan.targets] == [1]
assert plan.auto_added == []
def test_selection_before_frontier_is_untouched():
st = _statuses("trunc_rowboundary_a1.sras")
plan = plan_resume(st, selected={0})
assert [t.angle_idx for t in plan.targets] == [0]
assert plan.auto_added == []
def test_selecting_only_a_later_angle_pulls_in_the_frontier():
"""Data is one contiguous stream, so angle 1 can't be skipped to reach 2."""
st = _statuses("header_only.sras") # nothing written: frontier = 0
assert plan_resume(st, selected={0}).frontier_idx == 0
plan = plan_resume(st, selected={1})
assert [t.angle_idx for t in plan.targets] == [0, 1]
assert plan.auto_added == [0]
def test_targets_carry_offsets_and_rows(tmp_path):
out = tmp_path / "v7.sras"
write_v7(out)
st = SrasFile(out).angle_status()
plan = plan_resume(st, selected={0, 1})
for target, status in zip(plan.targets, st, strict=True):
# A re-acquired angle rewrites its background too, so a target has to
# know where the block starts as well as where the rows do.
assert target.bg_offset == status.bg_offset
assert target.data_offset == status.data_offset
assert target.bg_offset < target.data_offset
assert target.n_rows == status.n_rows
assert target.angle_deg == status.angle_deg
assert plan.total_rows == sum(s.n_rows for s in st)
def test_to_state_carries_samples_per_frame():
sras = SrasFile(GOLDEN / "complete.sras")
state = plan_resume(sras.angle_status(), selected={0}).to_state(sras)
assert state.path == sras.path
assert state.samples_per_frame == sras.header.samples_per_frame
assert state.target_indices == {0}
def test_is_compatible_rejects_a_legacy_file():
"""A v6 file has no room for the background block each angle now writes."""
sras = SrasFile(GOLDEN / "complete.sras")
h = sras.header
assert not is_compatible(sras, velocity=h.velocity, laser_freq=h.laser_freq,
sample_rate=h.sample_rate, n_channels=h.n_channels)
def test_is_compatible_checks_acquisition_settings(tmp_path):
out = tmp_path / "v7.sras"
write_v7(out)
sras = SrasFile(out)
h = sras.header
ok = dict(velocity=h.velocity, laser_freq=h.laser_freq,
sample_rate=h.sample_rate, n_channels=h.n_channels)
assert is_compatible(sras, **ok)
assert not is_compatible(sras, **{**ok, "velocity": h.velocity + 1})
assert not is_compatible(sras, **{**ok, "laser_freq": h.laser_freq * 2})
assert not is_compatible(sras, **{**ok, "sample_rate": h.sample_rate * 2})
assert not is_compatible(sras, **{**ok, "n_channels": h.n_channels + 1})