summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-30 04:23:33 (GMT)
committerLisa Roach <lisaroach14@gmail.com>2019-09-30 04:23:33 (GMT)
commit36e7e4aabb662e86e9dace1a6447492f45868654 (patch)
tree17d7463e7ca04101a18d24babdcf0e861f1b23eb
parentb76ab352405df105c2d459fc66ef8dc98e47b37c (diff)
downloadcpython-36e7e4aabb662e86e9dace1a6447492f45868654.zip
cpython-36e7e4aabb662e86e9dace1a6447492f45868654.tar.gz
cpython-36e7e4aabb662e86e9dace1a6447492f45868654.tar.bz2
bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443) (GH-16481)
-rw-r--r--Lib/unittest/mock.py36
-rw-r--r--Lib/unittest/test/testmock/testasync.py4
-rw-r--r--Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst1
3 files changed, 2 insertions, 39 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 8c542cf..5d32f88 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -246,7 +246,6 @@ def _setup_async_mock(mock):
mock.await_count = 0
mock.await_args = None
mock.await_args_list = _CallList()
- mock.awaited = _AwaitEvent(mock)
# Mock is not configured yet so the attributes are set
# to a function and then the corresponding mock helper function
@@ -2102,7 +2101,6 @@ class MagicProxy(Base):
class AsyncMockMixin(Base):
- awaited = _delegating_property('awaited')
await_count = _delegating_property('await_count')
await_args = _delegating_property('await_args')
await_args_list = _delegating_property('await_args_list')
@@ -2116,7 +2114,6 @@ class AsyncMockMixin(Base):
# It is set through __dict__ because when spec_set is True, this
# attribute is likely undefined.
self.__dict__['_is_coroutine'] = asyncio.coroutines._is_coroutine
- self.__dict__['_mock_awaited'] = _AwaitEvent(self)
self.__dict__['_mock_await_count'] = 0
self.__dict__['_mock_await_args'] = None
self.__dict__['_mock_await_args_list'] = _CallList()
@@ -2145,7 +2142,6 @@ class AsyncMockMixin(Base):
self.await_count += 1
self.await_args = _call
self.await_args_list.append(_call)
- await self.awaited._notify()
return await proxy()
@@ -2878,35 +2874,3 @@ class _AsyncIterator:
except StopIteration:
pass
raise StopAsyncIteration
-
-
-class _AwaitEvent:
- def __init__(self, mock):
- self._mock = mock
- self._condition = None
-
- async def _notify(self):
- condition = self._get_condition()
- try:
- await condition.acquire()
- condition.notify_all()
- finally:
- condition.release()
-
- def _get_condition(self):
- """
- Creation of condition is delayed, to minimize the chance of using the
- wrong loop.
- A user may create a mock with _AwaitEvent before selecting the
- execution loop. Requiring a user to delay creation is error-prone and
- inflexible. Instead, condition is created when user actually starts to
- use the mock.
- """
- # No synchronization is needed:
- # - asyncio is thread unsafe
- # - there are no awaits here, method will be executed without
- # switching asyncio context.
- if self._condition is None:
- self._condition = asyncio.Condition()
-
- return self._condition
diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py
index df5ac5e..ed8aefc 100644
--- a/Lib/unittest/test/testmock/testasync.py
+++ b/Lib/unittest/test/testmock/testasync.py
@@ -4,7 +4,7 @@ import re
import unittest
from unittest.mock import (ANY, call, AsyncMock, patch, MagicMock,
- create_autospec, _AwaitEvent, sentinel, _CallList)
+ create_autospec, sentinel, _CallList)
def tearDownModule():
@@ -178,7 +178,6 @@ class AsyncAutospecTest(unittest.TestCase):
self.assertEqual(spec.await_count, 0)
self.assertIsNone(spec.await_args)
self.assertEqual(spec.await_args_list, [])
- self.assertIsInstance(spec.awaited, _AwaitEvent)
spec.assert_not_awaited()
asyncio.run(main())
@@ -208,7 +207,6 @@ class AsyncAutospecTest(unittest.TestCase):
self.assertEqual(mock_method.await_count, 0)
self.assertEqual(mock_method.await_args_list, [])
self.assertIsNone(mock_method.await_args)
- self.assertIsInstance(mock_method.awaited, _AwaitEvent)
mock_method.assert_not_awaited()
await awaitable
diff --git a/Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst b/Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst
new file mode 100644
index 0000000..0077033
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst
@@ -0,0 +1 @@
+Removes _AwaitEvent from AsyncMock.