From 77043fb6e214d5e6e3967121f9890254ebe2be95 Mon Sep 17 00:00:00 2001
From: Tianzi Cai <tianzih@outlook.com>
Date: Fri, 10 Aug 2018 16:01:02 -0700
Subject: [PATCH] Updated google-cloud-pubsub to version 0.35
 [(#1624)](https://github.com/GoogleCloudPlatform/python-docs-samples/issues/1624)

* Updated library version

* Rewrote test for publish with error handler

* Custom _publish function in test prints no 'Attributes'
---
 samples/snippets/publisher_test.py  | 21 ++++++++++++++++++++-
 samples/snippets/requirements.txt   |  2 +-
 samples/snippets/subscriber.py      |  2 +-
 samples/snippets/subscriber_test.py |  1 -
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/samples/snippets/publisher_test.py b/samples/snippets/publisher_test.py
index 2eda09c6c..cdb4d0e0e 100644
--- a/samples/snippets/publisher_test.py
+++ b/samples/snippets/publisher_test.py
@@ -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
@@ -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 _():
@@ -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
diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt
index c74eb4e3c..23ed91dd2 100644
--- a/samples/snippets/requirements.txt
+++ b/samples/snippets/requirements.txt
@@ -1 +1 @@
-google-cloud-pubsub==0.33.0
+google-cloud-pubsub==0.35.0
diff --git a/samples/snippets/subscriber.py b/samples/snippets/subscriber.py
index 34f2301d8..46bb51188 100644
--- a/samples/snippets/subscriber.py
+++ b/samples/snippets/subscriber.py
@@ -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.
diff --git a/samples/snippets/subscriber_test.py b/samples/snippets/subscriber_test.py
index f04373ae8..adbc44e84 100644
--- a/samples/snippets/subscriber_test.py
+++ b/samples/snippets/subscriber_test.py
@@ -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