More fixes to force tests to work

Fixed yet another odd QT behavior when tests
were run all together.
This commit is contained in:
Marta Marczykowska-Górecka 2019-05-20 23:23:03 +02:00
parent d92c782ec9
commit 5d3c870c1b
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
6 changed files with 146 additions and 24 deletions

View File

@ -62,16 +62,29 @@ class BackupTest(unittest.TestCase):
def tearDown(self): def tearDown(self):
self.dialog.hide() self.dialog.hide()
# process any pending events before destroying the object
self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.qtapp.deleteLater() self.qtapp.deleteLater()
self.dialog.deleteLater() self.dialog.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents() self.qtapp.processEvents()
self.qtapp.processEvents()
self.qtapp.processEvents() # execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0)) self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close() self.loop.close()
del self.loop
del self.dialog del self.dialog
del self.qtapp del self.qtapp
del self.loop
gc.collect() gc.collect()
super(BackupTest, self).tearDown() super(BackupTest, self).tearDown()

View File

@ -21,7 +21,9 @@
# #
import logging.handlers import logging.handlers
import unittest.mock import unittest.mock
import sys import quamash
import asyncio
import gc
from PyQt4 import QtGui from PyQt4 import QtGui
from qubesadmin import Qubes from qubesadmin import Qubes
@ -33,9 +35,31 @@ class BackupUtilsTest(unittest.TestCase):
super(BackupUtilsTest, self).setUp() super(BackupUtilsTest, self).setUp()
self.qapp = Qubes() self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"]) self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
def tearDown(self): def tearDown(self):
# process any pending events before destroying the object
self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.qtapp.deleteLater() self.qtapp.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents()
# execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close()
del self.qtapp
del self.loop
gc.collect()
super(BackupUtilsTest, self).tearDown() super(BackupUtilsTest, self).tearDown()
def test_01_fill_apvms(self): def test_01_fill_apvms(self):

View File

@ -20,13 +20,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
import logging.handlers import logging.handlers
import sys import quamash
import asyncio
import unittest import unittest
import unittest.mock import unittest.mock
import qubesadmin import qubesadmin
import gc
from PyQt4 import QtGui, QtTest, QtCore from PyQt4 import QtGui, QtTest, QtCore
from qubesadmin import Qubes, events, utils, exc from qubesadmin import Qubes
from qubesmanager import create_new_vm from qubesmanager import create_new_vm
@ -36,6 +38,7 @@ class NewVmTest(unittest.TestCase):
self.qapp = Qubes() self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"]) self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
# mock up the Create VM Thread to avoid changing system state # mock up the Create VM Thread to avoid changing system state
self.patcher_thread = unittest.mock.patch( self.patcher_thread = unittest.mock.patch(
@ -53,10 +56,31 @@ class NewVmTest(unittest.TestCase):
self.qtapp, self.qapp) self.qtapp, self.qapp)
def tearDown(self): def tearDown(self):
self.dialog.deleteLater() # process any pending events before destroying the object
self.qtapp.deleteLater()
self.qtapp.processEvents() self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.qtapp.deleteLater()
self.dialog.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents()
# execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close()
del self.dialog
del self.qtapp
del self.loop
gc.collect()
super(NewVmTest, self).tearDown() super(NewVmTest, self).tearDown()
def test_00_window_loads(self): def test_00_window_loads(self):

View File

@ -20,7 +20,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# #
import logging.handlers import logging.handlers
import sys import quamash
import asyncio
import unittest import unittest
import unittest.mock import unittest.mock
import gc import gc
@ -36,6 +37,7 @@ class GlobalSettingsTest(unittest.TestCase):
self.qapp = Qubes() self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"]) self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
self.dialog = global_settings.GlobalSettingsWindow(self.qtapp, self.dialog = global_settings.GlobalSettingsWindow(self.qtapp,
self.qapp) self.qapp)
@ -45,13 +47,29 @@ class GlobalSettingsTest(unittest.TestCase):
self.addCleanup(self.setattr_patcher.stop) self.addCleanup(self.setattr_patcher.stop)
def tearDown(self): def tearDown(self):
self.dialog.deleteLater() # process any pending events before destroying the object
self.qtapp.deleteLater()
self.qtapp.processEvents() self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.qtapp.deleteLater()
self.dialog.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents()
# execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close()
del self.dialog del self.dialog
del self.qtapp del self.qtapp
del self.loop
gc.collect() gc.collect()
super(GlobalSettingsTest, self).tearDown() super(GlobalSettingsTest, self).tearDown()

View File

