Files
AareDAQ/tests/unit/gui/test_illumination_panel.py
duan_jandClaude Fable 5 16e112f44a
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 1m3s
CI / test (3.11) (pull_request) Successful in 1m25s
CI / test (3.12) (pull_request) Successful in 1m25s
CI / test (3.13) (pull_request) Successful in 1m24s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 1m32s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Successful in 1m37s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 1m41s
CI / test-with-coverage (pull_request) Successful in 2m4s
CI / coverage-analysis (pull_request) Successful in 3s
test: lift diff coverage over the 80 percent gate
Promote the illumination panel's __main__ self-check to a real pytest
file so CI counts it, add busy-overlay render checks (status text
paints, video view routes through it), and cover the motor group's
incomplete-entry and below-min Enter paths. Local diff coverage from
the gui suite alone: 82 percent.

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

81 lines
2.6 KiB
Python

"""Send/readback wiring for the light sliders (was a __main__ self-check in
the panel; promoted here so CI counts it). Every deliberate input path must
emit, and the status-poll readback must neither clobber a fresh user change
nor echo a PUT back to the server."""
import time
from types import SimpleNamespace
import pytest
from PySide6.QtCore import QPoint, QPointF, Qt
from PySide6.QtGui import QWheelEvent
from PySide6.QtWidgets import QApplication
from aare.gui.panels.illumination_panel import READBACK_GRACE_S, IlluminationPanel
@pytest.fixture
def panel(qtbot):
panel = IlluminationPanel()
qtbot.addWidget(panel)
return panel
def _wheel_notch(slider):
# One wheel notch; sliderReleased never fires for this path, which is
# exactly the case the valueChanged wiring exists for.
QApplication.sendEvent(
slider,
QWheelEvent(
QPointF(5, 5),
QPointF(5, 5),
QPoint(0, 0),
QPoint(0, 120),
Qt.MouseButton.NoButton,
Qt.KeyboardModifier.NoModifier,
Qt.ScrollPhase.NoScrollPhase,
False,
),
)
def _status(front=90.0, back=10.0):
return SimpleNamespace(bl=SimpleNamespace(front_light=front, back_light=back))
def test_wheel_notch_emits_both_lights(panel):
front, back = [], []
panel.front_light.connect(front.append)
panel.back_light.connect(back.append)
_wheel_notch(panel.front_light_slider)
_wheel_notch(panel.back_light_slider)
assert front, "wheel adjustment must emit front_light"
assert back, "wheel adjustment must emit back_light"
def test_readback_grace_holds_user_value(panel):
_wheel_notch(panel.front_light_slider)
held = panel.front_light_slider.value()
panel.update_daq_status(_status())
assert panel.front_light_slider.value() == held, "grace window must hold user value"
def test_readback_applies_after_grace_without_echo(panel):
sent = []
panel.front_light.connect(sent.append)
panel._last_user_change = time.monotonic() - READBACK_GRACE_S - 1
panel.update_daq_status(_status())
assert panel.front_light_slider.value() == 90, "readback must apply after grace"
assert panel.back_light_slider.value() == 10
assert not sent, "readback must not echo a PUT"
def test_readback_skipped_while_sliding(panel):
panel.on_slider_pressed()
panel._last_user_change = 0.0
panel.update_daq_status(_status(front=55.0))
assert panel.front_light_slider.value() != 55
panel.on_slider_released()
panel.update_daq_status(_status(front=55.0))
assert panel.front_light_slider.value() == 55