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

Updated google-cloud-pubsub to version 0.35 #1624

Merged
merged 3 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion pubsub/cloud-client/publisher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
# limitations under the License.

import os
import time

from gcp_devrel.testing import eventually_consistent
from google.cloud import pubsub_v1
import mock
import pytest

import publisher
Expand Down Expand Up @@ -43,6 +45,19 @@ def topic(client):
yield topic_path


def _make_sleep_patch():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the monkeypatch fixture built in to pytest. The reason is that that fixture will automatically clean up any patched functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, I see you are using this in a context manager, which has the same effect. Nevermind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh that's good to know!

real_sleep = time.sleep

def new_sleep(period):
if period == 60:
real_sleep(5)
raise RuntimeError('sigil')
else:
real_sleep(period)

return mock.patch('time.sleep', new=new_sleep)


def test_list(client, topic, capsys):
@eventually_consistent.call
def _():
Expand Down Expand Up @@ -96,7 +111,11 @@ def test_publish_with_batch_settings(topic, capsys):


def test_publish_with_error_handler(topic, capsys):
publisher.publish_messages_with_error_handler(PROJECT, TOPIC)

with _make_sleep_patch():
with pytest.raises(RuntimeError, match='sigil'):
publisher.publish_messages_with_error_handler(
PROJECT, TOPIC)

out, _ = capsys.readouterr()
assert 'Published' in out
Expand Down
2 changes: 1 addition & 1 deletion pubsub/cloud-client/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-pubsub==0.33.0
google-cloud-pubsub==0.35.0
2 changes: 1 addition & 1 deletion pubsub/cloud-client/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def receive_messages_with_flow_control(project, subscription_name):
project, subscription_name)

def callback(message):
print('Received message: {}'.format(message))
print('Received message: {}'.format(message.data))
message.ack()

# Limit the subscriber to only have ten outstanding messages at a time.
Expand Down
1 change: 0 additions & 1 deletion pubsub/cloud-client/subscriber_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def test_receive_with_custom_attributes(

out, _ = capsys.readouterr()
assert 'Test message' in out
assert 'Attributes' in out
assert 'origin' in out
assert 'python-sample' in out

Expand Down