Repository: incubator-beam
Updated Branches:
  refs/heads/python-sdk 127e763c1 -> 450b64754


fixup! updates an error message and adds a test for error path.


Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/04c650f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/04c650f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/04c650f8

Branch: refs/heads/python-sdk
Commit: 04c650f88b661b6af056eaf4d16795b180a3df8c
Parents: d8a76a5
Author: Chamikara Jayalath <[email protected]>
Authored: Mon Aug 8 16:33:43 2016 -0700
Committer: Chamikara Jayalath <[email protected]>
Committed: Mon Aug 8 16:35:25 2016 -0700

----------------------------------------------------------------------
 sdks/python/apache_beam/io/fileio.py     |  4 ++--
 sdks/python/apache_beam/io/gcsio_test.py | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/04c650f8/sdks/python/apache_beam/io/fileio.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/io/fileio.py 
b/sdks/python/apache_beam/io/fileio.py
index ecacb9f..9b98a43 100644
--- a/sdks/python/apache_beam/io/fileio.py
+++ b/sdks/python/apache_beam/io/fileio.py
@@ -533,8 +533,8 @@ class FileSink(iobase.Sink):
         try:
           exists = channel_factory.exists(final_name)
         except Exception as exists_e:  # pylint: disable=broad-except
-          logging.warning('Exception when invoking channel_factory.exists(): '
-                          '%s', exists_e)
+          logging.warning('Exception when checking if file %s exists: '
+                          '%s', final_name, exists_e)
           # Returning original exception after logging the exception from
           # exists() call.
           return (None, e)

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/04c650f8/sdks/python/apache_beam/io/gcsio_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/apache_beam/io/gcsio_test.py 
b/sdks/python/apache_beam/io/gcsio_test.py
index b909fdd..99c99b3 100644
--- a/sdks/python/apache_beam/io/gcsio_test.py
+++ b/sdks/python/apache_beam/io/gcsio_test.py
@@ -29,6 +29,7 @@ from apitools.base.py.exceptions import HttpError
 from apache_beam.internal.clients import storage
 
 from apache_beam.io import gcsio
+from mock import patch
 
 
 class FakeGcsClient(object):
@@ -197,6 +198,18 @@ class TestGCSIO(unittest.TestCase):
     self.assertFalse(self.gcs.exists(file_name + 'xyz'))
     self.assertTrue(self.gcs.exists(file_name))
 
+  @patch.object(FakeGcsObjects, 'Get')
+  def test_exists_failure(self, mock_get):
+    # Raising an error other than 404. Raising 404 is a valid failure for
+    # exists() call.
+    mock_get.side_effect = HttpError({'status':400}, None, None)
+    file_name = 'gs://gcsio-test/dummy_file'
+    file_size = 1234
+    self._insert_random_file(self.client, file_name, file_size)
+    with self.assertRaises(HttpError) as cm:
+      self.gcs.exists(file_name)
+    self.assertEquals(400, cm.exception.status_code)
+
   def test_size(self):
     file_name = 'gs://gcsio-test/dummy_file'
     file_size = 1234

Reply via email to