Files
scanengine-3/tests/test_smoke_apps.py
T
Thomas Ales 844fcd0297 SAW quality check: one middle row per angle, and a viewer that overlays them
A full multi-angle scan takes hours, and a rig whose angles disagree produces
all of them before anyone finds out. This adds a test mode that acquires one
row per angle — the row-wise middle of the ROI — and a viewer that puts every
angle's SAW frequency on one graph. The default 80×50 mm ROI at 5 angles goes
from 1461 rows to 5.

Why the middle row answers an alignment question at all: build_plan centres
every angle's rotated bounding box on the same nominal ROI centre, so each
angle's middle row crosses that one point on the sample. All the angles
measure the same material, so a spread in their frequencies belongs to the rig
rather than to where each row happened to land. test_every_angles_middle_row_
crosses_the_roi_centre pins that premise, since the whole comparison rests on
it and nothing else in the geometry code would notice it breaking.

core/saw_check.py — both halves of the mode, kept together because neither is
much use alone. middle_row_plan() reduces a ScanPlan to one row per angle
(n_rows // 2, the upper of two centre rows when even); frequency_traces() and
alignment_summary() turn the resulting file back into per-angle frequency
traces and the scalars an operator is actually asking about — the spread of
the per-angle medians, the worst drift along a row, the sparsest row. The
verdict thresholds are labelled as rules of thumb, not physics: an anisotropic
sample genuinely varies with angle, so a wide spread is a prompt to look at
the curves rather than a verdict.

Format v10: byte-identical to v6, one row per angle. The version byte earns
its keep because the two are otherwise indistinguishable — a v6 scan aborted
after its first row is not a check, and a reader guessing from the row count
would read a failed scan as a deliberate measurement. create_scan_file()
enforces the one-row rule at write time, since nothing downstream can recover
from a v10 file that breaks it. ScanEngine gains file_version and is otherwise
untouched: the acquisition, the abort/pause path and the background capture
are the scan's, unchanged.

sras_scan_manager.py now carries the source file's version through an export
instead of stamping v6 on everything, which the wider reader would otherwise
have made a lie.

saw_check_viewer.py — frequency along the row, one curve per angle, over a
common offset axis so the curves lie on the same piece of sample; a summary of
each angle's median ±1σ against angle; and the per-angle numbers in a table.
Analysis parameters (DC threshold, background, time gate) recompute on a
worker thread; display ones (smoothing, axis, MHz↔m/s) only redraw. A full v6
scan opens too — the same middle row is pulled out of it — so a finished scan
can be re-examined with the check's own read-out.

In the app, a check finishes by handing the operator the file and an "Open
Viewer" button rather than shutting the rig down the way a completed scan
does. Burst mode is not offered: one row per angle means every burst would be
a single row, so it buys nothing and still pays for the gate preflight.

137 tests passing, ruff clean.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 08:13:54 -05:00

111 lines
2.5 KiB
Python

"""Offscreen smoke tests: every GUI app must construct without hardware.
These don't exercise behavior — they catch import errors, missing .ui
widgets, and constructor regressions during the refactor.
"""
import pytest
from PyQt6.QtWidgets import QApplication
@pytest.fixture(scope="session")
def qapp():
app = QApplication.instance() or QApplication([])
yield app
def _pump(qapp):
qapp.processEvents()
def test_sc3_aui_main_window(qapp):
import sc3_aui_app
win = sc3_aui_app.MainWindow()
_pump(qapp)
try:
assert win.x_start_edit.text()
assert win.windowTitle() == "Scanengine-3 AUI"
finally:
for worker, thread in (
(win._bbd_worker, win._bbd_thread),
(win._oscope_worker, win._oscope_thread),
(win._helios_worker, win._helios_thread),
):
worker.stop_worker()
thread.quit()
assert thread.wait(2000)
win._camera_win.deleteLater()
win.deleteLater()
_pump(qapp)
def test_sras_viewer_window(qapp):
import sras_viewer
win = sras_viewer.SrasViewerWindow()
_pump(qapp)
try:
assert win.windowTitle()
finally:
win.deleteLater()
_pump(qapp)
def test_saw_check_viewer_window(qapp):
import saw_check_viewer
win = saw_check_viewer.SawCheckWindow()
_pump(qapp)
try:
assert win.windowTitle()
finally:
win.deleteLater()
_pump(qapp)
def test_helios_test_app(qapp):
import helios_test_app
win = helios_test_app.HeliosTestApp()
_pump(qapp)
try:
assert win.windowTitle()
finally:
win.deleteLater()
_pump(qapp)
def test_bbd202_test_app(qapp):
import bbd202_test_app
win = bbd202_test_app.BBD202TestApp()
_pump(qapp)
try:
assert win.windowTitle()
finally:
win.close()
_pump(qapp)
def test_camera_test_app(qapp):
import camera_test_app
win = camera_test_app.CameraTestWindow()
_pump(qapp)
try:
assert win.windowTitle()
finally:
win.deleteLater()
_pump(qapp)
def test_t3r_control_panel(qapp):
from hardware.t3r_driver import T3RDriver
from t3r_control_panel import T3RControlPanel
driver = T3RDriver()
panel = T3RControlPanel(driver)
_pump(qapp)
try:
assert panel.windowTitle()
finally:
panel.deleteLater()
_pump(qapp)
def test_sras_scan_manager_importable():
import sras_scan_manager # noqa: F401