11681: Return native str type from KeepLocator.__str__() and Collection.portable_data...
authorTom Clegg <tom@curoverse.com>
Thu, 11 May 2017 19:37:32 +0000 (15:37 -0400)
committerTom Clegg <tom@curoverse.com>
Thu, 11 May 2017 19:37:32 +0000 (15:37 -0400)
sdk/python/arvados/collection.py
sdk/python/arvados/keep.py
sdk/python/tests/test_collections.py
sdk/python/tests/test_keep_locator.py

index 1f5067360d0589351733ac44c1ae4462d3de867c..d4f24047d22d3116f50382ed615f88c945590c38 100644 (file)
@@ -360,7 +360,7 @@ class CollectionWriter(CollectionBase):
 
     def portable_data_hash(self):
         stripped = self.stripped_manifest().encode()
-        return hashlib.md5(stripped).hexdigest() + '+' + str(len(stripped))
+        return '{}+{}'.format(hashlib.md5(stripped).hexdigest(), len(stripped))
 
     def manifest_text(self):
         self.finish_current_stream()
index b0413ebf92a06985591685c54e567b890f6827b1..4b5aa754c2ba3e41a81a2a6a54cb4b7c45dddc61 100644 (file)
@@ -1,6 +1,7 @@
 from __future__ import absolute_import
 from __future__ import division
 from future import standard_library
+from future.utils import native_str
 standard_library.install_aliases()
 from builtins import next
 from builtins import str
@@ -73,8 +74,9 @@ class KeepLocator(object):
 
     def __str__(self):
         return '+'.join(
-            str(s) for s in [self.md5sum, self.size,
-                             self.permission_hint()] + self.hints
+            native_str(s)
+            for s in [self.md5sum, self.size,
+                      self.permission_hint()] + self.hints
             if s is not None)
 
     def stripped(self):
index 77ec7bb0fa70800233a0002a6641fbd6a12942b7..b40ba579085e3f7a2f43856b6b3d7f0ae80b12c9 100644 (file)
@@ -55,6 +55,10 @@ class ArvadosCollectionsTest(run_test_server.TestCaseWithServers,
         cw.finish()
         return cw.portable_data_hash()
 
+    def test_pdh_is_native_str(self):
+        pdh = self.write_foo_bar_baz()
+        self.assertEqual(type(''), type(pdh))
+
     def test_keep_local_store(self):
         self.assertEqual(self.keep_client.put(b'foo'), 'acbd18db4cc2f85cedef654fccc4a4d8+3', 'wrong md5 hash from Keep.put')
         self.assertEqual(self.keep_client.get('acbd18db4cc2f85cedef654fccc4a4d8+3'), b'foo', 'wrong data from Keep.get')
index 9b9c4b6ab324f185a471c781f7d4d9a80157a140..4c3d920f7bda2e19a23c49e54983bcf5335fa4be 100644 (file)
@@ -63,6 +63,11 @@ class ArvadosKeepLocatorTest(unittest.TestCase):
             locator = '+'.join((base,) + loc_hints)
             self.assertEqual(locator, str(KeepLocator(locator)))
 
+    def test_str_type(self):
+        base = next(self.base_locators(1))
+        locator = KeepLocator(base)
+        self.assertEqual(type(''), type(locator.__str__()))
+
     def test_expiry_passed(self):
         base = next(self.base_locators(1))
         signature = next(self.signatures(1))