From 7cbecd46c73576a93077bbcc7f99850f1046ff4f Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Mon, 2 Jan 2023 15:08:52 -0600 Subject: [PATCH] Addon Manager: Modify dialog closing during tests --- .../AddonManagerTest/gui/gui_mocks.py | 10 ++++++++++ .../AddonManagerTest/gui/test_installer_gui.py | 16 +--------------- .../AddonManagerTest/gui/test_uninstaller_gui.py | 6 ------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py b/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py index 3270e34780..2bd9df1c5d 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/gui_mocks.py @@ -44,6 +44,11 @@ class DialogWatcher(QtCore.QObject): else: self.button = QtWidgets.QDialogButtonBox.Cancel + self.execution_counter = 0 + self.timer = QtCore.QTimer() + self.timer.timeout.connect(self.run) + self.timer.start(10) + def run(self): widget = QtWidgets.QApplication.activeModalWidget() if widget: @@ -56,7 +61,12 @@ class DialogWatcher(QtCore.QObject): # Found the dialog we are looking for: now try to "click" the appropriate button self.click_button(widget) self.dialog_found = True + self.timer.stop() self.has_run = True + self.execution_counter += 1 + if self.execution_counter > 100: + print("Stopper timer after 100 iterations") + self.timer.stop() def click_button(self, widget): button_boxes = widget.findChildren(QtWidgets.QDialogButtonBox) diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py b/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py index 9b2cdac8be..8cd0b94a0e 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/test_installer_gui.py @@ -44,6 +44,7 @@ class TestInstallerGui(unittest.TestCase): self.installer_gui = AddonInstallerGUI(self.addon_to_install) self.finalized_thread = False + def tearDown(self): pass @@ -53,7 +54,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Success"), QtWidgets.QDialogButtonBox.Ok, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._installation_succeeded() self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -68,7 +68,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Installation Failed"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._installation_failed( self.addon_to_install, "Test of installation failure" ) @@ -85,7 +84,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Cannot execute Python"), QtWidgets.QDialogButtonBox.No, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._report_no_python_exe() self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -100,7 +98,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Cannot execute pip"), QtWidgets.QDialogButtonBox.No, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._report_no_pip("pip not actually run, this was a test") self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -115,7 +112,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Package installation failed"), QtWidgets.QDialogButtonBox.No, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._report_dependency_failure( "Unit test", "Nothing really failed, this is a test of the dialog box" ) @@ -150,7 +146,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Missing Requirement"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._handle_disallowed_python(disallowed_packages) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -168,7 +163,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Missing Requirement"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._handle_disallowed_python(disallowed_packages) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -184,7 +178,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Missing Requirement"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._report_missing_workbenches(wbs) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -200,7 +193,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Missing Requirement"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._report_missing_workbenches(wbs) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -221,7 +213,6 @@ class TestInstallerGui(unittest.TestCase): translate("DependencyResolutionDialog", "Resolve Dependencies"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer_gui._resolve_dependencies_then_install(missing) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -240,7 +231,6 @@ class TestInstallerGui(unittest.TestCase): translate("AddonsInstaller", "Incompatible Python version"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) stop_installing = self.installer_gui._check_python_version(missing) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -464,7 +454,6 @@ class TestMacroInstallerGui(unittest.TestCase): translate("select_toolbar_dialog", "Select Toolbar"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) result = self.installer._ask_for_toolbar([]) self.assertIsNone(result) @@ -481,7 +470,6 @@ class TestMacroInstallerGui(unittest.TestCase): translate("select_toolbar_dialog", "Select Toolbar"), QtWidgets.QDialogButtonBox.Ok, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) result = self.installer._ask_for_toolbar([]) self.assertIsNotNone(result) self.assertTrue(hasattr(result, "get")) @@ -501,7 +489,6 @@ class TestMacroInstallerGui(unittest.TestCase): translate("select_toolbar_dialog", "Select Toolbar"), self.interactor_selection_option_and_checkbox, ) - QtCore.QTimer.singleShot(10, dialog_interactor.run) ut_tb_1 = self.installer.toolbar_params.GetGroup("UT_TB_1") ut_tb_2 = self.installer.toolbar_params.GetGroup("UT_TB_2") ut_tb_3 = self.installer.toolbar_params.GetGroup("UT_TB_3") @@ -561,7 +548,6 @@ class TestMacroInstallerGui(unittest.TestCase): translate("toolbar_button", "Add button?"), QtWidgets.QDialogButtonBox.No, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.installer._ask_to_install_toolbar_button() # Blocks until killed by watcher self.assertTrue(dialog_watcher.dialog_found) diff --git a/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py b/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py index 93c59635ea..82e0b7b418 100644 --- a/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py +++ b/src/Mod/AddonManager/AddonManagerTest/gui/test_uninstaller_gui.py @@ -60,7 +60,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Confirm remove"), QtWidgets.QDialogButtonBox.Yes, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) answer = self.uninstaller_gui._confirm_uninstallation() self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -75,7 +74,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Confirm remove"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) answer = self.uninstaller_gui._confirm_uninstallation() self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -92,7 +90,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Removing Addon"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.uninstaller_gui._show_progress_dialog() # That call isn't modal, so spin our own event loop: while self.uninstaller_gui.progress_dialog.isVisible(): @@ -110,7 +107,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Removing Addon"), QtWidgets.QDialogButtonBox.Cancel, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) QtCore.QTimer.singleShot(20, worker.stop) self.uninstaller_gui._confirm_uninstallation = lambda: True self.uninstaller_gui._run_uninstaller = worker.work @@ -131,7 +127,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Uninstall complete"), QtWidgets.QDialogButtonBox.Ok, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.uninstaller_gui._succeeded(self.addon_to_remove) self.assertTrue( dialog_watcher.dialog_found, "Failed to find the expected dialog box" @@ -145,7 +140,6 @@ class TestUninstallerGUI(unittest.TestCase): translate("AddonsInstaller", "Uninstall failed"), QtWidgets.QDialogButtonBox.Ok, ) - QtCore.QTimer.singleShot(10, dialog_watcher.run) self.uninstaller_gui._failed( self.addon_to_remove, "Some failure message\nAnother failure message" )