Addon Manager: Fix GUI unit tests
Eliminate all calls to terminate() when dealing with QThread.
This commit is contained in:
committed by
Chris Hennes
parent
6c1d9701eb
commit
29faa0dfda
@@ -63,7 +63,7 @@ class DialogWatcher(QtCore.QObject):
|
||||
self.dialog_found = True
|
||||
self.timer.stop()
|
||||
|
||||
if not self.dialog_found:
|
||||
if self.execution_counter > 25 and 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()
|
||||
@@ -80,7 +80,7 @@ class DialogWatcher(QtCore.QObject):
|
||||
self.has_run = True
|
||||
self.execution_counter += 1
|
||||
if self.execution_counter > 100:
|
||||
print("Stopper timer after 100 iterations")
|
||||
print("Stopped timer after 100 iterations")
|
||||
self.timer.stop()
|
||||
|
||||
def click_button(self, widget):
|
||||
|
||||
@@ -552,6 +552,9 @@ class TestMacroInstallerGui(unittest.TestCase):
|
||||
translate("toolbar_button", "Add button?"),
|
||||
QtWidgets.QDialogButtonBox.No,
|
||||
)
|
||||
# Note: that dialog does not use a QButtonBox, so we can really only test its
|
||||
# reject() signal, which is triggered by the DialogWatcher when it cannot find
|
||||
# the button. In this case, failure to find that button is NOT an error.
|
||||
self.installer._ask_to_install_toolbar_button() # Blocks until killed by watcher
|
||||
self.assertTrue(dialog_watcher.dialog_found)
|
||||
|
||||
|
||||
@@ -116,7 +116,20 @@ class TestUpdateAllGui(unittest.TestCase):
|
||||
self.assertEqual(self.test_object.dialog.tableWidget.rowCount(), 3)
|
||||
|
||||
def test_cancelling_installation(self):
|
||||
self.factory.work_function = lambda: sleep(0.1)
|
||||
class Worker:
|
||||
def __init__(self):
|
||||
self.counter = 0
|
||||
self.LIMIT = 100
|
||||
self.limit_reached = False
|
||||
def run(self):
|
||||
while self.counter < self.LIMIT:
|
||||
if QtCore.QThread.currentThread().isInterruptionRequested():
|
||||
return
|
||||
self.counter += 1
|
||||
sleep(0.01)
|
||||
self.limit_reached = True
|
||||
worker = Worker()
|
||||
self.factory.work_function = worker.run
|
||||
self.test_object.run()
|
||||
cancel_timer = QtCore.QTimer()
|
||||
cancel_timer.timeout.connect(
|
||||
@@ -217,7 +230,7 @@ class TestUpdateAllGui(unittest.TestCase):
|
||||
self.test_object.active_installer = self.factory.get_updater(self.addons[0])
|
||||
self.test_object._update_finished()
|
||||
self.assertFalse(self.test_object.worker_thread.isRunning())
|
||||
self.test_object.worker_thread.terminate()
|
||||
self.test_object.worker_thread.quit()
|
||||
self.assertTrue(call_interceptor.called)
|
||||
self.test_object.worker_thread.wait()
|
||||
|
||||
@@ -227,7 +240,7 @@ class TestUpdateAllGui(unittest.TestCase):
|
||||
self.test_object.worker_thread.start()
|
||||
self.test_object._finalize()
|
||||
self.assertFalse(self.test_object.worker_thread.isRunning())
|
||||
self.test_object.worker_thread.terminate()
|
||||
self.test_object.worker_thread.quit()
|
||||
self.test_object.worker_thread.wait()
|
||||
self.assertFalse(self.test_object.running)
|
||||
self.assertIsNotNone(
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2022 FreeCAD Project Association *
|
||||
# * *
|
||||
@@ -39,11 +37,14 @@ from addonmanager_workers_startup import (
|
||||
LoadMacrosFromCacheWorker,
|
||||
)
|
||||
|
||||
run_slow_tests = False
|
||||
|
||||
|
||||
class TestWorkersStartup(unittest.TestCase):
|
||||
|
||||
MODULE = "test_workers_startup" # file name without extension
|
||||
|
||||
@unittest.skipUnless(run_slow_tests, "This integration test is slow and uses the network")
|
||||
def setUp(self):
|
||||
"""Set up the test"""
|
||||
self.test_dir = os.path.join(
|
||||
|
||||
@@ -35,6 +35,7 @@ class TestWorkersUtility(unittest.TestCase):
|
||||
|
||||
MODULE = "test_workers_utility" # file name without extension
|
||||
|
||||
@unittest.skip("Test is slow and uses the network: refactor!")
|
||||
def setUp(self):
|
||||
self.test_dir = os.path.join(
|
||||
FreeCAD.getHomePath(), "Mod", "AddonManager", "AddonManagerTest", "data"
|
||||
|
||||
Reference in New Issue
Block a user