Skip to content

Commit 57581be

Browse files
Updated google-cloud-pubsub to version 0.35 [(#1624)](GoogleCloudPlatform/python-docs-samples#1624)
* Updated library version * Rewrote test for publish with error handler * Custom _publish function in test prints no 'Attributes'
1 parent 2b6e80f commit 57581be

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

samples/snippets/publisher_test.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
# limitations under the License.
1414

1515
import os
16+
import time
1617

1718
from gcp_devrel.testing import eventually_consistent
1819
from google.cloud import pubsub_v1
20+
import mock
1921
import pytest
2022

2123
import publisher
@@ -43,6 +45,19 @@ def topic(client):
4345
yield topic_path
4446

4547

48+
def _make_sleep_patch():
49+
real_sleep = time.sleep
50+
51+
def new_sleep(period):
52+
if period == 60:
53+
real_sleep(5)
54+
raise RuntimeError('sigil')
55+
else:
56+
real_sleep(period)
57+
58+
return mock.patch('time.sleep', new=new_sleep)
59+
60+
4661
def test_list(client, topic, capsys):
4762
@eventually_consistent.call
4863
def _():
@@ -96,7 +111,11 @@ def test_publish_with_batch_settings(topic, capsys):
96111

97112

98113
def test_publish_with_error_handler(topic, capsys):
99-
publisher.publish_messages_with_error_handler(PROJECT, TOPIC)
114+
115+
with _make_sleep_patch():
116+
with pytest.raises(RuntimeError, match='sigil'):
117+
publisher.publish_messages_with_error_handler(
118+
PROJECT, TOPIC)
100119

101120
out, _ = capsys.readouterr()
102121
assert 'Published' in out

samples/snippets/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-pubsub==0.33.0
1+
google-cloud-pubsub==0.35.0

samples/snippets/subscriber.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def receive_messages_with_flow_control(project, subscription_name):
191191
project, subscription_name)
192192

193193
def callback(message):
194-
print('Received message: {}'.format(message))
194+
print('Received message: {}'.format(message.data))
195195
message.ack()
196196

197197
# Limit the subscriber to only have ten outstanding messages at a time.

samples/snippets/subscriber_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def test_receive_with_custom_attributes(
171171

172172
out, _ = capsys.readouterr()
173173
assert 'Test message' in out
174-
assert 'Attributes' in out
175174
assert 'origin' in out
176175
assert 'python-sample' in out
177176

0 commit comments

Comments
 (0)