Skip to content

Commit 665e9cd

Browse files
fepitrepiotrbartman
authored andcommitted
tests: use AsyncMock
1 parent 371e584 commit 665e9cd

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

qubesusbproxy/tests.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from unittest.mock import Mock, AsyncMock
2828

2929
import jinja2
30-
3130
import qubes.tests.extra
3231

3332
core3 = False
@@ -723,11 +722,9 @@ def test_010_on_qdb_change_multiple_assignments_including_full(self):
723722
qubesusbproxy.core3ext.USBDevice(Port(back, "1-1", "usb"))
724723
)
725724

726-
self.ext.attach_and_notify = Mock()
725+
self.ext.attach_and_notify = AsyncMock()
727726
loop = asyncio.get_event_loop()
728-
with mock.patch("asyncio.wait"):
729-
with mock.patch("asyncio.ensure_future"):
730-
loop.run_until_complete(self.ext.on_domain_start(front, None))
727+
loop.run_until_complete(self.ext.on_domain_start(front, None))
731728
self.assertEqual(
732729
self.ext.attach_and_notify.call_args[0][1].options, {"pid": "did"}
733730
)
@@ -755,11 +752,9 @@ def test_011_on_qdb_change_multiple_assignments_port_vs_dev(self):
755752
qubesusbproxy.core3ext.USBDevice(Port(back, "1-1", "usb"))
756753
)
757754

758-
self.ext.attach_and_notify = Mock()
755+
self.ext.attach_and_notify = AsyncMock()
759756
loop = asyncio.get_event_loop()
760-
with mock.patch("asyncio.wait"):
761-
with mock.patch("asyncio.ensure_future"):
762-
loop.run_until_complete(self.ext.on_domain_start(front, None))
757+
loop.run_until_complete(self.ext.on_domain_start(front, None))
763758
self.assertEqual(
764759
self.ext.attach_and_notify.call_args[0][1].options, {"pid": "any"}
765760
)
@@ -790,11 +785,9 @@ def test_012_on_qdb_change_multiple_assignments_dev(self):
790785
qubesusbproxy.core3ext.USBDevice(Port(back, "1-2", "usb"))
791786
)
792787

793-
self.ext.attach_and_notify = Mock()
788+
self.ext.attach_and_notify = AsyncMock()
794789
loop = asyncio.get_event_loop()
795-
with mock.patch("asyncio.wait"):
796-
with mock.patch("asyncio.ensure_future"):
797-
loop.run_until_complete(self.ext.on_domain_start(front, None))
790+
loop.run_until_complete(self.ext.on_domain_start(front, None))
798791
self.assertEqual(
799792
self.ext.attach_and_notify.call_args[0][1].options, {"any": "did"}
800793
)
@@ -990,10 +983,9 @@ def test_023_on_startup_already_attached(self):
990983
front.devices["usb"]._assigned.append(assmnt)
991984
back.devices["usb"]._exposed.append(exp_dev)
992985

993-
self.ext.attach_and_notify = Mock()
986+
self.ext.attach_and_notify = AsyncMock()
994987
loop = asyncio.get_event_loop()
995-
with mock.patch("asyncio.ensure_future"):
996-
loop.run_until_complete(self.ext.on_domain_start(front, None))
988+
loop.run_until_complete(self.ext.on_domain_start(front, None))
997989
self.ext.attach_and_notify.assert_not_called()
998990

999991

0 commit comments

Comments
 (0)