Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
25e115ec
Commit
25e115ec
authored
Sep 29, 2019
by
Lisa Roach
Committed by
GitHub
Sep 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-38161: Removes _AwaitEvent from AsyncMock. (GH-16443)
parent
fb4ae152
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2 additions
and
39 deletions
+2
-39
Lib/unittest/mock.py
Lib/unittest/mock.py
+0
-36
Lib/unittest/test/testmock/testasync.py
Lib/unittest/test/testmock/testasync.py
+1
-3
Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst
...S.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst
+1
-0
No files found.
Lib/unittest/mock.py
View file @
25e115ec
...
...
@@ -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
Lib/unittest/test/testmock/testasync.py
View file @
25e115ec
...
...
@@ -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
())
...
...
@@ -212,7 +211,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
...
...
Misc/NEWS.d/next/Library/2019-09-27-16-31-28.bpo-38161.zehai1.rst
0 → 100644
View file @
25e115ec
Removes _AwaitEvent from AsyncMock.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment