Skip to content

Commit

Permalink
Updated google-cloud-pubsub to version 0.35 [(#1624)](GoogleCloudPlat…
Browse files Browse the repository at this point in the history
…form/python-docs-samples#1624)

* Updated library version

* Rewrote test for publish with error handler

* Custom _publish function in test prints no 'Attributes'
  • Loading branch information
anguillanneuf authored and plamut committed Jul 10, 2020
1 parent 604cbcf commit 77043fb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
21 changes: 20 additions & 1 deletion samples/snippets/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():
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 samples/snippets/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 samples/snippets/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 samples/snippets/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

0 comments on commit 77043fb

Please sign in to comment.