0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

cleanup, use dict instead of scan_history message in qt signals/slots

This commit is contained in:
2025-07-13 21:25:48 +02:00
parent 27d4b939e1
commit 834a17aeb0
4 changed files with 49 additions and 52 deletions

View File

@ -116,7 +116,9 @@ def test_scan_history_device_viewer_receive_msg(
assert scan_history_device_viewer.scan_history_msg is None
assert scan_history_device_viewer.signal_model.signals == []
assert scan_history_device_viewer.signal_model.rowCount() == 0
scan_history_device_viewer.update_devices_from_scan_history(scan_history_msg)
scan_history_device_viewer.update_devices_from_scan_history(
scan_history_msg.content, scan_history_msg.metadata
)
assert scan_history_device_viewer.scan_history_msg == scan_history_msg
assert scan_history_device_viewer.device_combo.currentText() == "device2"
assert scan_history_device_viewer.signal_model.signals == [
@ -133,7 +135,7 @@ def test_scan_history_device_viewer_receive_msg(
## Update of second message should not change the device if still available
new_msg = scan_history_msg_2
scan_history_device_viewer.update_devices_from_scan_history(new_msg)
scan_history_device_viewer.update_devices_from_scan_history(new_msg.content, new_msg.metadata)
assert scan_history_device_viewer.scan_history_msg == new_msg
assert scan_history_device_viewer.signal_model.signals == [
("device2_signal4", _StoredDataInfo(shape=(30,))),
@ -152,7 +154,7 @@ def test_scan_history_device_viewer_receive_msg(
def test_scan_history_device_viewer_clear_view(qtbot, scan_history_device_viewer, scan_history_msg):
"""Test clearing the device viewer."""
scan_history_device_viewer.update_devices_from_scan_history(scan_history_msg)
scan_history_device_viewer.update_devices_from_scan_history(scan_history_msg.content)
assert scan_history_device_viewer.scan_history_msg == scan_history_msg
scan_history_device_viewer.clear_view()
assert scan_history_device_viewer.scan_history_msg is None
@ -163,7 +165,7 @@ def test_scan_history_device_viewer_on_request_plotting_clicked(
qtbot, scan_history_device_viewer, scan_history_msg
):
"""Test the request plotting button click."""
scan_history_device_viewer.update_devices_from_scan_history(scan_history_msg)
scan_history_device_viewer.update_devices_from_scan_history(scan_history_msg.content)
plotting_callback_args = []
@ -174,11 +176,14 @@ def test_scan_history_device_viewer_on_request_plotting_clicked(
scan_history_device_viewer.request_history_plot.connect(plotting_callback)
qtbot.mouseClick(scan_history_device_viewer.request_plotting_button, QtCore.Qt.LeftButton)
qtbot.waitUntil(lambda: len(plotting_callback_args) > 0, timeout=5000)
assert plotting_callback_args[0][2] == scan_history_msg
assert plotting_callback_args[0][0] in scan_history_msg.stored_data_info.keys()
# scan_id
assert plotting_callback_args[0][0] == scan_history_msg.scan_id
# device_name
assert plotting_callback_args[0][1] in scan_history_msg.stored_data_info.keys()
# signal_name
assert (
plotting_callback_args[0][1]
in scan_history_msg.stored_data_info[plotting_callback_args[0][0]].keys()
plotting_callback_args[0][2]
in scan_history_msg.stored_data_info[plotting_callback_args[0][1]].keys()
)
@ -188,7 +193,7 @@ def test_scan_history_metadata_viewer_receive_msg(
"""Test the initialization of ScanHistoryMetadataViewer."""
assert scan_history_metadata_viewer.scan_history_msg is None
assert scan_history_metadata_viewer.title() == "No Scan Selected"
scan_history_metadata_viewer.update_view(scan_history_msg)
scan_history_metadata_viewer.update_view(scan_history_msg.content)
assert scan_history_metadata_viewer.scan_history_msg == scan_history_msg
assert scan_history_metadata_viewer.title() == f"Metadata - Scan {scan_history_msg.scan_number}"
for row, k in enumerate(scan_history_metadata_viewer._scan_history_msg_labels.keys()):
@ -204,7 +209,7 @@ def test_scan_history_metadata_viewer_clear_view(
qtbot, scan_history_metadata_viewer, scan_history_msg
):
"""Test clearing the metadata viewer."""
scan_history_metadata_viewer.update_view(scan_history_msg)
scan_history_metadata_viewer.update_view(scan_history_msg.content)
assert scan_history_metadata_viewer.scan_history_msg == scan_history_msg
scan_history_metadata_viewer.clear_view()
assert scan_history_metadata_viewer.scan_history_msg is None
@ -289,17 +294,18 @@ def test_scan_history_browser(qtbot, scan_history_browser, scan_history_msg, sca
scan_history_browser.scan_history_view.topLevelItem(0)
).center(),
)
assert scan_history_browser.scan_history_view.currentIndex().row() == 0
# Both metadata and device viewers should be updated with the first scan
qtbot.waitUntil(
lambda: scan_history_browser.scan_history_metadata_viewer.scan_history_msg
== scan_history_msg_2,
timeout=5000,
timeout=2000,
)
qtbot.waitUntil(
lambda: scan_history_browser.scan_history_device_viewer.scan_history_msg
== scan_history_msg_2,
timeout=5000,
timeout=2000,
)
# Click on second scan item history to select it
@ -310,22 +316,15 @@ def test_scan_history_browser(qtbot, scan_history_browser, scan_history_msg, sca
scan_history_browser.scan_history_view.topLevelItem(1)
).center(),
)
qtbot.wait(2000)
qtbot.waitUntil(
lambda: scan_history_browser.scan_history_view.currentIndex().row() == 1, timeout=5000
)
qtbot.wait(2000) # Wait for cbs to be processed on scan history metadata and device viewers
assert scan_history_browser.scan_history_metadata_viewer.scan_history_msg == scan_history_msg
assert scan_history_browser.scan_history_device_viewer.scan_history_msg == scan_history_msg
# Both metadata and device viewers should be updated with the first scan
# qtbot.waitUntil(
# lambda: scan_history_browser.scan_history_metadata_viewer.scan_history_msg
# == scan_history_msg,
# timeout=5000,
# )
# qtbot.waitUntil(
# lambda: scan_history_browser.scan_history_device_viewer.scan_history_msg
# == scan_history_msg,
# timeout=5000,
# )
callback_args = []
def plotting_callback(device_name, signal_name, msg):
@ -340,9 +339,9 @@ def test_scan_history_browser(qtbot, scan_history_browser, scan_history_msg, sca
QtCore.Qt.LeftButton,
)
qtbot.waitUntil(lambda: len(callback_args) > 0, timeout=5000)
assert callback_args[0][2] == scan_history_msg
device_name = callback_args[0][0]
signal_name = callback_args[0][1]
assert callback_args[0][0] == scan_history_msg.scan_id
device_name = callback_args[0][1]
signal_name = callback_args[0][2]
assert device_name in scan_history_msg.stored_data_info.keys()
assert signal_name in scan_history_msg.stored_data_info[device_name].keys()
@ -355,9 +354,9 @@ def test_scan_history_browser(qtbot, scan_history_browser, scan_history_msg, sca
qtbot.waitUntil(
lambda: scan_history_browser.scan_history_metadata_viewer.scan_history_msg is None,
timeout=5000,
timeout=2000,
)
qtbot.waitUntil(
lambda: scan_history_browser.scan_history_device_viewer.scan_history_msg is None,
timeout=5000,
timeout=2000,
)