E501 Line too long.
MODIFY
test/test_collections.py
test/test_collections.py
@@ -160,7 +160,8 @@ class TestHTTPHeaderDict(unittest.TestCase):
self.assertEqual(len(h), len(set(teststr)))
def test_create_from_list(self):
- h = HTTPHeaderDict([('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')])
+ headers = [('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')]
+ h = HTTPHeaderDict(headers)
self.assertEqual(len(h), 3)
self.assertTrue('ab' in h)
clist = h.getlist('cookie')
@@ -169,7 +170,8 @@ class TestHTTPHeaderDict(unittest.TestCase):
self.assertEqual(clist[-1], 'E')
def test_create_from_headerdict(self):
- org = HTTPHeaderDict([('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')])
+ headers = [('ab', 'A'), ('cd', 'B'), ('cookie', 'C'), ('cookie', 'D'), ('cookie', 'E')]
+ org = HTTPHeaderDict(headers)
h = HTTPHeaderDict(org)
self.assertEqual(len(h), 3)
self.assertTrue('ab' in h)
@@ -299,7 +301,9 @@ class TestHTTPHeaderDict(unittest.TestCase):
def test_dict_conversion(self):
# Also tested in connectionpool, needs to preserve case
- hdict = {'Content-Length': '0', 'Content-type': 'text/plain', 'Server': 'TornadoServer/1.2.3'}
+ hdict = {'Content-Length': '0',
+ 'Content-type': 'text/plain',
+ 'Server': 'TornadoServer/1.2.3'}
h = dict(HTTPHeaderDict(hdict).items())
self.assertEqual(hdict, h)
self.assertEqual(hdict, dict(HTTPHeaderDict(hdict)))

MODIFY
test/test_connectionpool.py
test/test_connectionpool.py
@@ -322,7 +322,8 @@ class TestConnectionPool(unittest.TestCase):
self.assertEqual(initial_pool_size, new_pool_size)
def test_release_conn_param_is_respected_after_http_error_retry(self):
- """For successful ```urlopen(release_conn=False)```, the connection isn't released, even after a retry.
+ """For successful ```urlopen(release_conn=False)```,
+ the connection isn't released, even after a retry.
This is a regression test for issue #651 [1], where the connection
would be released if the initial request failed, even if a retry

MODIFY
test/test_filepost.py
test/test_filepost.py
@@ -112,7 +112,9 @@ class TestMultipartEncoding(unittest.TestCase):
'multipart/form-data; boundary=' + str(BOUNDARY))
def test_request_fields(self):
- fields = [RequestField('k', b'v', filename='somefile.txt', headers={'Content-Type': 'image/jpeg'})]
+ fields = [RequestField('k', b'v',
+ filename='somefile.txt',
+ headers={'Content-Type': 'image/jpeg'})]
encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
expected = (b'--' + b(BOUNDARY) + b'\r\n'

MODIFY
test/test_retry.py
test/test_retry.py
@@ -187,7 +187,8 @@ class RetryTest(unittest.TestCase):
def test_error_message(self):
retry = Retry(total=0)
try:
- retry = retry.increment(method='GET', error=ReadTimeoutError(None, "/", "read timed out"))
+ retry = retry.increment(method='GET',
+ error=ReadTimeoutError(None, "/", "read timed out"))
raise AssertionError("Should have raised a MaxRetryError")
except MaxRetryError as e:
assert 'Caused by redirect' not in str(e)
@@ -229,16 +230,21 @@ class RetryTest(unittest.TestCase):
self.assertEqual(retry.history, tuple())
connection_error = ConnectTimeoutError('conntimeout')
retry = retry.increment('GET', '/test1', None, connection_error)
- self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),))
+ history = (RequestHistory('GET', '/test1', connection_error, None, None),)
+ self.assertEqual(retry.history, history)
+
read_error = ReadTimeoutError(None, "/test2", "read timed out")
retry = retry.increment('POST', '/test2', None, read_error)
- self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
- RequestHistory('POST', '/test2', read_error, None, None)))
+ history = (RequestHistory('GET', '/test1', connection_error, None, None),
+ RequestHistory('POST', '/test2', read_error, None, None))
+ self.assertEqual(retry.history, history)
+
response = HTTPResponse(status=500)
retry = retry.increment('GET', '/test3', response, None)
- self.assertEqual(retry.history, (RequestHistory('GET', '/test1', connection_error, None, None),
+ history = (RequestHistory('GET', '/test1', connection_error, None, None),
RequestHistory('POST', '/test2', read_error, None, None),
- RequestHistory('GET', '/test3', None, 500, None)))
+ RequestHistory('GET', '/test3', None, 500, None))
+ self.assertEqual(retry.history, history)
def test_retry_method_not_in_whitelist(self):
error = ReadTimeoutError(None, "/", "read timed out")

