Addon Manager: Modify dialog closing during tests

This commit is contained in:
Chris Hennes
2023-01-02 15:08:52 -06:00
parent 3bae9ab611
commit 7cbecd46c7
3 changed files with 11 additions and 21 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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"
)