mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
test: fix tests for namespace updates
This commit is contained in:
@ -28,16 +28,11 @@ def test_gui_rpc_registry(qtbot, connected_client_gui_obj):
|
||||
dock = dock_area.new("dock_0")
|
||||
|
||||
def check_dock_registered():
|
||||
dock_dict = (
|
||||
gui._registry_state.get(dock_area._gui_id, {}).get("config", {}).get("docks", {})
|
||||
)
|
||||
return len(dock_dict) == 1
|
||||
return dock._gui_id in gui._registry_state
|
||||
|
||||
qtbot.waitUntil(check_dock_registered, timeout=5000)
|
||||
assert hasattr(gui.cool_dock_area, "dock_0")
|
||||
|
||||
# assert hasattr(dock_area, "dock_0")
|
||||
|
||||
|
||||
def test_rpc_add_dock_with_figure_e2e(qtbot, bec_client_lib, connected_client_gui_obj):
|
||||
|
||||
@ -56,12 +51,9 @@ def test_rpc_add_dock_with_figure_e2e(qtbot, bec_client_lib, connected_client_gu
|
||||
|
||||
# Check that callback for dock_registry is done
|
||||
def check_docks_registered():
|
||||
dock_register = dock._parent._registry_state.get(dock._gui_id, None)
|
||||
if dock_register is not None:
|
||||
n_docks = dock_register.get("config", {}).get("docks", {})
|
||||
return len(n_docks) == 3
|
||||
return False
|
||||
# raise AssertionError("Docks not registered yet")
|
||||
return all(
|
||||
[gui_id in gui._registry_state for gui_id in [d0._gui_id, d1._gui_id, d2._gui_id]]
|
||||
)
|
||||
|
||||
# Waii until docks are registered
|
||||
qtbot.waitUntil(check_docks_registered, timeout=5000)
|
||||
@ -74,18 +66,12 @@ def test_rpc_add_dock_with_figure_e2e(qtbot, bec_client_lib, connected_client_gu
|
||||
fig1 = d1.new("BECFigure")
|
||||
fig2 = d2.new("BECFigure")
|
||||
|
||||
def check_fig2_registered():
|
||||
# return hasattr(d2, "BECFigure_2")
|
||||
dock_config = dock._parent._registry_state[dock._gui_id]["config"]["docks"].get(
|
||||
d2.widget_name, {}
|
||||
def check_figs_registered():
|
||||
return all(
|
||||
[gui_id in gui._registry_state for gui_id in [fig0._gui_id, fig1._gui_id, fig2._gui_id]]
|
||||
)
|
||||
if dock_config:
|
||||
n_widgets = dock_config.get("widgets", {})
|
||||
if any(widget_name.startswith("BECFigure") for widget_name in n_widgets.keys()):
|
||||
return True
|
||||
raise AssertionError("Figure not registered yet")
|
||||
|
||||
qtbot.waitUntil(check_fig2_registered, timeout=5000)
|
||||
qtbot.waitUntil(check_figs_registered, timeout=5000)
|
||||
|
||||
assert len(d0.element_list) == 1
|
||||
assert len(d1.element_list) == 1
|
||||
@ -112,11 +98,11 @@ def test_rpc_add_dock_with_figure_e2e(qtbot, bec_client_lib, connected_client_gu
|
||||
|
||||
def test_dock_manipulations_e2e(qtbot, connected_client_gui_obj):
|
||||
gui = connected_client_gui_obj
|
||||
dock = gui.bec
|
||||
dock_area = gui.bec
|
||||
|
||||
d0 = dock.new("dock_0")
|
||||
d1 = dock.new("dock_1")
|
||||
d2 = dock.new("dock_2")
|
||||
d0 = dock_area.new("dock_0")
|
||||
d1 = dock_area.new("dock_1")
|
||||
d2 = dock_area.new("dock_2")
|
||||
|
||||
assert hasattr(gui.bec, "dock_0")
|
||||
assert hasattr(gui.bec, "dock_1")
|
||||
@ -124,110 +110,54 @@ def test_dock_manipulations_e2e(qtbot, connected_client_gui_obj):
|
||||
assert len(gui.bec.panels) == 3
|
||||
|
||||
d0.detach()
|
||||
dock.detach_dock("dock_2")
|
||||
dock_area.detach_dock("dock_2")
|
||||
# How can we properly check that the dock is detached?
|
||||
assert len(gui.bec.panels) == 3
|
||||
|
||||
d0.attach()
|
||||
assert len(gui.bec.panels) == 3
|
||||
|
||||
gui_id = d2._gui_id
|
||||
|
||||
def wait_for_dock_removed():
|
||||
dock_config = gui._registry_state[gui.bec._gui_id]["config"]["docks"]
|
||||
return len(dock_config.keys()) == 2
|
||||
return gui_id not in gui._ipython_registry
|
||||
|
||||
d2.remove()
|
||||
qtbot.waitUntil(wait_for_dock_removed, timeout=5000)
|
||||
assert len(gui.bec.panels) == 2
|
||||
|
||||
def wait_for_docks_removed():
|
||||
dock_config = gui._registry_state[gui.bec._gui_id]["config"]["docks"]
|
||||
return len(dock_config.keys()) == 0
|
||||
ids = [widget._gui_id for widget in dock_area.panel_list]
|
||||
|
||||
dock.clear_all()
|
||||
def wait_for_docks_removed():
|
||||
return all(widget_id not in gui._ipython_registry for widget_id in ids)
|
||||
|
||||
dock_area.delete_all()
|
||||
qtbot.waitUntil(wait_for_docks_removed, timeout=5000)
|
||||
assert len(gui.bec.panels) == 0
|
||||
|
||||
|
||||
def test_ring_bar(connected_client_dock):
|
||||
dock = connected_client_dock
|
||||
def test_ring_bar(qtbot, connected_client_gui_obj):
|
||||
gui = connected_client_gui_obj
|
||||
dock_area = gui.bec
|
||||
d0 = dock_area.new("dock_0")
|
||||
|
||||
d0 = dock.add_dock(name="dock_0")
|
||||
|
||||
bar = d0.add_widget("RingProgressBar")
|
||||
assert bar.__class__.__name__ == "RingProgressBar"
|
||||
|
||||
plt = get_default_figure()
|
||||
|
||||
gui.selected_device = "bpm4i"
|
||||
|
||||
status = scans.line_scan(dev.samx, -5, 5, steps=10, exp_time=0.05, relative=False)
|
||||
status.wait()
|
||||
|
||||
# get data from curves
|
||||
widgets = plt.widget_list
|
||||
qtbot.waitUntil(lambda: len(plt.widget_list) > 0, timeout=5000)
|
||||
|
||||
item = queue.scan_storage.storage[-1]
|
||||
last_scan_data = item.live_data if hasattr(item, "live_data") else item.data
|
||||
|
||||
num_elements = 10
|
||||
|
||||
plot_name = f"Scan {status.scan.scan_number} - {dock.selected_device}"
|
||||
|
||||
qtbot.waitUntil(lambda: check_remote_data_size(widgets[0], plot_name, num_elements))
|
||||
plt_data = widgets[0].get_all_data()
|
||||
|
||||
# check plotted data
|
||||
assert (
|
||||
plt_data[f"Scan {status.scan.scan_number} - bpm4i"]["x"]
|
||||
== last_scan_data["samx"]["samx"].val
|
||||
)
|
||||
assert (
|
||||
plt_data[f"Scan {status.scan.scan_number} - bpm4i"]["y"]
|
||||
== last_scan_data["bpm4i"]["bpm4i"].val
|
||||
)
|
||||
|
||||
status = scans.grid_scan(
|
||||
dev.samx, -10, 10, 5, dev.samy, -5, 5, 5, exp_time=0.05, relative=False
|
||||
)
|
||||
status.wait()
|
||||
|
||||
plt = auto_updates.get_default_figure()
|
||||
widgets = plt.widget_list
|
||||
|
||||
qtbot.waitUntil(lambda: len(plt.widget_list) > 0, timeout=5000)
|
||||
|
||||
item = queue.scan_storage.storage[-1]
|
||||
last_scan_data = item.live_data if hasattr(item, "live_data") else item.data
|
||||
|
||||
plot_name = f"Scan {status.scan.scan_number} - bpm4i"
|
||||
|
||||
num_elements_bec = 25
|
||||
qtbot.waitUntil(lambda: check_remote_data_size(widgets[0], plot_name, num_elements_bec))
|
||||
plt_data = widgets[0].get_all_data()
|
||||
|
||||
# check plotted data
|
||||
assert (
|
||||
plt_data[f"Scan {status.scan.scan_number} - {dock.selected_device}"]["x"]
|
||||
== last_scan_data["samx"]["samx"].val
|
||||
)
|
||||
assert (
|
||||
plt_data[f"Scan {status.scan.scan_number} - {dock.selected_device}"]["y"]
|
||||
== last_scan_data["samy"]["samy"].val
|
||||
)
|
||||
bar = d0.new("RingProgressBar")
|
||||
assert bar.__class__.__name__ == "RPCReference"
|
||||
assert gui._ipython_registry[bar._gui_id].__class__.__name__ == "RingProgressBar"
|
||||
|
||||
|
||||
def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
gui = connected_client_gui_obj
|
||||
|
||||
assert gui.selected_device is None
|
||||
assert len(gui.windows) == 1
|
||||
assert gui.windows["bec"] is gui.bec
|
||||
mw = gui.bec
|
||||
assert mw.__class__.__name__ == "BECDockArea"
|
||||
assert mw.__class__.__name__ == "RPCReference"
|
||||
assert gui._ipython_registry[mw._gui_id].__class__.__name__ == "BECDockArea"
|
||||
|
||||
xw = gui.new("X")
|
||||
assert xw.__class__.__name__ == "BECDockArea"
|
||||
assert xw.__class__.__name__ == "RPCReference"
|
||||
assert gui._ipython_registry[xw._gui_id].__class__.__name__ == "BECDockArea"
|
||||
assert len(gui.windows) == 2
|
||||
|
||||
gui_info = gui._dump()
|
||||
@ -239,7 +169,7 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
assert xw_info["visible"]
|
||||
|
||||
gui.hide()
|
||||
gui_info = gui._dump()
|
||||
gui_info = gui._dump() #
|
||||
assert not any(windows["visible"] for windows in gui_info.values())
|
||||
|
||||
gui.show()
|
||||
@ -247,13 +177,13 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
assert all(windows["visible"] for windows in gui_info.values())
|
||||
|
||||
assert gui._gui_is_alive()
|
||||
gui._close()
|
||||
gui.close()
|
||||
assert not gui._gui_is_alive()
|
||||
gui._start_server(wait=True)
|
||||
gui._start(wait=True)
|
||||
assert gui._gui_is_alive()
|
||||
# calling start multiple times should not change anything
|
||||
gui._start_server(wait=True)
|
||||
gui._start()
|
||||
gui.start(wait=True)
|
||||
gui.start(wait=True)
|
||||
# gui.windows should have bec with gui_id 'bec'
|
||||
assert len(gui.windows) == 1
|
||||
assert gui.windows["bec"]._gui_id == mw._gui_id
|
||||
@ -261,24 +191,18 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
gui_info = gui._dump()
|
||||
assert gui_info[mw._gui_id]["visible"]
|
||||
|
||||
with pytest.raises(RuntimeError):
|
||||
gui.bec.delete()
|
||||
|
||||
yw = gui.new("Y")
|
||||
assert len(gui.windows) == 2
|
||||
yw.delete()
|
||||
assert len(gui.windows) == 1
|
||||
# check it is really deleted on server
|
||||
gui_info = gui._dump()
|
||||
assert yw._gui_id not in gui_info
|
||||
yw.remove()
|
||||
assert len(gui.windows) == 1 # only bec is left
|
||||
|
||||
|
||||
def test_rpc_call_with_exception_in_safeslot_error_popup(connected_client_gui_obj, qtbot):
|
||||
gui = connected_client_gui_obj
|
||||
|
||||
gui.main.add_dock("test")
|
||||
qtbot.waitUntil(lambda: len(gui.main.panels) == 2) # default_figure + test
|
||||
gui.bec.new("test")
|
||||
qtbot.waitUntil(lambda: len(gui.bec.panels) == 1) # test
|
||||
qtbot.wait(500)
|
||||
with pytest.raises(ValueError):
|
||||
gui.bec.add_dock("test")
|
||||
gui.bec.new("test")
|
||||
# time.sleep(0.1)
|
||||
|
@ -1,42 +1,30 @@
|
||||
import pytest
|
||||
|
||||
from bec_widgets.cli.client import BECFigure, BECImageShow, BECMotorMap, BECWaveform
|
||||
from bec_widgets.cli.client import ImageItem
|
||||
from bec_widgets.cli.rpc.rpc_base import RPCReference
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
# pylint: disable=protected-access
|
||||
|
||||
|
||||
def test_rpc_register_list_connections(connected_client_gui_obj):
|
||||
def test_rpc_reference_objects(connected_client_gui_obj):
|
||||
gui = connected_client_gui_obj
|
||||
fig = gui.window_list[0].new("fig").new(name="fig", widget="BECFigure")
|
||||
dock = gui.window_list[0].new("dock")
|
||||
plt = dock.new(name="fig", widget="Waveform")
|
||||
|
||||
plt = fig.plot(x_name="samx", y_name="bpm4i")
|
||||
im = fig.image("eiger")
|
||||
motor_map = fig.motor_map("samx", "samy")
|
||||
plt_z = fig.plot(x_name="samx", y_name="samy", z_name="bpm4i", new=True)
|
||||
plt.plot(x_name="samx", y_name="bpm4i")
|
||||
|
||||
# keep only class names from objects, since objects on server and client are different
|
||||
# so the best we can do is to compare types (rpc register is unit-tested elsewhere)
|
||||
all_connections = {obj_id: type(obj).__name__ for obj_id, obj in fig._get_all_rpc().items()}
|
||||
im = dock.new("Image")
|
||||
im.image("eiger")
|
||||
motor_map = dock.new("MotorMap")
|
||||
motor_map.map("samx", "samy")
|
||||
plt_z = dock.new("Waveform")
|
||||
plt_z.plot(x_name="samx", y_name="samy", z_name="bpm4i")
|
||||
|
||||
all_subwidgets_expected = {wid: type(widget).__name__ for wid, widget in fig.widgets.items()}
|
||||
curve_1D = fig.widgets[plt._rpc_id]
|
||||
curve_2D = fig.widgets[plt_z._rpc_id]
|
||||
curves_expected = {
|
||||
curve_1D._rpc_id: type(curve_1D).__name__,
|
||||
curve_2D._rpc_id: type(curve_2D).__name__,
|
||||
}
|
||||
curves_expected.update({curve._gui_id: type(curve).__name__ for curve in curve_1D.curves})
|
||||
curves_expected.update({curve._gui_id: type(curve).__name__ for curve in curve_2D.curves})
|
||||
fig_expected = {fig._rpc_id: type(fig).__name__, fig._rpc_id + ":window": "BECMainWindow"}
|
||||
image_item_expected = {
|
||||
fig.widgets[im._rpc_id].images[0]._rpc_id: type(fig.widgets[im._rpc_id].images[0]).__name__
|
||||
}
|
||||
assert len(plt_z.curves) == 1
|
||||
assert len(plt.curves) == 1
|
||||
assert im.monitor == "eiger"
|
||||
|
||||
all_connections_expected = {
|
||||
**all_subwidgets_expected,
|
||||
**curves_expected,
|
||||
**fig_expected,
|
||||
**image_item_expected,
|
||||
}
|
||||
|
||||
assert len(all_connections) == 9 + 3 # gui, dock_area, dock
|
||||
# In the old implementation, gui , dock_area and dock were not included in the _get_all_rpc() method
|
||||
# assert all_connections == all_connections_expected
|
||||
assert isinstance(im.main_image, RPCReference)
|
||||
image_item = gui._ipython_registry.get(im.main_image._gui_id, None)
|
||||
assert isinstance(image_item, ImageItem)
|
||||
|
Reference in New Issue
Block a user