summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/testmock/testasync.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/unittest/test/testmock/testasync.py')
-rw-r--r--Lib/unittest/test/testmock/testasync.py32
1 files changed, 30 insertions, 2 deletions
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py
index 5502342..87f3cfc 100644
--- a/Lib/unittest/test/testmock/testasync.py
+++ b/Lib/unittest/test/testmock/testasync.py
@@ -2,8 +2,8 @@ import asyncio
import inspect
import unittest
-from unittest.mock import (call, AsyncMock, patch, MagicMock, create_autospec,
- _AwaitEvent)
+from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock,
+ create_autospec, _AwaitEvent)
def tearDownModule():
@@ -192,6 +192,10 @@ class AsyncAutospecTest(unittest.TestCase):
spec.assert_awaited_with(1, 2, c=3)
spec.assert_awaited()
+ with self.assertRaises(AssertionError):
+ spec.assert_any_await(e=1)
+
+
def test_patch_with_autospec(self):
async def test_async():
@@ -607,6 +611,30 @@ class AsyncMockAssert(unittest.TestCase):
asyncio.run(self._runnable_test('SomethingElse'))
self.mock.assert_has_awaits(calls)
+ def test_awaits_asserts_with_any(self):
+ class Foo:
+ def __eq__(self, other): pass
+
+ asyncio.run(self._runnable_test(Foo(), 1))
+
+ self.mock.assert_has_awaits([call(ANY, 1)])
+ self.mock.assert_awaited_with(ANY, 1)
+ self.mock.assert_any_await(ANY, 1)
+
+ def test_awaits_asserts_with_spec_and_any(self):
+ class Foo:
+ def __eq__(self, other): pass
+
+ mock_with_spec = AsyncMock(spec=Foo)
+
+ async def _custom_mock_runnable_test(*args):
+ await mock_with_spec(*args)
+
+ asyncio.run(_custom_mock_runnable_test(Foo(), 1))
+ mock_with_spec.assert_has_awaits([call(ANY, 1)])
+ mock_with_spec.assert_awaited_with(ANY, 1)
+ mock_with_spec.assert_any_await(ANY, 1)
+
def test_assert_has_awaits_ordered(self):
calls = [call('NormalFoo'), call('baz')]
with self.assertRaises(AssertionError):