mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
feat(server,launcher)!: RPC server separated with the launcher window introduced
This commit is contained in:
@ -144,7 +144,7 @@ def test_ring_bar(qtbot, connected_client_gui_obj):
|
||||
def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
gui = connected_client_gui_obj
|
||||
|
||||
assert len(gui.windows) == 1
|
||||
qtbot.waitUntil(lambda: len(gui.windows) == 1, timeout=3000)
|
||||
assert gui.windows["bec"] is gui.bec
|
||||
mw = gui.bec
|
||||
assert mw.__class__.__name__ == "RPCReference"
|
||||
@ -155,22 +155,6 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
assert gui._ipython_registry[xw._gui_id].__class__.__name__ == "BECDockArea"
|
||||
assert len(gui.windows) == 2
|
||||
|
||||
gui_info = gui._dump()
|
||||
mw_info = gui_info[mw._gui_id]
|
||||
assert mw_info["title"] == "BEC"
|
||||
assert mw_info["visible"]
|
||||
xw_info = gui_info[xw._gui_id]
|
||||
assert xw_info["title"] == "BEC - X"
|
||||
assert xw_info["visible"]
|
||||
|
||||
gui.hide()
|
||||
gui_info = gui._dump() #
|
||||
assert not any(windows["visible"] for windows in gui_info.values())
|
||||
|
||||
gui.show()
|
||||
gui_info = gui._dump()
|
||||
assert all(windows["visible"] for windows in gui_info.values())
|
||||
|
||||
assert gui._gui_is_alive()
|
||||
gui.kill_server()
|
||||
assert not gui._gui_is_alive()
|
||||
@ -186,10 +170,8 @@ def test_rpc_gui_obj(connected_client_gui_obj, qtbot):
|
||||
qtbot.waitUntil(wait_for_gui_started, timeout=3000)
|
||||
# gui.windows should have bec with gui_id 'bec'
|
||||
assert len(gui.windows) == 1
|
||||
assert gui.windows["bec"]._gui_id == mw._gui_id
|
||||
|
||||
# communication should work, main dock area should have same id and be visible
|
||||
gui_info = gui._dump()
|
||||
assert gui_info[mw._gui_id]["visible"]
|
||||
|
||||
yw = gui.new("Y")
|
||||
assert len(gui.windows) == 2
|
||||
|
@ -60,18 +60,14 @@ def test_rpc_plotting_shortcuts_init_configs(qtbot, connected_client_gui_obj):
|
||||
|
||||
# check if the correct devices are set
|
||||
# Curve
|
||||
assert c1._config["signal"] == {
|
||||
assert c1._config_dict["signal"] == {
|
||||
"dap": None,
|
||||
"name": "bpm4i",
|
||||
"entry": "bpm4i",
|
||||
"dap_oversample": 1,
|
||||
}
|
||||
assert c1._config["source"] == "device"
|
||||
assert c1._config["label"] == "bpm4i-bpm4i"
|
||||
|
||||
# Image Item
|
||||
assert im_item._config["monitor"] == "eiger"
|
||||
assert im_item._config["source"] == "auto"
|
||||
assert c1._config_dict["source"] == "device"
|
||||
assert c1._config_dict["label"] == "bpm4i-bpm4i"
|
||||
|
||||
|
||||
def test_rpc_waveform_scan(qtbot, bec_client_lib, connected_client_gui_obj):
|
||||
@ -93,6 +89,7 @@ def test_rpc_waveform_scan(qtbot, bec_client_lib, connected_client_gui_obj):
|
||||
status = scans.line_scan(dev.samx, -5, 5, steps=10, exp_time=0.05, relative=False)
|
||||
status.wait()
|
||||
|
||||
# FIXME if this gets flaky, we wait for status.scan.scan_id to be in client.history[-1] and then fetch data from history
|
||||
item = queue.scan_storage.storage[-1]
|
||||
last_scan_data = item.live_data if hasattr(item, "live_data") else item.data
|
||||
|
||||
|
@ -28,8 +28,10 @@ def qapplication(qtbot, request, testable_qtimer_class): # pylint: disable=unus
|
||||
print("Test failed, skipping cleanup checks")
|
||||
return
|
||||
|
||||
testable_qtimer_class.check_all_stopped(qtbot)
|
||||
# qapp = BECApplication()
|
||||
# qapp.shutdown()
|
||||
|
||||
testable_qtimer_class.check_all_stopped(qtbot)
|
||||
qapp = QApplication.instance()
|
||||
qapp.processEvents()
|
||||
if hasattr(qapp, "os_listener") and qapp.os_listener:
|
||||
|
@ -31,7 +31,7 @@ def test_rpc_call_new_dock(cli_dock_area):
|
||||
)
|
||||
def test_client_utils_start_plot_process(config, call_config):
|
||||
with mock.patch("bec_widgets.cli.client_utils.subprocess.Popen") as mock_popen:
|
||||
_start_plot_process("gui_id", BECDockArea, "bec", config)
|
||||
_start_plot_process("gui_id", "bec", config, gui_class="BECDockArea")
|
||||
command = [
|
||||
"bec-gui-server",
|
||||
"--id",
|
||||
@ -82,7 +82,6 @@ def test_client_utils_passes_client_config_to_server(bec_dispatcher):
|
||||
) # the started event will not be set, wait=True would block forever
|
||||
mock_start_plot.assert_called_once_with(
|
||||
"gui_id",
|
||||
BECGuiClient,
|
||||
gui_class_id="bec",
|
||||
config=mixin._client._service_config.config,
|
||||
logger=mock.ANY,
|
||||
|
@ -1,45 +1,56 @@
|
||||
import argparse
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from bec_lib.service_config import ServiceConfig
|
||||
|
||||
from bec_widgets.cli.server import _start_server
|
||||
from bec_widgets.widgets.containers.dock import BECDockArea
|
||||
from bec_widgets.cli.server import GUIServer
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mocked_cli_server():
|
||||
with mock.patch("bec_widgets.cli.server.BECWidgetsCLIServer") as mock_server:
|
||||
with mock.patch("bec_widgets.cli.server.ServiceConfig") as mock_config:
|
||||
with mock.patch("bec_lib.logger.bec_logger.configure") as mock_logger:
|
||||
yield mock_server, mock_config, mock_logger
|
||||
def gui_server():
|
||||
args = argparse.Namespace(
|
||||
config=None, id="gui_id", gui_class="LaunchWindow", gui_class_id="bec", hide=False
|
||||
)
|
||||
return GUIServer(args=args)
|
||||
|
||||
|
||||
def test_rpc_server_start_server_without_service_config(mocked_cli_server):
|
||||
def test_gui_server_start_server_without_service_config(gui_server):
|
||||
"""
|
||||
Test that the server is started with the correct arguments.
|
||||
"""
|
||||
mock_server, mock_config, _ = mocked_cli_server
|
||||
assert gui_server.config is None
|
||||
assert gui_server.gui_id == "gui_id"
|
||||
assert gui_server.gui_class == "LaunchWindow"
|
||||
assert gui_server.gui_class_id == "bec"
|
||||
assert gui_server.hide is False
|
||||
|
||||
_start_server("gui_id", BECDockArea, config=None)
|
||||
mock_server.assert_called_once_with(
|
||||
gui_id="gui_id", config=mock_config(), gui_class=BECDockArea, gui_class_id="bec"
|
||||
)
|
||||
|
||||
def test_gui_server_get_service_config(gui_server):
|
||||
"""
|
||||
Test that the server is started with the correct arguments.
|
||||
"""
|
||||
assert gui_server._get_service_config().config is ServiceConfig().config
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"config, call_config",
|
||||
"connections, hide",
|
||||
[
|
||||
("/path/to/config.yml", {"config_path": "/path/to/config.yml"}),
|
||||
({"key": "value"}, {"config": {"key": "value"}}),
|
||||
({}, False),
|
||||
({"launcher": mock.MagicMock()}, False),
|
||||
({"launcher": mock.MagicMock(), "dock_area": mock.MagicMock()}, True),
|
||||
],
|
||||
)
|
||||
def test_rpc_server_start_server_with_service_config(mocked_cli_server, config, call_config):
|
||||
"""
|
||||
Test that the server is started with the correct arguments.
|
||||
"""
|
||||
mock_server, mock_config, _ = mocked_cli_server
|
||||
config = mock_config(**call_config)
|
||||
_start_server("gui_id", BECDockArea, config=config)
|
||||
mock_server.assert_called_once_with(
|
||||
gui_id="gui_id", config=config, gui_class=BECDockArea, gui_class_id="bec"
|
||||
)
|
||||
def test_gui_server_turns_off_the_lights(gui_server, connections, hide):
|
||||
with mock.patch.object(gui_server, "launcher_window") as mock_launcher_window:
|
||||
with mock.patch.object(gui_server, "app") as mock_app:
|
||||
gui_server._turn_off_the_lights(connections)
|
||||
|
||||
if not hide:
|
||||
mock_launcher_window.show.assert_called_once()
|
||||
mock_launcher_window.activateWindow.assert_called_once()
|
||||
mock_launcher_window.raise_.assert_called_once()
|
||||
mock_app.setQuitOnLastWindowClosed.assert_called_once_with(True)
|
||||
else:
|
||||
mock_launcher_window.hide.assert_called_once()
|
||||
mock_app.setQuitOnLastWindowClosed.assert_called_once_with(False)
|
||||
|
Reference in New Issue
Block a user