-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
[WIP] bpo-17013: Implement WaitableMock to create Mock objects that can wait until called #12818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
826a69e
aa73fbc
0f0482e
f51f5b7
a941ca1
3031310
c67715b
5b59f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2495,6 +2495,7 @@ class WaitableMock(MagicMock): | |
|
||
def __init__(self, *args, event_class=threading.Event, **kwargs): | ||
_safe_super(WaitableMock, self).__init__(*args, **kwargs) | ||
self._event_class = event_class | ||
self._event = event_class() | ||
self._expected_calls = defaultdict(lambda: event_class()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably simplify this to be just ‘defaultdict(event_class)’. Without the lambda. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed. Thanks 👍 |
||
|
||
|
@@ -2523,7 +2524,7 @@ def wait_until_called_with(self, *args, timeout=1.0): | |
`timeout` - time to wait for in seconds. Defaults to 1. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t have a great alternative, but feels a pity if users cannot wait for calls that had a timeout parameter as discussed in the issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I would wait if someone has a less conflicting name or perhaps receive |
||
""" | ||
if args: | ||
if args not in self.expected_calls: | ||
if args not in self._expected_calls: | ||
event = self._event_class() | ||
self._expected_calls[args] = event | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage self._event vs self._expected_calls which contains events is non obvious. Can add a comment to explain where each event is used and how.