diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/test_multithreading.py | 14 | ||||
-rw-r--r-- | test/unit/test_service.py | 4 | ||||
-rw-r--r-- | test/unit/test_shell.py | 4 | ||||
-rw-r--r-- | test/unit/test_swiftclient.py | 136 | ||||
-rw-r--r-- | test/unit/test_utils.py | 70 |
5 files changed, 114 insertions, 114 deletions
diff --git a/test/unit/test_multithreading.py b/test/unit/test_multithreading.py index ee9e7cc..d51bfb7 100644 --- a/test/unit/test_multithreading.py +++ b/test/unit/test_multithreading.py @@ -192,18 +192,18 @@ class TestOutputManager(unittest.TestCase): thread_manager.print_msg('one-argument') thread_manager.print_msg('one %s, %d fish', 'fish', 88) thread_manager.error('I have %d problems, but a %s is not one', - 99, u'\u062A\u062A') + 99, '\u062A\u062A') thread_manager.print_msg('some\n%s\nover the %r', 'where', - u'\u062A\u062A') + '\u062A\u062A') thread_manager.error('one-error-argument') thread_manager.error('Sometimes\n%.1f%% just\ndoes not\nwork!', 3.14159) thread_manager.print_raw( - u'some raw bytes: \u062A\u062A'.encode('utf-8')) + 'some raw bytes: \u062A\u062A'.encode('utf-8')) thread_manager.print_items([ ('key', 'value'), - ('object', u'O\u0308bject'), + ('object', 'O\u0308bject'), ]) thread_manager.print_raw(b'\xffugly\xffraw') @@ -222,13 +222,13 @@ class TestOutputManager(unittest.TestCase): 'one fish, 88 fish\n', 'some\n', 'where\n', over_the, - u'some raw bytes: \u062a\u062a', + 'some raw bytes: \u062a\u062a', ' key: value\n', - u' object: O\u0308bject\n' + ' object: O\u0308bject\n' ]).encode('utf8') + b'\xffugly\xffraw', out_stream.getvalue()) self.assertEqual(''.join([ - u'I have 99 problems, but a \u062A\u062A is not one\n', + 'I have 99 problems, but a \u062A\u062A is not one\n', 'one-error-argument\n', 'Sometimes\n', '3.1% just\n', 'does not\n', 'work!\n' ]), err_stream.getvalue().decode('utf8')) diff --git a/test/unit/test_service.py b/test/unit/test_service.py index 9f3a2a2..0ad5378 100644 --- a/test/unit/test_service.py +++ b/test/unit/test_service.py @@ -564,7 +564,7 @@ class TestServiceDelete(_TestServiceBase): stub_headers, json.dumps(stub_resp).encode('utf8')) obj_list = ['x%02d' % i for i in range(100)] expected = [{ - 'action': u'bulk_delete', + 'action': 'bulk_delete', 'attempts': 0, 'container': 'c', 'objects': list(objs), @@ -594,7 +594,7 @@ class TestServiceDelete(_TestServiceBase): obj_list = [SwiftDeleteObject('x%02d' % i, options={'version_id': i}) for i in range(100)] expected = [{ - 'action': u'delete_object', + 'action': 'delete_object', 'attempts': 0, 'container': 'c', 'object': obj.object_name, diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py index adf3776..eb70a92 100644 --- a/test/unit/test_shell.py +++ b/test/unit/test_shell.py @@ -400,7 +400,7 @@ class TestShell(unittest.TestCase): def test_list_json(self, connection): connection.return_value.get_account.side_effect = [ [None, [{'name': 'container'}]], - [None, [{'name': u'\u263A', 'some-custom-key': 'and value'}]], + [None, [{'name': '\u263A', 'some-custom-key': 'and value'}]], [None, []], ] @@ -412,7 +412,7 @@ class TestShell(unittest.TestCase): connection.return_value.get_account.assert_has_calls(calls) listing = [{'name': 'container'}, - {'name': u'\u263A', 'some-custom-key': 'and value'}] + {'name': '\u263A', 'some-custom-key': 'and value'}] expected = json.dumps(listing, sort_keys=True, indent=2) + '\n' self.assertEqual(output.out, expected) diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py index 673f65f..3b59166 100644 --- a/test/unit/test_swiftclient.py +++ b/test/unit/test_swiftclient.py @@ -163,34 +163,34 @@ class TestHttpHelpers(MockHttpTest): self.assertEqual('bytes%FF', c.quote(value)) value = 'native string' self.assertEqual('native%20string', c.quote(value)) - value = u'unicode string' + value = 'unicode string' self.assertEqual('unicode%20string', c.quote(value)) - value = u'unicode:\xe9\u20ac' + value = 'unicode:\xe9\u20ac' self.assertEqual('unicode%3A%C3%A9%E2%82%AC', c.quote(value)) def test_parse_header_string(self): value = b'bytes' - self.assertEqual(u'bytes', c.parse_header_string(value)) - value = u'unicode:\xe9\u20ac' - self.assertEqual(u'unicode:\xe9\u20ac', c.parse_header_string(value)) + self.assertEqual('bytes', c.parse_header_string(value)) + value = 'unicode:\xe9\u20ac' + self.assertEqual('unicode:\xe9\u20ac', c.parse_header_string(value)) value = 'native%20string' - self.assertEqual(u'native string', c.parse_header_string(value)) + self.assertEqual('native string', c.parse_header_string(value)) value = b'encoded%20bytes%E2%82%AC' - self.assertEqual(u'encoded bytes\u20ac', c.parse_header_string(value)) + self.assertEqual('encoded bytes\u20ac', c.parse_header_string(value)) value = 'encoded%20unicode%E2%82%AC' - self.assertEqual(u'encoded unicode\u20ac', + self.assertEqual('encoded unicode\u20ac', c.parse_header_string(value)) value = b'bad%20bytes%ff%E2%82%AC' - self.assertEqual(u'bad%20bytes%ff%E2%82%AC', + self.assertEqual('bad%20bytes%ff%E2%82%AC', c.parse_header_string(value)) - value = u'bad%20unicode%ff\u20ac' - self.assertEqual(u'bad%20unicode%ff\u20ac', + value = 'bad%20unicode%ff\u20ac' + self.assertEqual('bad%20unicode%ff\u20ac', c.parse_header_string(value)) value = b'really%20bad\xffbytes' - self.assertEqual(u'really%2520bad%FFbytes', + self.assertEqual('really%2520bad%FFbytes', c.parse_header_string(value)) def test_http_connection(self): @@ -205,9 +205,9 @@ class TestHttpHelpers(MockHttpTest): def test_encode_meta_headers(self): headers = {'abc': '123', - u'x-container-meta-\u0394': 123, - u'x-account-meta-\u0394': 12.3, - u'x-object-meta-\u0394': True} + 'x-container-meta-\u0394': 123, + 'x-account-meta-\u0394': 12.3, + 'x-object-meta-\u0394': True} r = swiftclient.encode_meta_headers(headers) @@ -1111,9 +1111,9 @@ class TestGetObject(MockHttpTest): conn = c.http_connection('http://www.test.com') headers, data = c.get_object('url_is_irrelevant', 'TOKEN', 'container', 'object', http_conn=conn) - self.assertEqual(u't\xe9st', headers.get('x-utf-8-header', '')) - self.assertEqual(u'%ff', headers.get('x-non-utf-8-header', '')) - self.assertEqual(u'%FF', headers.get('x-binary-header', '')) + self.assertEqual('t\xe9st', headers.get('x-utf-8-header', '')) + self.assertEqual('%ff', headers.get('x-non-utf-8-header', '')) + self.assertEqual('%FF', headers.get('x-binary-header', '')) def test_chunk_size_read_method(self): conn = c.Connection('http://auth.url/', 'some_user', 'some_key') @@ -1338,14 +1338,14 @@ class TestPutObject(MockHttpTest): ]) def test_unicode_ok(self): - conn = c.http_connection(u'http://www.test.com/') - mock_file = io.StringIO(u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91') - args = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + conn = c.http_connection('http://www.test.com/') + mock_file = io.StringIO('\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91') + args = ('\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', mock_file) - text = u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + text = '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' headers = {'X-Header1': text, 'X-2': '1', 'X-3': "{'a': 'b'}", 'a-b': '.x:yz mn:fg:lp'} @@ -1410,7 +1410,7 @@ class TestPutObject(MockHttpTest): def test_raw_upload(self): # Raw upload happens when content_length is passed to put_object - conn = c.http_connection(u'http://www.test.com/') + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1432,7 +1432,7 @@ class TestPutObject(MockHttpTest): def test_chunk_upload(self): # Chunked upload happens when no content_length is passed to put_object - conn = c.http_connection(u'http://www.test.com/') + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1457,7 +1457,7 @@ class TestPutObject(MockHttpTest): def data(): for chunk in ('foo', '', 'bar'): yield chunk - conn = c.http_connection(u'http://www.test.com/') + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1524,7 +1524,7 @@ class TestPutObject(MockHttpTest): self.assertEqual(etag, contents.get_md5sum()) def test_params(self): - conn = c.http_connection(u'http://www.test.com/') + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1535,8 +1535,8 @@ class TestPutObject(MockHttpTest): self.assertEqual(request_header['etag'], b'1234-5678') self.assertEqual(request_header['content-type'], b'text/plain') - def test_no_content_type_requests(self): - conn = c.http_connection(u'http://www.test.com/') + def test_no_content_type(self): + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1546,7 +1546,7 @@ class TestPutObject(MockHttpTest): self.assertNotIn('content-type', request_header) def test_content_type_in_headers(self): - conn = c.http_connection(u'http://www.test.com/') + conn = c.http_connection('http://www.test.com/') resp = MockHttpResponse(status=200) conn[1].getresponse = resp.fake_response conn[1]._request = resp._fake_request @@ -1586,12 +1586,12 @@ class TestPostObject(MockHttpTest): }) def test_unicode_ok(self): - conn = c.http_connection(u'http://www.test.com/') - args = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91') - text = u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + conn = c.http_connection('http://www.test.com/') + args = ('\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91', + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91') + text = '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' headers = {'X-Header1': text, b'X-Header2': 'value', 'X-2': '1', 'X-3': "{'a': 'b'}", 'a-b': '.x:yz mn:kl:qr', @@ -1890,66 +1890,66 @@ class TestGetCapabilities(MockHttpTest): class TestHTTPConnection(MockHttpTest): def test_bad_url_scheme(self): - url = u'www.test.com' + url = 'www.test.com' with self.assertRaises(c.ClientException) as exc_context: c.http_connection(url) exc = exc_context.exception - expected = u'Unsupported scheme "" in url "www.test.com"' + expected = 'Unsupported scheme "" in url "www.test.com"' self.assertEqual(expected, str(exc)) - url = u'://www.test.com' + url = '://www.test.com' with self.assertRaises(c.ClientException) as exc_context: c.http_connection(url) exc = exc_context.exception - expected = u'Unsupported scheme "" in url "://www.test.com"' + expected = 'Unsupported scheme "" in url "://www.test.com"' self.assertEqual(expected, str(exc)) - url = u'blah://www.test.com' + url = 'blah://www.test.com' with self.assertRaises(c.ClientException) as exc_context: c.http_connection(url) exc = exc_context.exception - expected = u'Unsupported scheme "blah" in url "blah://www.test.com"' + expected = 'Unsupported scheme "blah" in url "blah://www.test.com"' self.assertEqual(expected, str(exc)) def test_ok_url_scheme(self): for scheme in ('http', 'https', 'HTTP', 'HTTPS'): - url = u'%s://www.test.com' % scheme + url = '%s://www.test.com' % scheme parsed_url, conn = c.http_connection(url) self.assertEqual(scheme.lower(), parsed_url.scheme) - self.assertEqual(u'%s://www.test.com' % scheme, conn.url) + self.assertEqual('%s://www.test.com' % scheme, conn.url) def test_ok_proxy(self): - conn = c.http_connection(u'http://www.test.com/', + conn = c.http_connection('http://www.test.com/', proxy='http://localhost:8080') self.assertEqual(conn[1].requests_args['proxies']['http'], 'http://localhost:8080') def test_bad_proxy(self): try: - c.http_connection(u'http://www.test.com/', proxy='localhost:8080') + c.http_connection('http://www.test.com/', proxy='localhost:8080') except c.ClientException as e: self.assertEqual(e.msg, "Proxy's missing scheme") def test_cacert(self): - conn = c.http_connection(u'http://www.test.com/', + conn = c.http_connection('http://www.test.com/', cacert='/dev/urandom') self.assertEqual(conn[1].requests_args['verify'], '/dev/urandom') def test_insecure(self): - conn = c.http_connection(u'http://www.test.com/', insecure=True) + conn = c.http_connection('http://www.test.com/', insecure=True) self.assertEqual(conn[1].requests_args['verify'], False) def test_cert(self): - conn = c.http_connection(u'http://www.test.com/', cert='minnie') + conn = c.http_connection('http://www.test.com/', cert='minnie') self.assertEqual(conn[1].requests_args['cert'], 'minnie') def test_cert_key(self): conn = c.http_connection( - u'http://www.test.com/', cert='minnie', cert_key='mickey') + 'http://www.test.com/', cert='minnie', cert_key='mickey') self.assertEqual(conn[1].requests_args['cert'], ('minnie', 'mickey')) def test_response_connection_released(self): - _parsed_url, conn = c.http_connection(u'http://www.test.com/') + _parsed_url, conn = c.http_connection('http://www.test.com/') conn.resp = MockHttpResponse() conn.resp.raw = mock.Mock() conn.resp.raw.read.side_effect = ["Chunk", ""] @@ -1962,7 +1962,7 @@ class TestHTTPConnection(MockHttpTest): def test_response_headers(self): '''Test latin1-encoded headers. ''' - _, conn = c.http_connection(u'http://www.test.com/') + _, conn = c.http_connection('http://www.test.com/') conn.resp = MockHttpResponse( status=200, headers={ @@ -2860,7 +2860,7 @@ class TestLogging(MockHttpTest): def test_content_encoding_gzip_body_is_logged_decoded(self): buf = io.BytesIO() gz = gzip.GzipFile(fileobj=buf, mode='w') - data = {"test": u"\u2603"} + data = {"test": "\u2603"} decoded_body = json.dumps(data).encode('utf-8') gz.write(decoded_body) gz.close() @@ -2877,7 +2877,7 @@ class TestLogging(MockHttpTest): self.assertEqual(exc_context.exception.http_status, 500) # it will log the decoded body self.assertEqual([ - mock.call('REQ: %s', u'curl -i http://www.test.com/asdf/asdf ' + mock.call('REQ: %s', 'curl -i http://www.test.com/asdf/asdf ' '-X GET -H "X-Auth-Token: ..."'), mock.call('RESP STATUS: %s %s', 500, 'Fake'), mock.call('RESP HEADERS: %s', {'content-encoding': 'gzip'}), @@ -2888,9 +2888,9 @@ class TestLogging(MockHttpTest): with mock.patch('swiftclient.client.logger.debug') as mock_log: token_value = 'tkee96b40a8ca44fc5ad72ec5a7c90d9b' token_encoded = token_value.encode('utf8') - unicode_token_value = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' - u'\u5929\u7a7a\u4e2d\u7684\u4e4c') + unicode_token_value = ('\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + '\u5929\u7a7a\u4e2d\u7684\u4e4c') unicode_token_encoded = unicode_token_value.encode('utf8') set_cookie_value = 'X-Auth-Token=%s' % token_value set_cookie_encoded = set_cookie_value.encode('utf8') @@ -2914,8 +2914,8 @@ class TestLogging(MockHttpTest): out = [] for _, args, kwargs in mock_log.mock_calls: for arg in args: - out.append(u'%s' % arg) - output = u''.join(out) + out.append('%s' % arg) + output = ''.join(out) self.assertIn('X-Auth-Token', output) self.assertIn(token_value[:16] + '...', output) self.assertIn('X-Storage-Token', output) @@ -2930,9 +2930,9 @@ class TestLogging(MockHttpTest): with mock.patch('swiftclient.client.logger.debug') as mock_log: token_value = 'tkee96b40a8ca44fc5ad72ec5a7c90d9b' token_encoded = token_value.encode('utf8') - unicode_token_value = (u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' - u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' - u'\u5929\u7a7a\u4e2d\u7684\u4e4c') + unicode_token_value = ('\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + '\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91' + '\u5929\u7a7a\u4e2d\u7684\u4e4c') c.logger_settings['redact_sensitive_headers'] = False unicode_token_encoded = unicode_token_value.encode('utf8') c.http_log( @@ -2954,8 +2954,8 @@ class TestLogging(MockHttpTest): out = [] for _, args, kwargs in mock_log.mock_calls: for arg in args: - out.append(u'%s' % arg) - output = u''.join(out) + out.append('%s' % arg) + output = ''.join(out) self.assertIn('X-Auth-Token', output) self.assertIn(token_value, output) self.assertIn('X-Storage-Token', output) @@ -2963,12 +2963,12 @@ class TestLogging(MockHttpTest): @mock.patch('swiftclient.client.logger.debug') def test_unicode_path(self, mock_log): - path = u'http://swift/v1/AUTH_account-\u062a'.encode('utf-8') + path = 'http://swift/v1/AUTH_account-\u062a'.encode('utf-8') c.http_log(['GET', path], {}, MockHttpResponse(status=200, headers=[]), '') request_log_line = mock_log.mock_calls[0] self.assertEqual('REQ: %s', request_log_line[1][0]) - self.assertEqual(u'curl -i -X GET %s' % path.decode('utf-8'), + self.assertEqual('curl -i -X GET %s' % path.decode('utf-8'), request_log_line[1][1]) diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index 007b91e..3833154 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -304,7 +304,7 @@ class TestTempURL(unittest.TestCase): b'1400003600', b'2146636800') else: expected_url = self.expected_url.replace( - u'1400003600', u'2146636800') + '1400003600', '2146636800') url = u.generate_temp_url(self.url, 2146636800, self.key, self.method, absolute=True) self.assertEqual(url, expected_url) @@ -372,32 +372,32 @@ class TestTempURL(unittest.TestCase): class TestTempURLUnicodePathAndKey(TestTempURL): - url = u'/v1/\u00e4/c/\u00f3' - key = u'k\u00e9y' - expected_url = (u'%s?temp_url_sig=temp_url_signature' - u'&temp_url_expires=1400003600') % url - expected_body = u'\n'.join([ - u'GET', - u'1400003600', + url = '/v1/\u00e4/c/\u00f3' + key = 'k\u00e9y' + expected_url = ('%s?temp_url_sig=temp_url_signature' + '&temp_url_expires=1400003600') % url + expected_body = '\n'.join([ + 'GET', + '1400003600', url, ]).encode('utf-8') class TestTempURLUnicodePathBytesKey(TestTempURL): - url = u'/v1/\u00e4/c/\u00f3' - key = u'k\u00e9y'.encode('utf-8') - expected_url = (u'%s?temp_url_sig=temp_url_signature' - u'&temp_url_expires=1400003600') % url + url = '/v1/\u00e4/c/\u00f3' + key = 'k\u00e9y'.encode('utf-8') + expected_url = ('%s?temp_url_sig=temp_url_signature' + '&temp_url_expires=1400003600') % url expected_body = '\n'.join([ - u'GET', - u'1400003600', + 'GET', + '1400003600', url, ]).encode('utf-8') class TestTempURLBytesPathUnicodeKey(TestTempURL): - url = u'/v1/\u00e4/c/\u00f3'.encode('utf-8') - key = u'k\u00e9y' + url = '/v1/\u00e4/c/\u00f3'.encode('utf-8') + key = 'k\u00e9y' expected_url = url + (b'?temp_url_sig=temp_url_signature' b'&temp_url_expires=1400003600') expected_body = b'\n'.join([ @@ -408,8 +408,8 @@ class TestTempURLBytesPathUnicodeKey(TestTempURL): class TestTempURLBytesPathAndKey(TestTempURL): - url = u'/v1/\u00e4/c/\u00f3'.encode('utf-8') - key = u'k\u00e9y'.encode('utf-8') + url = '/v1/\u00e4/c/\u00f3'.encode('utf-8') + key = 'k\u00e9y'.encode('utf-8') expected_url = url + (b'?temp_url_sig=temp_url_signature' b'&temp_url_expires=1400003600') expected_body = b'\n'.join([ @@ -420,7 +420,7 @@ class TestTempURLBytesPathAndKey(TestTempURL): class TestTempURLBytesPathAndNonUtf8Key(TestTempURL): - url = u'/v1/\u00e4/c/\u00f3'.encode('utf-8') + url = '/v1/\u00e4/c/\u00f3'.encode('utf-8') key = b'k\xffy' expected_url = url + (b'?temp_url_sig=temp_url_signature' b'&temp_url_expires=1400003600') @@ -463,7 +463,7 @@ class TestReadableToIterable(unittest.TestCase): def test_unicode(self): # Check no errors are raised if unicode data is feed in. - unicode_data = u'abc' + unicode_data = 'abc' actual_md5sum = md5(unicode_data.encode()).hexdigest() chunk_size = 2 @@ -486,11 +486,11 @@ class TestReadableToIterable(unittest.TestCase): class TestLengthWrapper(unittest.TestCase): def test_stringio(self): - contents = io.StringIO(u'a' * 50 + u'b' * 50) + contents = io.StringIO('a' * 50 + 'b' * 50) contents.seek(22) data = u.LengthWrapper(contents, 42, True) - s = u'a' * 28 + u'b' * 14 - read_data = u''.join(iter(data.read, '')) + s = 'a' * 28 + 'b' * 14 + read_data = ''.join(iter(data.read, '')) self.assertEqual(42, len(data)) self.assertEqual(42, len(read_data)) @@ -500,7 +500,7 @@ class TestLengthWrapper(unittest.TestCase): data.reset() self.assertEqual(md5().hexdigest(), data.get_md5sum()) - read_data = u''.join(iter(data.read, '')) + read_data = ''.join(iter(data.read, '')) self.assertEqual(42, len(read_data)) self.assertEqual(s, read_data) self.assertEqual(md5(s.encode()).hexdigest(), data.get_md5sum()) @@ -591,12 +591,12 @@ class TestApiResponeParser(unittest.TestCase): def test_utf8_default(self): result = u.parse_api_response( - {}, u'{"test": "\u2603"}'.encode('utf8')) - self.assertEqual({'test': u'\u2603'}, result) + {}, '{"test": "\u2603"}'.encode('utf8')) + self.assertEqual({'test': '\u2603'}, result) result = u.parse_api_response( - {}, u'{"test": "\\u2603"}'.encode('utf8')) - self.assertEqual({'test': u'\u2603'}, result) + {}, '{"test": "\\u2603"}'.encode('utf8')) + self.assertEqual({'test': '\u2603'}, result) def test_bad_json(self): self.assertRaises(ValueError, u.parse_api_response, @@ -610,35 +610,35 @@ class TestApiResponeParser(unittest.TestCase): result = u.parse_api_response( {'content-type': 'application/json; charset=iso8859-1'}, b'{"t\xe9st": "\xff"}') - self.assertEqual({u't\xe9st': u'\xff'}, result) + self.assertEqual({'t\xe9st': '\xff'}, result) def test_gzipped_utf8(self): buf = io.BytesIO() gz = gzip.GzipFile(fileobj=buf, mode='w') - gz.write(u'{"test": "\u2603"}'.encode('utf8')) + gz.write('{"test": "\u2603"}'.encode('utf8')) gz.close() result = u.parse_api_response( {'content-encoding': 'gzip'}, buf.getvalue()) - self.assertEqual({'test': u'\u2603'}, result) + self.assertEqual({'test': '\u2603'}, result) class TestGetBody(unittest.TestCase): def test_not_gzipped(self): result = u.parse_api_response( - {}, u'{"test": "\\u2603"}'.encode('utf8')) - self.assertEqual({'test': u'\u2603'}, result) + {}, '{"test": "\\u2603"}'.encode('utf8')) + self.assertEqual({'test': '\u2603'}, result) def test_gzipped_body(self): buf = io.BytesIO() gz = gzip.GzipFile(fileobj=buf, mode='w') - gz.write(u'{"test": "\u2603"}'.encode('utf8')) + gz.write('{"test": "\u2603"}'.encode('utf8')) gz.close() result = u.parse_api_response( {'content-encoding': 'gzip'}, buf.getvalue()) - self.assertEqual({'test': u'\u2603'}, result) + self.assertEqual({'test': '\u2603'}, result) class JSONTracker: |