MODIFY
test/test_util.py
test/test_util.py
@@ -83,8 +83,10 @@ class TestUtil(unittest.TestCase):
'http://[2a00:1450:4001:c01::67]:80/test': ('http', '[2a00:1450:4001:c01::67]', 80),
# More IPv6 from http://www.ietf.org/rfc/rfc2732.txt
- 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:8000/index.html': ('http', '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', 8000),
- 'http://[1080:0:0:0:8:800:200c:417a]/index.html': ('http', '[1080:0:0:0:8:800:200c:417a]', None),
+ 'http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:8000/index.html': (
+ 'http', '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', 8000),
+ 'http://[1080:0:0:0:8:800:200c:417a]/index.html': (
+ 'http', '[1080:0:0:0:8:800:200c:417a]', None),
'http://[3ffe:2a00:100:7031::1]': ('http', '[3ffe:2a00:100:7031::1]', None),
'http://[1080::8:800:200c:417a]/foo': ('http', '[1080::8:800:200c:417a]', None),
'http://[::192.9.5.5]/ipng': ('http', '[::192.9.5.5]', None),
@@ -119,8 +121,10 @@ class TestUtil(unittest.TestCase):
'173.194.35.7': ('http', '173.194.35.7', None),
'HTTP://173.194.35.7': ('http', '173.194.35.7', None),
'HTTP://[2a00:1450:4001:c01::67]:80/test': ('http', '[2a00:1450:4001:c01::67]', 80),
- 'HTTP://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000/index.html': ('http', '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', 8000),
- 'HTTPS://[1080:0:0:0:8:800:200c:417A]/index.html': ('https', '[1080:0:0:0:8:800:200c:417a]', None),
+ 'HTTP://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:8000/index.html': (
+ 'http', '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]', 8000),
+ 'HTTPS://[1080:0:0:0:8:800:200c:417A]/index.html': (
+ 'https', '[1080:0:0:0:8:800:200c:417a]', None),
}
for url, expected_host in url_host_map.items():
returned_host = get_host(url)
@@ -130,7 +134,8 @@ class TestUtil(unittest.TestCase):
"""Assert parse_url normalizes the scheme/host, and only the scheme/host"""
test_urls = [
('HTTP://GOOGLE.COM/MAIL/', 'http://google.com/MAIL/'),
- ('HTTP://JeremyCline:Hunter2@Example.com:8080/', 'http://JeremyCline:Hunter2@example.com:8080/'),
+ ('HTTP://JeremyCline:Hunter2@Example.com:8080/',
+ 'http://JeremyCline:Hunter2@example.com:8080/'),
('HTTPS://Example.Com/?Key=Value', 'https://example.com/?Key=Value'),
('Https://Example.Com/#Fragment', 'https://example.com/#Fragment'),
]
@@ -153,7 +158,9 @@ class TestUtil(unittest.TestCase):
'#?/!google.com/?foo#bar': Url(path='', fragment='?/!google.com/?foo#bar'),
'/foo': Url(path='/foo'),
'/foo?bar=baz': Url(path='/foo', query='bar=baz'),
- '/foo?bar=baz#banana?apple/orange': Url(path='/foo', query='bar=baz', fragment='banana?apple/orange'),
+ '/foo?bar=baz#banana?apple/orange': Url(path='/foo',
+ query='bar=baz',
+ fragment='banana?apple/orange'),
# Port
'http://google.com/': Url('http', host='google.com', path='/'),
@@ -163,7 +170,10 @@ class TestUtil(unittest.TestCase):
# Auth
'http://foo:bar@localhost/': Url('http', auth='foo:bar', host='localhost', path='/'),
'http://foo@localhost/': Url('http', auth='foo', host='localhost', path='/'),
- 'http://foo:bar@baz@localhost/': Url('http', auth='foo:bar@baz', host='localhost', path='/'),
+ 'http://foo:bar@baz@localhost/': Url('http',
+ auth='foo:bar@baz',
+ host='localhost',
+ path='/'),
'http://@': Url('http', host=None, auth='')
}
@@ -179,7 +189,8 @@ class TestUtil(unittest.TestCase):
}
def test_parse_url(self):
- for url, expected_Url in chain(self.parse_url_host_map.items(), self.non_round_tripping_parse_url_host_map.items()):
+ for url, expected_Url in chain(self.parse_url_host_map.items(),
+ self.non_round_tripping_parse_url_host_map.items()):
returned_Url = parse_url(url)
self.assertEqual(returned_Url, expected_Url)

