From 2575629e92f324ac9c7f6849fbb1bedfd1bcb65a Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Tue, 3 Jan 2023 20:19:30 -0600 Subject: [PATCH] Addon Manager: Fix macro installer bug Also some minor tweaks to the GUI unit testing. --- .../AddonManagerTest/gui/gui_mocks.py | 15 +++++++++++++++ .../AddonManagerTest/gui/test_installer_gui.py | 4 ++++ .../AddonManagerTest/gui/test_uninstaller_gui.py | 3 ++- .../AddonManager/addonmanager_installer_gui.py | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py b/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py index 2bd9df1c5d..7d4883accd 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py @@ -62,6 +62,21 @@ class DialogWatcher(QtCore.QObject): self.click_button(widget) self.dialog_found = True self.timer.stop() + + if not self.dialog_found: + # OK, it wasn't the active modal widget... was it some other window, and never became + # active? That's an error, but we should get it closed anyway. + windows = QtWidgets.QApplication.topLevelWidgets() + for widget in windows: + if ( + hasattr(widget, "windowTitle") + and callable(widget.windowTitle) + and widget.windowTitle() == self.dialog_to_watch_for + ): + self.click_button(widget) + self.timer.stop() + print("Found a window with the expected title, but it was not the active modal dialog.") + self.has_run = True self.execution_counter += 1 if self.execution_counter > 100: diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py b/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py index 8cd0b94a0e..6deb956274 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py @@ -434,6 +434,10 @@ class TestMacroInstallerGui(unittest.TestCase): def tearDown(self): pass + def test_class_is_initialized(self): + """Connecting to a signal does not throw""" + self.installer.finished.connect(lambda: None) + def test_ask_for_toolbar_no_dialog_default_exists(self): self.installer.addon_params.set("alwaysAskForToolbar", False) self.installer.addon_params.set("CustomToolbarName", "UnitTestCustomToolbar") diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py b/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py index 82e0b7b418..de24110726 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py @@ -107,7 +107,7 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Removing Addon"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(20, worker.stop) + QtCore.QTimer.singleShot(1000, worker.stop) # If the test fails, this kills the "worker" self.uninstaller_gui._confirm_uninstallation = lambda: True self.uninstaller_gui._run_uninstaller = worker.work self.uninstaller_gui._finalize = lambda: None @@ -121,6 +121,7 @@ class TestUninstallerGUI(unittest.TestCase): self.assertTrue( dialog_watcher.button_found, "Failed to find the expected button" ) + worker.stop() def test_success_dialog(self): dialog_watcher = DialogWatcher( diff --git a/src/Mod/AddonManager/addonmanager_installer_gui.py b/src/Mod/AddonManager/addonmanager_installer_gui.py index eea2414cea..e160aa2f1c 100644 --- a/src/Mod/AddonManager/addonmanager_installer_gui.py +++ b/src/Mod/AddonManager/addonmanager_installer_gui.py @@ -521,6 +521,7 @@ class MacroInstallerGUI(QtCore.QObject): """The provided addon object must have an attribute called "macro", and that attribute must itself provide a callable "install" method that takes a single string, the path to the installation location.""" + super().__init__() self.addon_to_install = addon self.worker_thread = None self.installer = MacroInstaller(self.addon_to_install)