From b7eca976b5e5cbfec7fa6c80db9247c79664eae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 3 Aug 2020 03:40:54 +0200 Subject: [PATCH] tests: use asynctest some more Instead of hoping normal Mock will work (which does not on Python 3.8). --- qubesadmin/tests/tools/qvm_backup.py | 7 +++++-- qubesadmin/tests/tools/qvm_shutdown.py | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_backup.py b/qubesadmin/tests/tools/qvm_backup.py index cc2b5d6..20634df 100644 --- a/qubesadmin/tests/tools/qvm_backup.py +++ b/qubesadmin/tests/tools/qvm_backup.py @@ -22,6 +22,7 @@ import os import unittest.mock as mock import asyncio +import asynctest import qubesadmin.tests import qubesadmin.tests.tools @@ -177,9 +178,11 @@ class TC_00_qvm_backup(qubesadmin.tests.QubesTestCase): None)] = \ b'0\0' try: + mock_events = asynctest.CoroutineMock() patch = mock.patch( - 'qubesadmin.events.EventsDispatcher._get_events_reader') - mock_events = patch.start() + 'qubesadmin.events.EventsDispatcher._get_events_reader', + mock_events) + patch.start() self.addCleanup(patch.stop) mock_events.side_effect = qubesadmin.tests.tools.MockEventsReader([ b'1\0\0connection-established\0\0', diff --git a/qubesadmin/tests/tools/qvm_shutdown.py b/qubesadmin/tests/tools/qvm_shutdown.py index c7dc732..963a303 100644 --- a/qubesadmin/tests/tools/qvm_shutdown.py +++ b/qubesadmin/tests/tools/qvm_shutdown.py @@ -18,7 +18,9 @@ # You should have received a copy of the GNU Lesser General Public License along # with this program; if not, see . import asyncio +import asynctest import unittest.mock + import qubesadmin.tests import qubesadmin.tests.tools import qubesadmin.tools.qvm_shutdown @@ -85,9 +87,11 @@ class TC_00_qvm_shutdown(qubesadmin.tests.QubesTestCase): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) + mock_events = asynctest.CoroutineMock() patch = unittest.mock.patch( - 'qubesadmin.events.EventsDispatcher._get_events_reader') - mock_events = patch.start() + 'qubesadmin.events.EventsDispatcher._get_events_reader', + mock_events) + patch.start() self.addCleanup(patch.stop) mock_events.side_effect = qubesadmin.tests.tools.MockEventsReader([ b'1\0\0connection-established\0\0', @@ -114,9 +118,11 @@ class TC_00_qvm_shutdown(qubesadmin.tests.QubesTestCase): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) + mock_events = asynctest.CoroutineMock() patch = unittest.mock.patch( - 'qubesadmin.events.EventsDispatcher._get_events_reader') - mock_events = patch.start() + 'qubesadmin.events.EventsDispatcher._get_events_reader', + mock_events) + patch.start() self.addCleanup(patch.stop) mock_events.side_effect = qubesadmin.tests.tools.MockEventsReader([ b'1\0\0connection-established\0\0', @@ -159,9 +165,11 @@ class TC_00_qvm_shutdown(qubesadmin.tests.QubesTestCase): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) + mock_events = asynctest.CoroutineMock() patch = unittest.mock.patch( - 'qubesadmin.events.EventsDispatcher._get_events_reader') - mock_events = patch.start() + 'qubesadmin.events.EventsDispatcher._get_events_reader', + mock_events) + patch.start() self.addCleanup(patch.stop) mock_events.side_effect = qubesadmin.tests.tools.MockEventsReader([ b'1\0\0connection-established\0\0',