From e10f5ec088c6937beb26ec468f510a209c7cc782 Mon Sep 17 00:00:00 2001 From: wakonig_k Date: Tue, 15 Apr 2025 12:26:09 +0200 Subject: [PATCH] test(launch_window): tests for default and plugin auto updates --- bec_widgets/applications/launch_window.py | 2 +- tests/unit_tests/test_launch_window.py | 35 +++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/bec_widgets/applications/launch_window.py b/bec_widgets/applications/launch_window.py index 1274ec79..3f2d6c2b 100644 --- a/bec_widgets/applications/launch_window.py +++ b/bec_widgets/applications/launch_window.py @@ -330,7 +330,7 @@ class LaunchWindow(BECMainWindow): auto_update = self.tile_auto_update.selector.currentText() if auto_update == "Default": auto_update = None - self.launch("auto_update", auto_update=auto_update) + return self.launch("auto_update", auto_update=auto_update) @SafeSlot(popup_error=True) def _open_custom_ui_file(self): diff --git a/tests/unit_tests/test_launch_window.py b/tests/unit_tests/test_launch_window.py index b7e19fe7..182ebf02 100644 --- a/tests/unit_tests/test_launch_window.py +++ b/tests/unit_tests/test_launch_window.py @@ -7,6 +7,7 @@ from bec_lib.endpoints import MessageEndpoints import bec_widgets from bec_widgets.applications.launch_window import LaunchWindow +from bec_widgets.widgets.containers.auto_update.auto_updates import AutoUpdates from bec_widgets.widgets.containers.main_window.main_window import BECMainWindow, UILaunchWindow from .client_mocks import mocked_client @@ -58,3 +59,37 @@ def test_launch_window_launch_ui_file_raises_for_qmainwindow(bec_launch_window): bec_launch_window.launch("custom_ui_file", ui_file=ui_file_path) assert "Loading a QMainWindow from a UI file is currently not supported." in str(excinfo.value) + + +def test_launch_window_launch_default_auto_update(bec_launch_window): + # Mock the auto update selection + bec_launch_window.tile_auto_update.selector.setCurrentText("Default") + + # Call the method to launch the auto update + res = bec_launch_window._open_auto_update() + + assert isinstance(res, AutoUpdates) + assert res.windowTitle() == "BEC - AutoUpdates" + + # We need to manually close the launched window as it is not registered with qtbot. + # In real usage, the GUIServer would handle this in the sigint handler in case of a ctrl-c initiated shutdown. + res.close() + res.deleteLater() + + +def test_launch_window_launch_plugin_auto_update(bec_launch_window): + class PluginAutoUpdate(AutoUpdates): ... + + bec_launch_window.available_auto_updates = {"PluginAutoUpdate": PluginAutoUpdate} + bec_launch_window.tile_auto_update.selector.clear() + bec_launch_window.tile_auto_update.selector.addItems( + list(bec_launch_window.available_auto_updates.keys()) + ["Default"] + ) + bec_launch_window.tile_auto_update.selector.setCurrentText("PluginAutoUpdate") + res = bec_launch_window._open_auto_update() + assert isinstance(res, PluginAutoUpdate) + assert res.windowTitle() == "BEC - PluginAutoUpdate" + # We need to manually close the launched window as it is not registered with qtbot. + # In real usage, the GUIServer would handle this in the sigint handler in case of a ctrl-c initiated shutdown. + res.close() + res.deleteLater()