"""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 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(): st = _statuses("complete.sras") plan = plan_resume(st, selected={0, 1}) for target, status in zip(plan.targets, st, strict=True): assert target.data_offset == status.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_checks_acquisition_settings(): sras = SrasFile(GOLDEN / "complete.sras") 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})