-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from mraspaud/feature-testing-utilities
Add close methods for subscriber and publisher and testing utilities
- Loading branch information
Showing
6 changed files
with
130 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""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)): | ||
yield | ||
|
||
@contextmanager | ||
def patched_publisher(): | ||
"""Patch the Subscriber object to return given messages.""" | ||
from unittest import mock | ||
published = [] | ||
|
||
def fake_send(self, message): | ||
published.append(message) | ||
|
||
def noop(self, *args, **kwargs): | ||
pass | ||
|
||
with mock.patch.multiple("posttroll.publisher.Publisher", send=fake_send, start=noop, stop=noop): | ||
yield published |
Oops, something went wrong.