tests: use asynctest some more

Instead of hoping normal Mock will work (which does not on Python 3.8).
This commit is contained in:
Marek Marczykowski-Górecki 2020-08-03 03:40:54 +02:00
parent 3e1d36fe4a
commit b7eca976b5
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 19 additions and 8 deletions

View File

@ -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',

View File

@ -18,7 +18,9 @@
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.
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',