MODIFY
test/with_dummyserver/test_connectionpool.py
test/with_dummyserver/test_connectionpool.py
@@ -114,7 +114,8 @@ class TestConnectionPoolTimeouts(SocketDummyServerTestCase):
delta = time.time() - now
block_event.set() # Release request
- self.assertTrue(delta < LONG_TIMEOUT, "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT")
+ message = "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT"
+ self.assertTrue(delta < LONG_TIMEOUT, message)
pool._put_conn(conn)
wait_for_socket(ready_event)
@@ -122,7 +123,8 @@ class TestConnectionPoolTimeouts(SocketDummyServerTestCase):
self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/', timeout=timeout)
delta = time.time() - now
- self.assertTrue(delta < LONG_TIMEOUT, "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT")
+ message = "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT"
+ self.assertTrue(delta < LONG_TIMEOUT, message)
block_event.set() # Release request
# Timeout int/float passed directly to request and _make_request should
@@ -134,7 +136,10 @@ class TestConnectionPoolTimeouts(SocketDummyServerTestCase):
wait_for_socket(ready_event)
conn = pool._new_conn()
# FIXME: This assert flakes sometimes. Not sure why.
- self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/', timeout=SHORT_TIMEOUT)
+ self.assertRaises(ReadTimeoutError,
+ pool._make_request,
+ conn, 'GET', '/',
+ timeout=SHORT_TIMEOUT)
block_event.set() # Release request
def test_connect_timeout(self):
@@ -155,7 +160,10 @@ class TestConnectionPoolTimeouts(SocketDummyServerTestCase):
big_timeout = Timeout(read=LONG_TIMEOUT, connect=LONG_TIMEOUT)
pool = HTTPConnectionPool(host, port, timeout=big_timeout, retries=False)
conn = pool._get_conn()
- self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url, timeout=timeout)
+ self.assertRaises(ConnectTimeoutError,
+ pool._make_request,
+ conn, 'GET', url,
+ timeout=timeout)
pool._put_conn(conn)
self.assertRaises(ConnectTimeoutError, pool.request, 'GET', url, timeout=timeout)
@@ -280,8 +288,8 @@ class TestConnectionPool(HTTPDummyServerTestCase):
def test_nagle(self):
""" Test that connections have TCP_NODELAY turned on """
- # This test needs to be here in order to be run. socket.create_connection actually tries to
- # connect to the host provided so we need a dummyserver to be running.
+ # This test needs to be here in order to be run. socket.create_connection actually tries
+ # to connect to the host provided so we need a dummyserver to be running.
pool = HTTPConnectionPool(self.host, self.port)
conn = pool._get_conn()
pool._make_request(conn, 'GET', '/')
@@ -302,8 +310,8 @@ class TestConnectionPool(HTTPDummyServerTestCase):
def test_disable_default_socket_options(self):
"""Test that passing None disables all socket options."""
- # This test needs to be here in order to be run. socket.create_connection actually tries to
- # connect to the host provided so we need a dummyserver to be running.
+ # This test needs to be here in order to be run. socket.create_connection actually tries
+ # to connect to the host provided so we need a dummyserver to be running.
pool = HTTPConnectionPool(self.host, self.port, socket_options=None)
s = pool._new_conn()._new_conn()
using_nagle = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY) == 0
@@ -312,8 +320,8 @@ class TestConnectionPool(HTTPDummyServerTestCase):
def test_defaults_are_applied(self):
"""Test that modifying the default socket options works."""
- # This test needs to be here in order to be run. socket.create_connection actually tries to
- # connect to the host provided so we need a dummyserver to be running.
+ # This test needs to be here in order to be run. socket.create_connection actually tries
+ # to connect to the host provided so we need a dummyserver to be running.
pool = HTTPConnectionPool(self.host, self.port)
# Get the HTTPConnection instance
conn = pool._new_conn()
@@ -547,7 +555,10 @@ class TestConnectionPool(HTTPDummyServerTestCase):
req2_data = {'count': 'b' * payload_size}
resp2_data = encode_multipart_formdata(req2_data, boundary=boundary)[0]
- r1 = pool.request('POST', '/echo', fields=req_data, multipart_boundary=boundary, preload_content=False)
+ r1 = pool.request('POST', '/echo',
+ fields=req_data,
+ multipart_boundary=boundary,
+ preload_content=False)
self.assertEqual(r1.read(first_chunk), resp_data[:first_chunk])
@@ -628,7 +639,9 @@ class TestConnectionPool(HTTPDummyServerTestCase):
for addr in INVALID_SOURCE_ADDRESSES:
pool = HTTPConnectionPool(self.host, self.port, source_address=addr, retries=False)
# FIXME: This assert flakes sometimes. Not sure why.
- self.assertRaises(NewConnectionError, pool.request, 'GET', '/source_address?{0}'.format(addr))
+ self.assertRaises(NewConnectionError,
+ pool.request,
+ 'GET', '/source_address?{0}'.format(addr))
def test_stream_keepalive(self):
x = 2
@@ -676,7 +689,10 @@ class TestConnectionPool(HTTPDummyServerTestCase):
'GET', '/redirect',
fields={'target': '/'}, release_conn=False, retries=0)
- r = http.request('GET', '/redirect', fields={'target': '/'}, release_conn=False, retries=1)
+ r = http.request('GET', '/redirect',
+ fields={'target': '/'},
+ release_conn=False,
+ retries=1)
r.release_conn()
# the pool should still contain poolsize elements
@@ -781,15 +797,19 @@ class TestRetry(HTTPDummyServerTestCase):
headers=headers, retries=retry)
self.assertEqual(resp.status, 200)
self.assertEqual(resp.retries.total, 1)
- self.assertEqual(resp.retries.history, (RequestHistory('GET', '/successful_retry', None, 418, None),))
+ self.assertEqual(resp.retries.history,
+ (RequestHistory('GET', '/successful_retry', None, 418, None),))
def test_retry_redirect_history(self):
resp = self.pool.request('GET', '/redirect', fields={'target': '/'})
self.assertEqual(resp.status, 200)
- self.assertEqual(resp.retries.history, (RequestHistory('GET', '/redirect?target=%2F', None, 303, '/'),))
+ self.assertEqual(resp.retries.history,
+ (RequestHistory('GET', '/redirect?target=%2F', None, 303, '/'),))
def test_multi_redirect_history(self):
- r = self.pool.request('GET', '/multi_redirect', fields={'redirect_codes': '303,302,200'}, redirect=False)
+ r = self.pool.request('GET', '/multi_redirect',
+ fields={'redirect_codes': '303,302,200'},
+ redirect=False)
self.assertEqual(r.status, 303)
self.assertEqual(r.retries.history, tuple())
@@ -797,13 +817,14 @@ class TestRetry(HTTPDummyServerTestCase):
fields={'redirect_codes': '303,302,301,307,302,200'})
self.assertEqual(r.status, 200)
self.assertEqual(r.data, b'Done redirecting')
- self.assertEqual([(request_history.status, request_history.redirect_location) for request_history in r.retries.history], [
- (303, '/multi_redirect?redirect_codes=302,301,307,302,200'),
+
+ expected = [(303, '/multi_redirect?redirect_codes=302,301,307,302,200'),
(302, '/multi_redirect?redirect_codes=301,307,302,200'),
(301, '/multi_redirect?redirect_codes=307,302,200'),
(307, '/multi_redirect?redirect_codes=302,200'),
- (302, '/multi_redirect?redirect_codes=200')
- ])
+ (302, '/multi_redirect?redirect_codes=200')]
+ actual = [(history.status, history.redirect_location) for history in r.retries.history]
+ self.assertEqual(actual, expected)
class TestRetryAfter(HTTPDummyServerTestCase):

