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
父節點 d92c782ec9
當前提交 5d3c870c1b
沒有發現已知的金鑰在資料庫的簽署中
GPG 金鑰 ID: 9A752C30B26FD04B
共有 6 個檔案被更改,包括 146 行新增24 行删除

查看文件

@ -62,16 +62,29 @@ class BackupTest(unittest.TestCase):
def tearDown(self):
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.dialog.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.loop
del self.dialog
del self.qtapp
del self.loop
gc.collect()
super(BackupTest, self).tearDown()

查看文件

@ -21,7 +21,9 @@
#
import logging.handlers
import unittest.mock
import sys
import quamash
import asyncio
import gc
from PyQt4 import QtGui
from qubesadmin import Qubes
@ -33,9 +35,31 @@ class BackupUtilsTest(unittest.TestCase):
super(BackupUtilsTest, self).setUp()
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
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()
# 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()
def test_01_fill_apvms(self):

查看文件

@ -20,13 +20,15 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import logging.handlers
import sys
import quamash
import asyncio
import unittest
import unittest.mock
import qubesadmin
import gc
from PyQt4 import QtGui, QtTest, QtCore
from qubesadmin import Qubes, events, utils, exc
from qubesadmin import Qubes
from qubesmanager import create_new_vm
@ -36,6 +38,7 @@ class NewVmTest(unittest.TestCase):
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
# mock up the Create VM Thread to avoid changing system state
self.patcher_thread = unittest.mock.patch(
@ -53,10 +56,31 @@ class NewVmTest(unittest.TestCase):
self.qtapp, self.qapp)
def tearDown(self):
self.dialog.deleteLater()
self.qtapp.deleteLater()
# 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.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()
def test_00_window_loads(self):

查看文件

@ -20,7 +20,8 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
import logging.handlers
import sys
import quamash
import asyncio
import unittest
import unittest.mock
import gc
@ -36,6 +37,7 @@ class GlobalSettingsTest(unittest.TestCase):
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
self.dialog = global_settings.GlobalSettingsWindow(self.qtapp,
self.qapp)
@ -45,13 +47,29 @@ class GlobalSettingsTest(unittest.TestCase):
self.addCleanup(self.setattr_patcher.stop)
def tearDown(self):
self.dialog.deleteLater()
self.qtapp.deleteLater()
# 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.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(GlobalSettingsTest, self).tearDown()

查看文件

@ -56,16 +56,29 @@ class QubeManagerTest(unittest.TestCase):
self.qtapp, self.qapp, self.dispatcher)
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.dialog.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.loop
del self.dialog
del self.qtapp
del self.loop
gc.collect()
super(QubeManagerTest, self).tearDown()
@ -1152,7 +1165,6 @@ class QubeManagerTest(unittest.TestCase):
self.assertTrue(self.dialog.logs_menu.isEnabled())
dom0_logs = set()
print(self.dialog.logs_menu.actions())
for c in self.dialog.logs_menu.actions():
dom0_logs.add(c.text())
self.assertIsNotNone(

查看文件

@ -24,6 +24,8 @@ import unittest
import unittest.mock
import gc
import quamash
import asyncio
from PyQt4 import QtGui, QtTest, QtCore
from qubesadmin import Qubes
@ -41,15 +43,36 @@ class VMSettingsTest(unittest.TestCase):
self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)
def tearDown(self):
del self.qapp.domains["testvm"]
self.qtapp.deleteLater()
# 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.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.loop
gc.collect()
super(VMSettingsTest, self).tearDown()
@ -60,37 +83,37 @@ class VMSettingsTest(unittest.TestCase):
self.vm, self.qtapp, "basic")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.basic_tab)
self.dialog.close()
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.advanced_tab)
self.dialog.close()
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "firewall")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.firewall_tab)
self.dialog.close()
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "devices")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.devices_tab)
self.dialog.close()
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "applications")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.apps_tab)
self.dialog.close()
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "services")
self.assertTrue(
self.dialog.tabWidget.currentWidget() is self.dialog.services_tab)
self.dialog.close()
self.dialog.deleteLater()
def test_01_basic_tab_default(self):
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.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced")
self.assertFalse(self.dialog.include_in_balancing.isChecked())
@ -456,6 +481,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.kernel, new_kernel)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced")
self._set_default(self.dialog.kernel)
@ -477,6 +504,8 @@ class VMSettingsTest(unittest.TestCase):
self.assertEqual(self.vm.virt_mode.upper(), mode)
self.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced")
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.dialog.deleteLater()
self.dialog = vm_settings.VMSettingsWindow(
self.vm, self.qtapp, "advanced")
self._set_default(self.dialog.default_dispvm)