@ -56,16 +56,29 @@ class QubeManagerTest(unittest.TestCase):
self.qtapp, self.qapp, self.dispatcher) self.qtapp, self.qapp, self.dispatcher)
def tearDown(self): def tearDown(self):
# process any pending events before destroying the object
self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.qtapp.deleteLater() self.qtapp.deleteLater()
self.dialog.deleteLater() self.dialog.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents() self.qtapp.processEvents()
self.qtapp.processEvents()
self.qtapp.processEvents() # execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0)) self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close() self.loop.close()
del self.loop
del self.dialog del self.dialog
del self.qtapp del self.qtapp
del self.loop
gc.collect() gc.collect()
super(QubeManagerTest, self).tearDown() super(QubeManagerTest, self).tearDown()
@ -1152,7 +1165,6 @@ class QubeManagerTest(unittest.TestCase):
self.assertTrue(self.dialog.logs_menu.isEnabled()) self.assertTrue(self.dialog.logs_menu.isEnabled())
dom0_logs = set() dom0_logs = set()
print(self.dialog.logs_menu.actions())
for c in self.dialog.logs_menu.actions(): for c in self.dialog.logs_menu.actions():
dom0_logs.add(c.text()) dom0_logs.add(c.text())
self.assertIsNotNone( self.assertIsNotNone(

View File

@ -24,6 +24,8 @@ import unittest
import unittest.mock import unittest.mock
import gc import gc
import quamash
import asyncio
from PyQt4 import QtGui, QtTest, QtCore from PyQt4 import QtGui, QtTest, QtCore
from qubesadmin import Qubes from qubesadmin import Qubes
@ -41,15 +43,36 @@ class VMSettingsTest(unittest.TestCase):
self.qapp = Qubes() self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"]) self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
def tearDown(self): def tearDown(self):
del self.qapp.domains["testvm"] del self.qapp.domains["testvm"]
self.qtapp.deleteLater() # process any pending events before destroying the object
self.qtapp.processEvents() self.qtapp.processEvents()
# queue destroying the QApplication object, do that for any other QT
# related objects here too
self.dialog.deleteLater()
self.qtapp.deleteLater()
# process any pending events (other than just queued destroy),
# just in case
self.qtapp.processEvents()
self.qtapp.processEvents()
self.qtapp.processEvents()
# execute main loop, which will process all events, _
# including just queued destroy_
self.loop.run_until_complete(asyncio.sleep(0))
# at this point it QT objects are destroyed, cleanup all remaining
# references;
# del other QT object here too
self.loop.close()
del self.dialog
del self.qtapp del self.qtapp
del self.loop
gc.collect() gc.collect()
super(VMSettingsTest, self).tearDown() super(VMSettingsTest, self).tearDown()
@ -60,37 +83,37 @@ class VMSettingsTest(unittest.TestCase):
self.vm, self.qtapp, "basic") self.vm, self.qtapp, "basic")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.basic_tab) self.dialog.tabWidget.currentWidget() is self.dialog.basic_tab)
self.dialog.close() self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced") self.vm, self.qtapp, "advanced")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.advanced_tab) self.dialog.tabWidget.currentWidget() is self.dialog.advanced_tab)
self.dialog.close() self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "firewall") self.vm, self.qtapp, "firewall")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.firewall_tab) self.dialog.tabWidget.currentWidget() is self.dialog.firewall_tab)
self.dialog.close() self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "devices") self.vm, self.qtapp, "devices")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.devices_tab) self.dialog.tabWidget.currentWidget() is self.dialog.devices_tab)
self.dialog.close() self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "applications") self.vm, self.qtapp, "applications")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.apps_tab) self.dialog.tabWidget.currentWidget() is self.dialog.apps_tab)
self.dialog.close() self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "services") self.vm, self.qtapp, "services")
self.assertTrue( self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.services_tab) self.dialog.tabWidget.currentWidget() is self.dialog.services_tab)
self.dialog.close() self.dialog.deleteLater()
def test_01_basic_tab_default(self): def test_01_basic_tab_default(self):
self.vm = self.qapp.add_new_vm("AppVM", "testvm", "blue") self.vm = self.qapp.add_new_vm("AppVM", "testvm", "blue")
@ -407,6 +430,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.maxmem, 0) self.assertEqual(self.vm.maxmem, 0)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced") self.vm, self.qtapp, "advanced")
self.assertFalse(self.dialog.include_in_balancing.isChecked()) self.assertFalse(self.dialog.include_in_balancing.isChecked())
@ -456,6 +481,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.kernel, new_kernel) self.assertEqual(self.vm.kernel, new_kernel)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced") self.vm, self.qtapp, "advanced")
self._set_default(self.dialog.kernel) self._set_default(self.dialog.kernel)
@ -477,6 +504,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.virt_mode.upper(), mode) self.assertEqual(self.vm.virt_mode.upper(), mode)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced") self.vm, self.qtapp, "advanced")
self._set_default(self.dialog.virt_mode) self._set_default(self.dialog.virt_mode)
@ -495,6 +524,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.default_dispvm.name, new_dvm) self.assertEqual(self.vm.default_dispvm.name, new_dvm)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow( self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced") self.vm, self.qtapp, "advanced")
self._set_default(self.dialog.default_dispvm) self._set_default(self.dialog.default_dispvm)