MODIFY
test/with_dummyserver/test_poolmanager.py
test/with_dummyserver/test_poolmanager.py
@@ -42,7 +42,8 @@ class TestPoolManager(HTTPDummyServerTestCase):
self.assertEqual(r.status, 303)
r = http.request('GET', '%s/redirect' % self.base_url,
- fields={'target': '%s/redirect?target=%s/' % (self.base_url, self.base_url)})
+ fields={'target': '%s/redirect?target=%s/' % (self.base_url,
+ self.base_url)})
self.assertEqual(r.status, 200)
self.assertEqual(r.data, b'Dummy server!')
@@ -86,7 +87,8 @@ class TestPoolManager(HTTPDummyServerTestCase):
try:
r = http.request('GET', '%s/redirect' % self.base_url,
- fields={'target': '%s/redirect?target=%s/' % (self.base_url, self.base_url)},
+ fields={'target': '%s/redirect?target=%s/' % (self.base_url,
+ self.base_url)},
retries=1)
self.fail("Failed to raise MaxRetryError exception, returned %r" % r.status)
except MaxRetryError:
@@ -94,7 +96,8 @@ class TestPoolManager(HTTPDummyServerTestCase):
try:
r = http.request('GET', '%s/redirect' % self.base_url,
- fields={'target': '%s/redirect?target=%s/' % (self.base_url, self.base_url)},
+ fields={'target': '%s/redirect?target=%s/' % (self.base_url,
+ self.base_url)},
retries=Retry(total=None, redirect=1))
self.fail("Failed to raise MaxRetryError exception, returned %r" % r.status)
except MaxRetryError:
@@ -104,7 +107,8 @@ class TestPoolManager(HTTPDummyServerTestCase):
http = PoolManager()
r = http.request('GET', '%s/redirect' % self.base_url,
- fields={'target': '%s/redirect?target=%s/' % (self.base_url, self.base_url)},
+ fields={'target': '%s/redirect?target=%s/' % (self.base_url,
+ self.base_url)},
retries=Retry(total=None, redirect=1, raise_on_redirect=False))
self.assertEqual(r.status, 303)
@@ -125,7 +129,9 @@ class TestPoolManager(HTTPDummyServerTestCase):
# raise explicitly
r = http.request('GET', '%s/status' % self.base_url,
fields={'status': '500 Internal Server Error'},
- retries=Retry(total=1, status_forcelist=range(500, 600), raise_on_status=True))
+ retries=Retry(total=1,
+ status_forcelist=range(500, 600),
+ raise_on_status=True))
self.fail("Failed to raise MaxRetryError exception, returned %r" % r.status)
except MaxRetryError:
pass
@@ -133,7 +139,9 @@ class TestPoolManager(HTTPDummyServerTestCase):
# don't raise
r = http.request('GET', '%s/status' % self.base_url,
fields={'status': '500 Internal Server Error'},
- retries=Retry(total=1, status_forcelist=range(500, 600), raise_on_status=False))
+ retries=Retry(total=1,
+ status_forcelist=range(500, 600),
+ raise_on_status=False))
self.assertEqual(r.status, 500)

MODIFY
test/with_dummyserver/test_socketlevel.py
test/with_dummyserver/test_socketlevel.py
@@ -143,7 +143,11 @@ class TestSocketClosing(SocketDummyServerTestCase):
sock.close()
self._start_server(socket_handler)
- http = HTTPConnectionPool(self.host, self.port, timeout=0.001, retries=False, maxsize=3, block=True)
+ http = HTTPConnectionPool(self.host, self.port,
+ timeout=0.001,
+ retries=False,
+ maxsize=3,
+ block=True)
try:
self.assertRaises(ReadTimeoutError, http.request, 'GET', '/', release_conn=False)
@@ -524,7 +528,8 @@ class TestSocketClosing(SocketDummyServerTestCase):
self.fail("Timed out waiting for connection close")
def test_release_conn_param_is_respected_after_timeout_retry(self):
- """For successful ```urlopen(release_conn=False)```, the connection isn't released, even after a retry.
+ """For successful ```urlopen(release_conn=False)```,
+ the connection isn't released, even after a retry.
This test allows a retry: one request fails, the next request succeeds.

E501 Line too long.