mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-05-10 16:52:11 +02:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 389519013d | |||
| bf483dedf1 | |||
| 1e8b135b6a | |||
| 8ca0e297cf | |||
| 494c3bafb3 | |||
| 5cdd8c56f2 | |||
| 7715439d25 | |||
| f95aee2091 |
+1
-1
@@ -44,7 +44,7 @@ bw-generate-cli = "bec_widgets.cli.generate_cli:main"
|
||||
[project.optional-dependencies]
|
||||
dev = [
|
||||
"coverage~=7.0",
|
||||
"fakeredis~=2.23, >=2.23.2",
|
||||
"fakeredis==2.34.1",
|
||||
"pytest-bec-e2e>=2.21.4, <=4.0",
|
||||
"pytest-qt~=4.4",
|
||||
"pytest-random-order~=1.1",
|
||||
|
||||
@@ -3,6 +3,7 @@ from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from bec_lib.client import BECClient
|
||||
from bec_lib.endpoints import MessageEndpoints
|
||||
from bec_lib.messages import AvailableResourceMessage, ScanHistoryMessage
|
||||
from qtpy.QtCore import QModelIndex, Qt
|
||||
@@ -255,11 +256,10 @@ scan_history = ScanHistoryMessage(
|
||||
|
||||
|
||||
@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.xadd(
|
||||
topic=MessageEndpoints.scan_history(), msg_dict={"data": scan_history}
|
||||
)
|
||||
mocked_client.connector.xadd(MessageEndpoints.scan_history(), msg_dict={"data": scan_history})
|
||||
widget = ScanControl(client=mocked_client)
|
||||
qtbot.addWidget(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"]
|
||||
|
||||
|
||||
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_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
|
||||
|
||||
args, kwargs = scan_control.get_scan_parameters(bec_object=False)
|
||||
|
||||
assert args == ["samx", 0.0, 2.0]
|
||||
assert kwargs == {
|
||||
qtbot.waitUntil(lambda: slot_hit, timeout=1000)
|
||||
args = ["samx", 0.0, 2.0]
|
||||
kwargs = {
|
||||
"steps": 10,
|
||||
"relative": False,
|
||||
"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"},
|
||||
}
|
||||
|
||||
qtbot.waitUntil(
|
||||
lambda: scan_control.get_scan_parameters(bec_object=False) == (args, kwargs), timeout=5000
|
||||
)
|
||||
|
||||
|
||||
TEST_MD = {
|
||||
"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)
|
||||
|
||||
|
||||
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
|
||||
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.
|
||||
"""
|
||||
# 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
|
||||
while scan_control.arg_box.count_arg_rows() < 3:
|
||||
scan_control.arg_box.add_widget_bundle()
|
||||
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
|
||||
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)
|
||||
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
|
||||
args, kwargs = scan_control.get_scan_parameters(bec_object=False)
|
||||
|
||||
Reference in New Issue
Block a user