From 53fe1ac63d60252ecac6a3de10644c7dc83f6883 Mon Sep 17 00:00:00 2001 From: appel_c Date: Fri, 16 Jan 2026 17:48:18 +0100 Subject: [PATCH] fix(device-manager-display-widget): fix error message popup on cancelling upload --- .../device_manager_display_widget.py | 27 +++++++------- tests/unit_tests/test_busy_loader.py | 3 +- ...test_device_initialization_progress_bar.py | 36 +++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/bec_widgets/applications/views/device_manager_view/device_manager_display_widget.py b/bec_widgets/applications/views/device_manager_view/device_manager_display_widget.py index b2db6bbd..b414090d 100644 --- a/bec_widgets/applications/views/device_manager_view/device_manager_display_widget.py +++ b/bec_widgets/applications/views/device_manager_view/device_manager_display_widget.py @@ -231,8 +231,9 @@ class DeviceManagerDisplayWidget(DockAreaWidget): # Build dock layout using shared helpers self._build_docks() - logger.info("Connecting application about to quit signal to device manager view...") - QApplication.instance().aboutToQuit.connect(self._about_to_quit_handler) + # TODO Implement once issue #1012 is solved + # logger.info("Connecting application about to quit signal to device manager view...") + # QApplication.instance().aboutToQuit.connect(self._about_to_quit_handler) ############################## ### Custom set busy widget ### @@ -248,16 +249,17 @@ class DeviceManagerDisplayWidget(DockAreaWidget): ### Application quit handler ### ################################ - @SafeSlot() - def _about_to_quit_handler(self): - """Handle application about to quit event. If config upload is active, cancel it.""" - logger.info("Application is quitting, checking for active config upload...") - if self._config_upload_active: - logger.info("Application is quitting, cancelling active config upload...") - self._config_helper.send_config_request( - action="cancel", config=None, wait_for_response=True, timeout_s=10 - ) - logger.info("Config upload cancelled.") + # TODO Implement once issue #1012 is solved + # @SafeSlot() + # def _about_to_quit_handler(self): + # """Handle application about to quit event. If config upload is active, cancel it.""" + # logger.info("Application is quitting, checking for active config upload...") + # if self._config_upload_active: + # logger.info("Application is quitting, cancelling active config upload...") + # self._config_helper.send_config_request( + # action="cancel", config=None, wait_for_response=True, timeout_s=10 + # ) + # logger.info("Config upload cancelled.") def _set_busy_wrapper(self, enabled: bool): """Thin wrapper around set_busy to flip the state variable.""" @@ -669,7 +671,6 @@ class DeviceManagerDisplayWidget(DockAreaWidget): def _handle_cancel_config_upload_failed(self, exception: Exception): """Handle failure to cancel the config upload.""" - QMessageBox.critical(self, "Error Cancelling Upload", f"{str(exception)}") self._set_busy_wrapper(enabled=False) validation_results = self.device_table_view.get_validation_results() diff --git a/tests/unit_tests/test_busy_loader.py b/tests/unit_tests/test_busy_loader.py index d7fdc68a..0425c78b 100644 --- a/tests/unit_tests/test_busy_loader.py +++ b/tests/unit_tests/test_busy_loader.py @@ -47,7 +47,7 @@ def test_becwidget_start_busy_shows_overlay(qtbot, widget_busy): def test_becwidget_set_busy_toggle_and_text(qtbot, widget_idle): overlay = getattr(widget_idle, "_busy_overlay", None) - assert overlay is None, "Overlay should be lazily created when idle" + assert overlay is not None widget_idle.set_busy(True) overlay = getattr(widget_idle, "_busy_overlay") @@ -120,7 +120,6 @@ def test_becwidget_overlay_frame_geometry_and_style(qtbot, widget_busy): ss = frame.styleSheet() assert "dashed" in ss assert "border" in ss - assert "rgba(128, 128, 128, 110)" in ss def test_becwidget_busy_cycle_start_on_off_on(qtbot, widget_busy): diff --git a/tests/unit_tests/test_device_initialization_progress_bar.py b/tests/unit_tests/test_device_initialization_progress_bar.py index 22aac824..530b53c1 100644 --- a/tests/unit_tests/test_device_initialization_progress_bar.py +++ b/tests/unit_tests/test_device_initialization_progress_bar.py @@ -20,10 +20,13 @@ def progress_bar(qtbot, mocked_client): def test_progress_bar_initialization(progress_bar): """Test the initial state of the DeviceInitializationProgressBar.""" assert progress_bar.failed_devices == [] - assert progress_bar._user_value == 0 - assert progress_bar._user_maximum == 1 + assert progress_bar.progress_bar._user_value == 0 + assert progress_bar.progress_bar._user_maximum == 100 assert progress_bar.toolTip() == "No device initialization failures." + assert progress_bar.progress_label.text() == "Initializing devices..." + assert progress_bar.group_box.title() == "Config Update Progress" + def test_update_device_initialization_progress(progress_bar, qtbot): """Test updating the progress bar with different device initialization messages.""" @@ -34,22 +37,19 @@ def test_update_device_initialization_progress(progress_bar, qtbot): ) progress_bar._update_device_initialization_progress(msg.model_dump(), {}) - assert progress_bar._user_value == 1 - assert progress_bar._user_maximum == 3 - assert ( - f"Device initialization for '{msg.device}' is in progress..." - in progress_bar.center_label.text() - ) + assert progress_bar.progress_bar._user_value == 1 + assert progress_bar.progress_bar._user_maximum == 3 + assert progress_bar.progress_label.text() == f"{msg.device} initialization in progress..." + assert "1 / 3 - 33 %" == progress_bar.progress_bar.center_label.text() # II. Update with message of finished DeviceInitializationProgressMessage, finished=True, success=True msg.finished = True msg.success = True progress_bar._update_device_initialization_progress(msg.model_dump(), {}) - assert progress_bar._user_value == 1 - assert progress_bar._user_maximum == 3 - assert ( - f"Device initialization for '{msg.device}' succeeded!" in progress_bar.center_label.text() - ) + assert progress_bar.progress_bar._user_value == 1 + assert progress_bar.progress_bar._user_maximum == 3 + assert progress_bar.progress_label.text() == f"{msg.device} initialization succeeded!" + assert "1 / 3 - 33 %" == progress_bar.progress_bar.center_label.text() # III. Update with message of finished DeviceInitializationProgressMessage, finished=True, success=False msg.finished = True @@ -58,11 +58,11 @@ def test_update_device_initialization_progress(progress_bar, qtbot): msg.index = 2 with qtbot.waitSignal(progress_bar.failed_devices_changed) as signal_blocker: progress_bar._update_device_initialization_progress(msg.model_dump(), {}) - assert progress_bar._user_value == 2 - assert progress_bar._user_maximum == 3 - assert ( - f"Device initialization for '{msg.device}' failed!" in progress_bar.center_label.text() - ) + assert progress_bar.progress_label.text() == f"{msg.device} initialization failed!" + assert "2 / 3 - 66 %" == progress_bar.progress_bar.center_label.text() + assert progress_bar.progress_bar._user_value == 2 + assert progress_bar.progress_bar._user_maximum == 3 + assert signal_blocker.args == [[msg.device]] assert progress_bar.toolTip() == f"Failed devices: {msg.device}"