Skip to content

Commit

Permalink
More fixes to force tests to work
Browse files Browse the repository at this point in the history
Fixed yet another odd QT behavior when tests
were run all together.
  • Loading branch information
marmarta committed May 20, 2019
1 parent d92c782 commit 5d3c870
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 19 deletions.
19 changes: 16 additions & 3 deletions qubesmanager/tests/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,29 @@ def setUp(self):

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

Expand Down
26 changes: 25 additions & 1 deletion qubesmanager/tests/test_backup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,9 +35,31 @@ def setUp(self):
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):
Expand Down
30 changes: 27 additions & 3 deletions qubesmanager/tests/test_create_new_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -36,6 +38,7 @@ def setUp(self):

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(
Expand All @@ -53,10 +56,31 @@ def setUp(self):
self.qtapp, self.qapp)

def tearDown(self):
self.dialog.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):
Expand Down
22 changes: 20 additions & 2 deletions qubesmanager/tests/test_global_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@ def setUp(self):

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)

Expand All @@ -45,13 +47,29 @@ def setUp(self):
self.addCleanup(self.setattr_patcher.stop)

def tearDown(self):
self.dialog.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()

Expand Down
20 changes: 16 additions & 4 deletions qubesmanager/tests/test_qube_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,29 @@ def setUp(self):
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()

Expand Down Expand Up @@ -1152,7 +1165,6 @@ def test_500_logs(self):
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(
Expand Down
43 changes: 37 additions & 6 deletions qubesmanager/tests/test_vm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import unittest.mock

import gc
import quamash
import asyncio

from PyQt4 import QtGui, QtTest, QtCore
from qubesadmin import Qubes
Expand All @@ -41,15 +43,36 @@ def setUp(self):

self.qapp = Qubes()
self.qtapp = QtGui.QApplication(["test", "-style", "cleanlooks"])
self.loop = quamash.QEventLoop(self.qtapp)

def tearDown(self):
del self.qapp.domains["testvm"]

# 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()

Expand All @@ -60,37 +83,37 @@ def test_00_load_correct_tab(self):
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")
Expand Down Expand Up @@ -407,6 +430,8 @@ def test_21_nondefaultmaxmem(self):

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())
Expand Down Expand Up @@ -456,6 +481,8 @@ def test_24_kernel(self):

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)
Expand All @@ -477,6 +504,8 @@ def test_25_virtmode_change(self):

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)
Expand All @@ -495,6 +524,8 @@ def test_26_default_dispvm(self):

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)
Expand Down

0 comments on commit 5d3c870

Please sign in to comment.