Compare commits

..

8 Commits

Author SHA1 Message Date
perl_d 389519013d pin fakeredis ? 2026-04-21 12:11:22 +02:00
perl_d bf483dedf1 readd to stream just before reading 2026-04-21 11:55:56 +02:00
perl_d 1e8b135b6a check slot is called 2026-04-21 11:41:06 +02:00
perl_d 8ca0e297cf check line scan exists in scans 2026-04-21 11:25:49 +02:00
perl_d 494c3bafb3 make sure current index will change before setting scan 2026-04-21 11:22:15 +02:00
perl_d 5cdd8c56f2 waituntil signals resolved 2026-04-21 10:48:55 +02:00
perl_d 7715439d25 waituntil signals resolved 2026-04-21 10:21:45 +02:00
perl_d f95aee2091 wip: clear redis just in case 2026-04-21 10:16:51 +02:00
2 changed files with 48 additions and 14 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ bw-generate-cli = "bec_widgets.cli.generate_cli:main"
[project.optional-dependencies] [project.optional-dependencies]
dev = [ dev = [
"coverage~=7.0", "coverage~=7.0",
"fakeredis~=2.23, >=2.23.2", "fakeredis==2.34.1",
"pytest-bec-e2e>=2.21.4, <=4.0", "pytest-bec-e2e>=2.21.4, <=4.0",
"pytest-qt~=4.4", "pytest-qt~=4.4",
"pytest-random-order~=1.1", "pytest-random-order~=1.1",
+47 -13
View File
@@ -3,6 +3,7 @@ from types import SimpleNamespace
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest import pytest
from bec_lib.client import BECClient
from bec_lib.endpoints import MessageEndpoints from bec_lib.endpoints import MessageEndpoints
from bec_lib.messages import AvailableResourceMessage, ScanHistoryMessage from bec_lib.messages import AvailableResourceMessage, ScanHistoryMessage
from qtpy.QtCore import QModelIndex, Qt from qtpy.QtCore import QModelIndex, Qt
@@ -255,11 +256,10 @@ scan_history = ScanHistoryMessage(
@pytest.fixture(scope="function") @pytest.fixture(scope="function")
def scan_control(qtbot, mocked_client): # , mock_dev): def scan_control(qtbot, mocked_client: BECClient):
mocked_client.connector._redis_conn.flushall()
mocked_client.connector.set(MessageEndpoints.available_scans(), available_scans_message) mocked_client.connector.set(MessageEndpoints.available_scans(), available_scans_message)
mocked_client.connector.xadd( mocked_client.connector.xadd(MessageEndpoints.scan_history(), msg_dict={"data": scan_history})
topic=MessageEndpoints.scan_history(), msg_dict={"data": scan_history}
)
widget = ScanControl(client=mocked_client) widget = ScanControl(client=mocked_client)
qtbot.addWidget(widget) qtbot.addWidget(widget)
qtbot.waitExposed(widget) qtbot.waitExposed(widget)
@@ -501,16 +501,29 @@ def test_changing_scans_remember_parameters(scan_control, mocked_client):
assert grid_kwargs["burst_at_each_point"] == kwargs["burst_at_each_point"] assert grid_kwargs["burst_at_each_point"] == kwargs["burst_at_each_point"]
def test_get_scan_parameters_from_redis(scan_control, mocked_client): def test_get_scan_parameters_from_redis(qtbot, scan_control: ScanControl, mocked_client):
scan_control.comboBox_scan_selection.setCurrentIndex(-1)
assert "line_scan" in [
scan_control.comboBox_scan_selection.itemText(i)
for i in range(scan_control.comboBox_scan_selection.count())
]
scan_name = "line_scan" scan_name = "line_scan"
scan_control.comboBox_scan_selection.setCurrentText(scan_name) scan_control.comboBox_scan_selection.setCurrentText(scan_name)
qtbot.wait(100)
slot_hit = False
def mock_request(*args):
ScanControl.request_last_executed_scan_parameters(scan_control, *args)
nonlocal slot_hit
slot_hit = True
scan_control.request_last_executed_scan_parameters = mock_request
# Trigger restore of parameters from history
scan_control.toggle.checked = True scan_control.toggle.checked = True
args, kwargs = scan_control.get_scan_parameters(bec_object=False) qtbot.waitUntil(lambda: slot_hit, timeout=1000)
args = ["samx", 0.0, 2.0]
assert args == ["samx", 0.0, 2.0] kwargs = {
assert kwargs == {
"steps": 10, "steps": 10,
"relative": False, "relative": False,
"exp_time": 2.0, "exp_time": 2.0,
@@ -518,6 +531,10 @@ def test_get_scan_parameters_from_redis(scan_control, mocked_client):
"metadata": {"comment": "", "sample_name": "", "scan_name": "line_scan"}, "metadata": {"comment": "", "sample_name": "", "scan_name": "line_scan"},
} }
qtbot.waitUntil(
lambda: scan_control.get_scan_parameters(bec_object=False) == (args, kwargs), timeout=5000
)
TEST_MD = { TEST_MD = {
"comment": "", "comment": "",
@@ -585,7 +602,7 @@ def test_scan_metadata_is_passed_to_scan_function(scan_control: ScanControl):
scans.grid_scan.assert_called_once_with(metadata=TEST_MD) scans.grid_scan.assert_called_once_with(metadata=TEST_MD)
def test_restore_parameters_with_fewer_arg_bundles(scan_control, qtbot): def test_restore_parameters_with_fewer_arg_bundles(scan_control: ScanControl, qtbot):
""" """
Ensure that when more argument bundles are present than exist in the Ensure that when more argument bundles are present than exist in the
stored history, restoring parameters regenerates the arg box to the stored history, restoring parameters regenerates the arg box to the
@@ -593,19 +610,36 @@ def test_restore_parameters_with_fewer_arg_bundles(scan_control, qtbot):
This is a check for the previous infinite loop bug. This is a check for the previous infinite loop bug.
""" """
# Select the scan type that has history with only one arg bundle # Select the scan type that has history with only one arg bundle
scan_control.comboBox_scan_selection.setCurrentText("line_scan") scan_control.comboBox_scan_selection.setCurrentIndex(-1)
assert "line_scan" in [
scan_control.comboBox_scan_selection.itemText(i)
for i in range(scan_control.comboBox_scan_selection.count())
]
scan_control.current_scan = "line_scan"
qtbot.waitUntil(lambda: scan_control.arg_box.count_arg_rows() == 1, timeout=1000)
# Manually add bundles so we end up with three rows # Manually add bundles so we end up with three rows
while scan_control.arg_box.count_arg_rows() < 3: while scan_control.arg_box.count_arg_rows() < 3:
scan_control.arg_box.add_widget_bundle() scan_control.arg_box.add_widget_bundle()
assert scan_control.arg_box.count_arg_rows() == 3 assert scan_control.arg_box.count_arg_rows() == 3
scan_control.client.connector.xadd(
MessageEndpoints.scan_history(), msg_dict={"data": scan_history}
)
slot_hit = False
def mock_request(*args):
ScanControl.request_last_executed_scan_parameters(scan_control, *args)
nonlocal slot_hit
slot_hit = True
scan_control.request_last_executed_scan_parameters = mock_request
# Trigger restore of parameters from history # Trigger restore of parameters from history
scan_control.toggle.checked = True scan_control.toggle.checked = True
qtbot.wait(200)
qtbot.waitUntil(lambda: slot_hit, timeout=1000)
# After restore, arg_box should have only one bundle (the history size) # After restore, arg_box should have only one bundle (the history size)
assert scan_control.arg_box.count_arg_rows() == 1 qtbot.waitUntil(lambda: scan_control.arg_box.count_arg_rows() == 1, timeout=1000)
# Verify that the restored parameter values match the history # Verify that the restored parameter values match the history
args, kwargs = scan_control.get_scan_parameters(bec_object=False) args, kwargs = scan_control.get_scan_parameters(bec_object=False)