Skip to content

Commit

Permalink
Merge pull request #57 from mraspaud/feature-patched-receiver-interup…
Browse files Browse the repository at this point in the history
…tible

Make testing's patched_subscriber_recv  interruptible
  • Loading branch information
mraspaud authored Dec 4, 2023
2 parents 53398c7 + 3e33ecf commit 488aa17
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion posttroll/testing.py
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

0 comments on commit 488aa17

Please sign in to comment.