Fix for icon size for Qube Manager tests

Also contains a tiny fix to Qube Manager itself (bug found with tests!)
And further fixes to qube manager tests for particularly slow days.
This commit is contained in:
Marta Marczykowska-Górecka 2020-08-14 12:38:21 +02:00
parent 3e512bb7c3
commit 22823f6106
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
2 changed files with 21 additions and 8 deletions

View File

@ -248,6 +248,7 @@ class VmInfo():
if not event or event.endswith(':label'):
self.label = getattr(self.vm, 'label', None)
self.icon = getattr(self.vm, 'icon', 'appvm-black')
if not event or event.endswith(':template'):
try:

View File

@ -38,7 +38,8 @@ import qubesmanager.qube_manager as qube_manager
from qubesmanager.tests import init_qtapp
icon_size = QSize(24, 24)
icon_size = qube_manager.icon_size
class QubeManagerTest(unittest.TestCase):
def setUp(self):
@ -208,10 +209,9 @@ class QubeManagerTest(unittest.TestCase):
def test_011_is_label_correct(self):
for row in range(self.dialog.table.model().rowCount()):
vm = self._get_table_vm(row)
icon = QIcon.fromTheme(vm.label.icon)
icon = QIcon.fromTheme(getattr(vm, 'icon', 'appvm-black'))
icon = icon.pixmap(icon_size)
label_pixmap = self._get_table_item(row, "Label", Qt.DecorationRole)
self.assertEqual(label_pixmap.toImage(), icon.toImage())
@ -825,7 +825,8 @@ class QubeManagerTest(unittest.TestCase):
# this requires very long timeout, because it takes time for the
# dispvm to vanish
self._run_command_and_process_events(
["qvm-run", "--dispvm", dispvm_template, "true"], timeout=60)
["qvm-run", "--dispvm", dispvm_template, "true"], timeout=60,
additional_timeout=30)
final_vms = self._create_set_of_current_vms()
@ -853,7 +854,8 @@ class QubeManagerTest(unittest.TestCase):
["qvm-prefs", dispvm_template, "memory", "600000"])
self._run_command_and_process_events(
["qvm-run", "--dispvm", dispvm_template, "true"], timeout=30)
["qvm-run", "--dispvm", dispvm_template, "true"], timeout=30,
additional_timeout=15)
final_vms = self._create_set_of_current_vms()
@ -1170,13 +1172,15 @@ class QubeManagerTest(unittest.TestCase):
result += 1
return result
def _run_command_and_process_events(self, command, timeout=5):
def _run_command_and_process_events(self, command, timeout=5,
additional_timeout=None):
"""
helper function to run a given command and process eventsDispatcher
events
:param command: list of strings, containing the command and all its
parameters
:param timeout: default 5 seconds
:param additional_timeout: default none
:return:
"""
asyncio.set_event_loop(self.loop)
@ -1187,6 +1191,13 @@ class QubeManagerTest(unittest.TestCase):
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)
if additional_timeout:
(done, pending) = self.loop.run_until_complete(
asyncio.wait({future1, future2}, timeout=timeout,
return_when=asyncio.FIRST_COMPLETED))
(done, pending) = self.loop.run_until_complete(
asyncio.wait(pending, timeout=additional_timeout))
else:
(done, pending) = self.loop.run_until_complete(
asyncio.wait({future1, future2}, timeout=timeout))
@ -1275,6 +1286,7 @@ class QubeManagerTest(unittest.TestCase):
column = self.dialog.qubes_model.columns_indices.index(column_name)
return model.index(row, column).data(role)
class QubeManagerThreadTest(unittest.TestCase):
def test_01_startvm_thread(self):
vm = unittest.mock.Mock(spec=['start'])