fix(gui): reach the file-exists guard from every tab, test exact names

The tabs are handed parent=DataCollectionSettings but
QStackedWidget.addWidget() reparents them to the stack, so the guard's
parent() lookup never found file_path_panel and every Run (rotation,
screening, raster, X-ray centering, Simple) skipped the check. Lookup
now walks up the widget tree; regression test drives all five runs
through the real DataCollectionSettings.

The "taken" test is exact again: <run>_master.h5 plus the DAQ's
derived <run>_raster2d/_raster1d_master.h5. The directory test and the
_*_master.h5 glob are gone: neither is a file a run writes, and they
painted run numbers red that nothing would ever produce.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 14:27:19 +02:00
committed by duan_j
co-authored by Claude Fable 5.1
parent 19361974d3
commit bd2b25e156
4 changed files with 69 additions and 18 deletions
@@ -547,18 +547,52 @@ def test_a_derived_dataset_counts_as_taken(file_panel, monkeypatch):
# X-ray centering writes <run>_raster2d_master.h5, not <run>_master.h5.
from aare.gui.panels import file_path_panel
_taken(monkeypatch)
monkeypatch.setattr(
file_path_panel.glob,
"glob",
lambda pat: ["hit"] if pat.endswith("raster/d/x_001_*_master.h5") else [],
)
_taken(monkeypatch, "raster/d/x_001_raster2d_master.h5")
monkeypatch.setattr(file_path_panel.QMessageBox, "warning", lambda *a, **k: None)
assert file_panel.file_path_error_box(scan_kind="raster") is False
assert file_panel.run_number_edit.value() == 2
def test_a_directory_or_a_sibling_run_is_not_taken(file_panel, monkeypatch):
# Only the exact master files count; anything else would paint runs red
# that nothing will write.
_taken(monkeypatch, "raster/d/x_001", "raster/d/x_0011_master.h5", "raster/d/x_001_data.h5")
file_panel.set_scan_kind("raster")
assert file_panel.file_name_label.styleSheet() == ""
assert file_panel.file_path_error_box(scan_kind="raster") is True
def test_every_tab_reaches_the_file_guard(settings_panel, monkeypatch):
# The tabs live in a QStackedWidget, which reparents them: a parent()
# lookup of file_path_panel found nothing and every Run skipped the guard.
from aare.gui.panels import scan_settings_panel
asked = []
monkeypatch.setattr(
settings_panel.file_path_panel,
"file_path_error_box",
lambda scan_kind: asked.append(scan_kind) or False,
)
monkeypatch.setattr(scan_settings_panel, "precondition_check", lambda *a, **k: True)
scans = []
for panel in (settings_panel.screening, settings_panel.raster):
panel._beamline_state = BeamlineStateEnum.SampleAlignment
settings_panel.screening.rotation_scan.connect(scans.append)
settings_panel.simple.rotation_scan.connect(scans.append)
settings_panel.raster.evaluate_grid.connect(lambda: scans.append("grid"))
settings_panel.raster.evaluate_grid_auto.connect(lambda: scans.append("auto"))
settings_panel.screening.run_screening()
settings_panel.screening.run_measurement()
settings_panel.simple.run_measurement()
settings_panel.raster._on_evaluate_clicked()
settings_panel.raster._on_evaluate_auto_clicked()
assert asked == ["screening", "rotation", "rotation", "raster", "raster"]
assert scans == []
def test_simple_tab_run_is_blocked_by_the_file_guard(qapp):
from PySide6.QtWidgets import QWidget