diff options
author | Lisa Roach <lisaroach14@gmail.com> | 2019-09-30 04:01:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-30 04:01:28 (GMT) |
commit | 25e115ec00b5f75e3589c9f21013c47c21e1753f (patch) | |
tree | 61ea44dac1f39cc313f562f6ef82dd00c33f3216 /Lib/unittest/mock.py | |
parent | fb4ae152a9930f0e00cae8b2807f534058cf341a (diff) | |
download | cpython-25e115ec00b5f75e3589c9f21013c47c21e1753f.zip cpython-25e115ec00b5f75e3589c9f21013c47c21e1753f.tar.gz cpython-25e115ec00b5f75e3589c9f21013c47c21e1753f.tar.bz2 |
bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443)
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r-- | Lib/unittest/mock.py | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 27aa3bc..e797d2f 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 @@ -2116,7 +2115,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') @@ -2130,7 +2128,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() @@ -2159,7 +2156,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() @@ -2890,35 +2886,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 |