diff options
author | Tim Burke <tim.burke@gmail.com> | 2020-06-17 21:05:03 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2020-06-17 21:05:25 -0700 |
commit | 22d1f3a39a9b23a62f443c2bd8ab9639c1b5a669 (patch) | |
tree | aafa1ecfada33cc69706171426b52c7ccc827af2 | |
parent | b63d9a3e96663753f643df41a420b1228210f9fa (diff) | |
download | python-swiftclient-22d1f3a39a9b23a62f443c2bd8ab9639c1b5a669.tar.gz |
Clean up some warnings
Change-Id: Iae149533d04c7b173c4ef88fb775f5fe13c16466
-rw-r--r-- | swiftclient/utils.py | 7 | ||||
-rw-r--r-- | test/unit/test_utils.py | 52 |
2 files changed, 31 insertions, 28 deletions
diff --git a/swiftclient/utils.py b/swiftclient/utils.py index 9e43237..656acad 100644 --- a/swiftclient/utils.py +++ b/swiftclient/utils.py @@ -14,7 +14,10 @@ # limitations under the License. """Miscellaneous utility functions for use with Swift.""" from calendar import timegm -import collections +try: + from collections.abc import Mapping +except ImportError: + from collections import Mapping import gzip import hashlib import hmac @@ -218,7 +221,7 @@ def parse_api_response(headers, body): def split_request_headers(options, prefix=''): headers = {} - if isinstance(options, collections.Mapping): + if isinstance(options, Mapping): options = options.items() for item in options: if isinstance(item, six.string_types): diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 97abc44..cbee82b 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -521,15 +521,15 @@ class TestLengthWrapper(unittest.TestCase): with tempfile.NamedTemporaryFile(mode='wb') as f: f.write(b'a' * 100) f.flush() - contents = open(f.name, 'rb') - data = u.LengthWrapper(contents, 42, True) - s = b'a' * 42 - read_data = b''.join(iter(data.read, '')) + with open(f.name, 'rb') as contents: + data = u.LengthWrapper(contents, 42, True) + s = b'a' * 42 + read_data = b''.join(iter(data.read, '')) - self.assertEqual(42, len(data)) - self.assertEqual(42, len(read_data)) - self.assertEqual(s, read_data) - self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) + self.assertEqual(42, len(data)) + self.assertEqual(42, len(read_data)) + self.assertEqual(s, read_data) + self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) def test_segmented_file(self): with tempfile.NamedTemporaryFile(mode='wb') as f: @@ -539,24 +539,24 @@ class TestLengthWrapper(unittest.TestCase): f.write((c * segment_length).encode()) f.flush() for i, c in enumerate(segments): - contents = open(f.name, 'rb') - contents.seek(i * segment_length) - data = u.LengthWrapper(contents, segment_length, True) - read_data = b''.join(iter(data.read, '')) - s = (c * segment_length).encode() - - self.assertEqual(segment_length, len(data)) - self.assertEqual(segment_length, len(read_data)) - self.assertEqual(s, read_data) - self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) - - data.reset() - self.assertEqual(md5().hexdigest(), data.get_md5sum()) - read_data = b''.join(iter(data.read, '')) - self.assertEqual(segment_length, len(data)) - self.assertEqual(segment_length, len(read_data)) - self.assertEqual(s, read_data) - self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) + with open(f.name, 'rb') as contents: + contents.seek(i * segment_length) + data = u.LengthWrapper(contents, segment_length, True) + read_data = b''.join(iter(data.read, '')) + s = (c * segment_length).encode() + + self.assertEqual(segment_length, len(data)) + self.assertEqual(segment_length, len(read_data)) + self.assertEqual(s, read_data) + self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) + + data.reset() + self.assertEqual(md5().hexdigest(), data.get_md5sum()) + read_data = b''.join(iter(data.read, '')) + self.assertEqual(segment_length, len(data)) + self.assertEqual(segment_length, len(read_data)) + self.assertEqual(s, read_data) + self.assertEqual(md5(s).hexdigest(), data.get_md5sum()) class TestGroupers(unittest.TestCase): |