"""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"