Skip to content
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

Make testing's patched_subscriber_recv interruptible #57

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion posttroll/testing.py
mraspaud marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""Testing utilities."""
from contextlib import contextmanager


@contextmanager
def patched_subscriber_recv(messages):
"""Patch the Subscriber object to return given messages."""
from unittest import mock
with mock.patch("posttroll.subscriber.Subscriber.recv", mock.Mock(return_value=messages)):

def interuptible_recv(self):
"""Yield message until the subscriber is closed."""
for msg in messages:
if self._loop is False:
break
yield msg

with mock.patch("posttroll.subscriber.Subscriber.recv", interuptible_recv):
yield

@contextmanager
Expand Down