libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 05/05: Fix Python 3 compatibility.
Date Tue, 28 May 2019 13:35:19 GMT
This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git

commit f40b2c4d2e6531cc4b52972b028f56b17f90cc27
Author: Tomaz Muraus <tomaz@tomaz.me>
AuthorDate: Tue May 28 15:34:51 2019 +0200

    Fix Python 3 compatibility.
---
 libcloud/test/storage/test_cloudfiles.py |  8 +++++++-
 libcloud/test/storage/test_s3.py         | 13 +++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/libcloud/test/storage/test_cloudfiles.py b/libcloud/test/storage/test_cloudfiles.py
index e3c6ff4..650cc53 100644
--- a/libcloud/test/storage/test_cloudfiles.py
+++ b/libcloud/test/storage/test_cloudfiles.py
@@ -33,6 +33,7 @@ from libcloud.utils.py3 import b
 from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlquote
 from libcloud.utils.py3 import StringIO
+from libcloud.utils.py3 import PY3
 from libcloud.utils.files import exhaust_iterator
 
 from libcloud.common.types import MalformedResponseError
@@ -392,7 +393,12 @@ class CloudFilesTests(unittest.TestCase):
                      container=container, meta_data=None,
                      driver=self.driver)
         result = self.driver.download_object_as_stream(obj=obj)
-        self.assertEqual(exhaust_iterator(result), 'a' * 1000)
+        result = exhaust_iterator(result)
+
+        if PY3:
+            result = result.decode('utf-8')
+
+        self.assertEqual(result, 'a' * 1000)
 
     def test_upload_object_success(self):
         def upload_file(self, object_name=None, content_type=None,
diff --git a/libcloud/test/storage/test_s3.py b/libcloud/test/storage/test_s3.py
index df31920..cc756fb 100644
--- a/libcloud/test/storage/test_s3.py
+++ b/libcloud/test/storage/test_s3.py
@@ -31,6 +31,7 @@ from libcloud.utils.py3 import httplib
 from libcloud.utils.py3 import urlparse
 from libcloud.utils.py3 import parse_qs
 from libcloud.utils.py3 import StringIO
+from libcloud.utils.py3 import PY3
 from libcloud.utils.files import exhaust_iterator
 
 from libcloud.common.types import InvalidCredsError
@@ -666,7 +667,10 @@ class S3Tests(unittest.TestCase):
         self.assertTrue(result)
 
     def test_download_object_as_stream_data_is_not_buffered_in_memory(self):
-        # If content is consumed and response.content attribute accessed execption
+        # Test case which verifies that response.response attribute is not accessed
+        # and as such, whole body response is not buffered into RAM
+
+        # If content is consumed and response.content attribute accessed exception
         # will be thrown and test will fail
         mock_response = Mock(name='mock response')
         mock_response.headers = {}
@@ -690,7 +694,12 @@ class S3Tests(unittest.TestCase):
                      driver=self.driver_type)
         destination_path = self._file_path
         result = self.driver.download_object_as_stream(obj=obj)
-        self.assertEqual(exhaust_iterator(result), 'a' * 1000)
+        result = exhaust_iterator(result)
+
+        if PY3:
+            result = result.decode('utf-8')
+
+        self.assertEqual(result, 'a' * 1000)
 
     def test_download_object_invalid_file_size(self):
         self.mock_response_klass.type = 'INVALID_SIZE'


Mime
View raw message