89 lines
2.8 KiB
Python
89 lines
2.8 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
|
|
|
|
|
|
@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 "color: red" in panel.ring_current.text()
|
|
assert "300.0" in panel.ring_current.text()
|