Files
AareDAQ/tests/unit/gui/test_panels.py
duan_jandClaude Fable 5 aa6c226103
CI / lint (push) Skipped
CI / test (3.11) (push) Skipped
CI / test (3.12) (push) Skipped
CI / test (3.13) (push) Skipped
CI / test-with-beamline-plugins (pxi_bec) (push) Skipped
CI / test-with-beamline-plugins (pxii_bec) (push) Skipped
CI / test-with-beamline-plugins (pxiii_bec) (push) Skipped
CI / lint (pull_request) Successful in 1m17s
CI / test (3.11) (pull_request) Successful in 1m44s
CI / test (3.12) (pull_request) Successful in 1m41s
CI / test (3.13) (pull_request) Successful in 2m1s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 1m57s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 2m0s
CI / test-with-coverage (pull_request) Successful in 2m26s
CI / coverage-analysis (pull_request) Successful in 3s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Failing after 18m13s
test: cover every changed line in the branch diff
Diff coverage vs main now 100 percent from the gui suite alone:
non-staff locked banners and both gated-tab popups, remote-close
bookkeeping in update_daq_status, smargon staged moves, camera More
link and Alt-wheel axis fallback, number box relimits, energy row
emit, and the gui.main() banner/graceful-exit path.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-14 09:20:44 +02:00

108 lines
3.4 KiB
Python

import pytest
from aarecommon.math.coordinate import Coordinate, SmargonCoordinate
from aarecommon.math.diffraction_geometry import DiffractionGeometry
from aarecommon.math.sample_geometry import SampleGeometryModel
from aarecommon.models.models import (
BeamlineStateEnum,
BeamlineStatus,
DAQStatusModel,
SampleCameraSettings,
SessionStatus,
)
from aare.gui.panels.status_panel import StatusPanel
from aare.gui.styles import STATUS_ALERT
@pytest.fixture
def mock_daq_status():
status = DAQStatusModel(
bl=BeamlineStatus(
name="X10SA",
ring_current_mA=400.0,
flux_ph_s=1e12,
transmission=1.0,
cryojet_K=100.0,
front_light=50.0,
back_light=50.0,
shutter_open=False,
exp_shutter_open=False,
sample_camera=SampleCameraSettings(gain=1.0, exposure=0.02),
zoom=1.0,
commissioning_mode=False,
dtz_min=120.0,
dtz_max=1600.0,
),
diffraction=DiffractionGeometry(
detector_description="EIGER",
detector_serial_number="123",
dtz_mm=200.0,
pixel_size_mm=0.075,
energy_keV=12.658,
beam_center_pxl=(1000.0, 1000.0),
detector_size_pxl=(4000, 4000),
poni_rot1_rad=0.0,
poni_rot2_rad=0.0,
),
geom=SampleGeometryModel(
beam_location_pxl=Coordinate(x=1000, y=1000),
pixel_in_mm=0.001,
aerotech=Coordinate(x=0, y=0),
aerotech_meas=Coordinate(x=0, y=0),
smargon=SmargonCoordinate(sh_mm=Coordinate(x=0, y=0, z=0), phi_deg=0, chi_deg=0),
omega_deg=10.5,
beam_size_mm=Coordinate(x=0.02, y=0.01),
),
session=SessionStatus(),
state=BeamlineStateEnum.Maintenance,
busy=False,
)
return status
def test_status_panel_update(qtbot, mock_daq_status):
panel = StatusPanel()
qtbot.addWidget(panel)
# Initial state check (some values from __init__ defaults)
assert "400" in panel.ring_current.text()
# Update with mock status
panel.update_daq_status(mock_daq_status)
assert panel.omega.text() == "<b>10.50</b>"
assert "20.0" in panel.beam_size.text() # 0.02 * 1000
assert "10.0" in panel.beam_size.text() # 0.01 * 1000
assert "400.0" in panel.ring_current.text()
assert "1000.00" in panel.flux.text() # 1e12 / 1e9 = 1000
assert "0.979" in panel.wavelength.text()
def test_status_panel_low_current(qtbot, mock_daq_status):
panel = StatusPanel()
qtbot.addWidget(panel)
mock_daq_status.bl.ring_current_mA = 300.0
panel.update_daq_status(mock_daq_status)
assert f"color: {STATUS_ALERT}" in panel.ring_current.text()
assert "300.0" in panel.ring_current.text()
def test_smargon_staged_axes_move_and_actual_tracking(qtbot, mock_daq_status):
"""_move_axes sends only the staged axes (absent keys stay None = no
motion) and the status tick feeds actuals back into the move group."""
from aare.gui.panels.smargon_panel import SmargonPanel
panel = SmargonPanel()
qtbot.addWidget(panel)
sent = []
panel.smargon.connect(sent.append)
panel._move_axes({"chi": 2.0})
assert sent and sent[0].chi_deg == 2.0
assert sent[0].phi_deg is None # phi was not staged: must not move
panel.update_daq_status(mock_daq_status)
assert panel._geom is mock_daq_status.geom