Skip to content

Commit 1a2ce72

Browse files
committed
Convert tests to use stdlib's AsyncMock()
asynctest doesn't work with Python 3.8+, but AsyncMock() and few other parts are available in the standard library already. See Martiusweb/asynctest#144 and Martiusweb/asynctest#126
1 parent fce4685 commit 1a2ce72

File tree

5 files changed

+9
-21
lines changed

5 files changed

+9
-21
lines changed

ci/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ mock
99
lxml
1010
PyYAML
1111
xcffib
12-
asynctest
1312
tqdm
1413
pyxdg

qubesadmin/tests/tools/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,5 @@ def readuntil(self, delim):
8080
self.current_event = rest
8181
return data + delim
8282

83-
@asyncio.coroutine
8483
def __call__(self, vm=None):
8584
return self, (lambda: None)

qubesadmin/tests/tools/qvm_backup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import unittest.mock as mock
2323

2424
import asyncio
25-
import asynctest
2625

2726
import qubesadmin.tests
2827
import qubesadmin.tests.tools
@@ -178,7 +177,7 @@ def test_012_main_existing_profile(self, mock_getpass, mock_input):
178177
None)] = \
179178
b'0\0'
180179
try:
181-
mock_events = asynctest.CoroutineMock()
180+
mock_events = mock.AsyncMock()
182181
patch = mock.patch(
183182
'qubesadmin.events.EventsDispatcher._get_events_reader',
184183
mock_events)

qubesadmin/tests/tools/qvm_shutdown.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# You should have received a copy of the GNU Lesser General Public License along
1919
# with this program; if not, see <http://www.gnu.org/licenses/>.
2020
import asyncio
21-
import asynctest
2221
import unittest.mock
2322

2423
import qubesadmin.tests
@@ -87,7 +86,7 @@ def test_010_wait(self):
8786
loop = asyncio.new_event_loop()
8887
asyncio.set_event_loop(loop)
8988

90-
mock_events = asynctest.CoroutineMock()
89+
mock_events = unittest.mock.AsyncMock()
9190
patch = unittest.mock.patch(
9291
'qubesadmin.events.EventsDispatcher._get_events_reader',
9392
mock_events)
@@ -118,7 +117,7 @@ def test_012_wait_all(self):
118117
loop = asyncio.new_event_loop()
119118
asyncio.set_event_loop(loop)
120119

121-
mock_events = asynctest.CoroutineMock()
120+
mock_events = unittest.mock.AsyncMock()
122121
patch = unittest.mock.patch(
123122
'qubesadmin.events.EventsDispatcher._get_events_reader',
124123
mock_events)
@@ -165,7 +164,7 @@ def test_015_wait_all_kill_timeout(self):
165164
loop = asyncio.new_event_loop()
166165
asyncio.set_event_loop(loop)
167166

168-
mock_events = asynctest.CoroutineMock()
167+
mock_events = unittest.mock.AsyncMock()
169168
patch = unittest.mock.patch(
170169
'qubesadmin.events.EventsDispatcher._get_events_reader',
171170
mock_events)

qubesadmin/tests/tools/qvm_start_daemon.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import re
2626
import asyncio
2727

28-
import asynctest
29-
3028
import qubesadmin.tests
3129
import qubesadmin.tools.qvm_start_daemon
3230
from qubesadmin.tools.qvm_start_daemon import GUI_DAEMON_OPTIONS
@@ -208,7 +206,7 @@ def test_013_common_args_guid_config(self):
208206
}
209207
''')
210208

211-
@asynctest.patch('asyncio.create_subprocess_exec')
209+
@unittest.mock.patch('asyncio.create_subprocess_exec')
212210
def test_020_start_gui_for_vm(self, proc_mock):
213211
loop = asyncio.new_event_loop()
214212
asyncio.set_event_loop(loop)
@@ -243,7 +241,7 @@ def test_020_start_gui_for_vm(self, proc_mock):
243241

244242
self.assertAllCalled()
245243

246-
@asynctest.patch('asyncio.create_subprocess_exec')
244+
@unittest.mock.patch('asyncio.create_subprocess_exec')
247245
def test_021_start_gui_for_vm_hvm(self, proc_mock):
248246
loop = asyncio.new_event_loop()
249247
asyncio.set_event_loop(loop)
@@ -316,7 +314,7 @@ def test_022_start_gui_for_vm_hvm_stubdom(self):
316314
pidfile.flush()
317315
self.addCleanup(pidfile.close)
318316

319-
patch_proc = asynctest.patch('asyncio.create_subprocess_exec')
317+
patch_proc = unittest.mock.patch('asyncio.create_subprocess_exec')
320318
patch_monitor_layout = unittest.mock.patch.object(
321319
qubesadmin.tools.qvm_start_daemon,
322320
'get_monitor_layout',
@@ -363,10 +361,7 @@ def test_030_start_gui_for_stubdomain(self):
363361
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui-emulated',
364362
None)] = \
365363
b'2\x00QubesFeatureNotFoundError\x00\x00Feature not set\x00'
366-
proc_mock = unittest.mock.Mock()
367-
with asynctest.patch('asyncio.create_subprocess_exec',
368-
lambda *args: self.mock_coroutine(proc_mock,
369-
*args)):
364+
with unittest.mock.patch('asyncio.create_subprocess_exec') as proc_mock:
370365
with unittest.mock.patch.object(self.launcher,
371366
'common_guid_args', lambda vm: []):
372367
loop.run_until_complete(self.launcher.start_gui_for_stubdomain(
@@ -397,10 +392,7 @@ def test_031_start_gui_for_stubdomain_forced(self):
397392
('test-vm', 'admin.vm.feature.CheckWithTemplate', 'gui-emulated',
398393
None)] = \
399394
b'0\x001'
400-
proc_mock = unittest.mock.Mock()
401-
with asynctest.patch('asyncio.create_subprocess_exec',
402-
lambda *args: self.mock_coroutine(proc_mock,
403-
*args)):
395+
with unittest.mock.patch('asyncio.create_subprocess_exec') as proc_mock:
404396
with unittest.mock.patch.object(self.launcher,
405397
'common_guid_args', lambda vm: []):
406398
loop.run_until_complete(self.launcher.start_gui_for_stubdomain(

0 commit comments

Comments
 (0)