mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat(server,launcher)!: RPC server separated with the launcher window introduced
This commit is contained in:
@ -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