From 22823f610671650c6f385c5b4afb229e1094009c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Fri, 14 Aug 2020 12:38:21 +0200 Subject: [PATCH] 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. --- qubesmanager/qube_manager.py | 1 + qubesmanager/tests/test_qube_manager.py | 28 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 71363e2..0fdcf3f 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -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: diff --git a/qubesmanager/tests/test_qube_manager.py b/qubesmanager/tests/test_qube_manager.py index 562abc4..1efaf02 100644 --- a/qubesmanager/tests/test_qube_manager.py +++ b/qubesmanager/tests/test_qube_manager.py @@ -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,8 +1191,15 @@ class QubeManagerTest(unittest.TestCase): stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - (done, pending) = self.loop.run_until_complete( - asyncio.wait({future1, future2}, timeout=timeout)) + 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)) for task in pending: with contextlib.suppress(asyncio.CancelledError): @@ -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'])