Files
AareDAQ/tests/unit/gui/test_busy_overlay.py
duan_jandClaude Fable 5.1 a56457d03b
CI / test (3.13) (pull_request) Successful in 1m4s
CI / lint (pull_request) Successful in 1m9s
CI / test (3.12) (pull_request) Successful in 1m13s
CI / test-with-beamline-plugins (pxi_bec) (pull_request) Successful in 1m11s
CI / test (3.14) (pull_request) Successful in 1m16s
CI / test-with-beamline-plugins (pxii_bec) (pull_request) Successful in 1m16s
CI / test-with-beamline-plugins (pxiii_bec) (pull_request) Successful in 1m25s
CI / test-with-coverage (pull_request) Successful in 1m40s
CI / coverage-analysis (pull_request) Successful in 4s
CI / lint (push) Successful in 31s
Docs build and publish / docker (push) Successful in 15s
CI / test (3.12) (push) Canceled after 40s
CI / test (3.13) (push) Canceled after 37s
CI / test (3.14) (push) Canceled after 35s
CI / test-with-beamline-plugins (pxi_bec) (push) Canceled after 32s
CI / test-with-beamline-plugins (pxii_bec) (push) Canceled after 30s
CI / test-with-beamline-plugins (pxiii_bec) (push) Canceled after 27s
CI / test-with-coverage (push) Canceled after 25s
CI / coverage-analysis (push) Canceled after 0s
Build and Publish / release (push) Successful in 27s
test: route the tell-state stand-in through object for basedpyright
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-08 14:57:29 +02:00

78 lines
3.0 KiB
Python

"""The Axis views' busy flag is a passive status: plain shadowed text, not
the badge pill (which reads as a button). These checks fail if the text
renderer stops painting or the video view stops routing through it."""
from aarecommon.models.models import SessionsStateEnum
from PySide6.QtCore import Qt
from PySide6.QtGui import QPainter, QPixmap
from aare.gui.widgets.busy_overlay import build_busy_overlay_style, draw_busy_status_text
from aare.gui.widgets.video_image import VideoGraphicsView
def _busy_style():
style = build_busy_overlay_style(is_busy=True, tell_state=None)
assert style is not None and style.text == "BEAMLINE BUSY"
return style
def test_status_text_paints_something(qapp):
pixmap = QPixmap(400, 300)
pixmap.fill(Qt.GlobalColor.black)
blank = pixmap.toImage()
painter = QPainter(pixmap)
draw_busy_status_text(painter, 400, 300, _busy_style())
painter.end()
assert pixmap.toImage() != blank, "busy text must actually paint"
def test_video_view_paints_busy_text(qtbot):
view = VideoGraphicsView()
qtbot.addWidget(view)
view.resize(400, 300)
idle = view.grab().toImage()
view.set_busy_overlay_style(_busy_style())
assert view.grab().toImage() != idle, "busy style must change the rendered view"
view.set_busy_overlay_style(None)
assert view.grab().toImage() == idle, "clearing the style must restore the view"
def test_auto_centering_flag_overrides_alignment_gate():
# Callers pass is_busy=False during SampleAlignment; the flag must still
# produce the overlay, and the viewing-mode badge must still win.
style = build_busy_overlay_style(is_busy=False, tell_state=None, auto_centering=True)
assert style is not None and style.text == "AUTO CENTERING"
assert build_busy_overlay_style(is_busy=False, tell_state=None) is None
viewing = build_busy_overlay_style(
is_busy=False,
tell_state=None,
session_state=SessionsStateEnum.OwnedByElse,
auto_centering=True,
)
assert viewing is not None and viewing.text.startswith("Viewing mode")
def test_robot_cooling_is_the_only_blue_busy_state():
from types import SimpleNamespace
from typing import cast
from aarecommon.models.tell import TellStateModel
from aare.gui.styles import BUSY_BLUE, BUSY_PSI_RED
def _style(activity: str):
# Only .activity.value is read; cast keeps basedpyright off the stand-in.
tell = cast(
TellStateModel, cast(object, SimpleNamespace(activity=SimpleNamespace(value=activity)))
)
style = build_busy_overlay_style(is_busy=True, tell_state=tell)
assert style is not None
return style
assert _style("cooling").text == "ROBOT COOLING"
assert _style("cooling").badge_bg == BUSY_BLUE
# Every other busy state shares the one PSI red.
for activity in ("mounting", "unmounting", "drying", "unknown"):
assert _style(activity).badge_bg == BUSY_PSI_RED
assert _style("unknown").text == "BEAMLINE BUSY"