Files
AareDAQ/tests/unit/gui/test_message_box.py
T
perl_d 40096ef2e4
CI / lint (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
wip fix: don't restart on beam recovery
2026-10-20 10:58:55 +02:00

67 lines
2.3 KiB
Python

from unittest.mock import MagicMock, patch
import pytest
from PySide6.QtWidgets import QMessageBox
from aare.gui.widgets.message_box import (
experiment_hutch_shutter_check,
reply_box,
ring_current_auto_check,
ring_current_low_check,
)
def test_reply_box(qtbot):
parent = MagicMock()
with patch("PySide6.QtWidgets.QMessageBox.question") as mock_question:
mock_question.return_value = QMessageBox.StandardButton.Yes
res = reply_box(parent, "Title", "Message")
assert res == QMessageBox.StandardButton.Yes
mock_question.assert_called_once()
@pytest.mark.timeout(10)
def test_ring_current_low_check_ok(qtbot):
# Should return True immediately if current is high enough
assert ring_current_low_check(None, 361.0) is True
def test_ring_current_low_check_low_yes(qtbot):
with patch("aare.gui.widgets.message_box.reply_box") as mock_reply:
mock_reply.return_value = QMessageBox.StandardButton.Yes
assert ring_current_low_check(None, 50.0) is True
mock_reply.assert_called_once()
def test_ring_current_low_check_low_no(qtbot):
with patch("aare.gui.widgets.message_box.reply_box") as mock_reply:
mock_reply.return_value = QMessageBox.StandardButton.No
assert ring_current_low_check(None, 50.0) is False
def test_experiment_hutch_shutter_check_open(qtbot):
assert experiment_hutch_shutter_check(None, True) is True
def test_experiment_hutch_shutter_check_closed_yes(qtbot):
with patch("aare.gui.widgets.message_box.reply_box") as mock_reply:
mock_reply.return_value = QMessageBox.StandardButton.Yes
assert experiment_hutch_shutter_check(None, False) is True
def test_ring_current_auto_check_yes(qtbot):
# This one uses a nested event loop, which can be tricky to test.
# We'll mock timer_box to return a box that we can close manually.
with patch("aare.gui.widgets.message_box.timer_box") as mock_timer_box:
box = QMessageBox()
box.setStandardButtons(QMessageBox.StandardButton.Yes)
mock_timer_box.return_value = box
# We need to close the box after some time to break the loop
from PySide6.QtCore import QTimer
QTimer.singleShot(100, lambda: box.done(QMessageBox.StandardButton.Yes))
res = ring_current_auto_check(None, 50.0, lambda: False)
assert res is True