Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 12b4e6f

Browse files
committed
Fixup linting errors in test/test_http11.py.
1 parent 5d18737 commit 12b4e6f

File tree

1 file changed

+50
-18
lines changed

1 file changed

+50
-18
lines changed

test/test_http11.py

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_pycohttpparser_installs_correctly(self):
3333
import pycohttpparser
3434
else:
3535
with pytest.raises(ImportError):
36-
import pycohttpparser
36+
import pycohttpparser # noqa
3737

3838
assert True
3939

@@ -88,7 +88,9 @@ def test_initialization_proxy_with_inline_port(self):
8888
assert c.proxy_port == 8443
8989

9090
def test_initialization_proxy_with_separate_port(self):
91-
c = HTTP11Connection('httpbin.org', proxy_host='localhost', proxy_port=8443)
91+
c = HTTP11Connection(
92+
'httpbin.org', proxy_host='localhost', proxy_port=8443
93+
)
9294

9395
assert c.host == 'httpbin.org'
9496
assert c.port == 80
@@ -97,7 +99,9 @@ def test_initialization_proxy_with_separate_port(self):
9799
assert c.proxy_port == 8443
98100

99101
def test_initialization_with_ipv6_addresses_proxy_inline_port(self):
100-
c = HTTP11Connection('[abcd:dcba::1234]', proxy_host='[ffff:aaaa::1]:8443')
102+
c = HTTP11Connection(
103+
'[abcd:dcba::1234]', proxy_host='[ffff:aaaa::1]:8443'
104+
)
101105

102106
assert c.host == 'abcd:dcba::1234'
103107
assert c.port == 80
@@ -153,7 +157,7 @@ def test_iterable_header(self):
153157

154158
def test_invalid_header(self):
155159
c = HTTP11Connection('httpbin.org')
156-
c._sock = sock = DummySocket()
160+
c._sock = DummySocket()
157161

158162
with pytest.raises(ValueError):
159163
c.request('GET', '/get', headers=42)
@@ -208,6 +212,7 @@ def test_request_with_file_body(self):
208212
# file and monkeypatching out 'os.fstat'. This makes it look like a
209213
# real file.
210214
FstatRval = namedtuple('FstatRval', ['st_size'])
215+
211216
def fake_fstat(*args):
212217
return FstatRval(16)
213218

@@ -242,6 +247,7 @@ def fake_fstat(*args):
242247
def test_request_with_generator_body(self):
243248
c = HTTP11Connection('httpbin.org')
244249
c._sock = sock = DummySocket()
250+
245251
def body():
246252
yield b'hi'
247253
yield b'there'
@@ -326,7 +332,7 @@ def test_get_response(self):
326332
c = HTTP11Connection('httpbin.org')
327333
c._sock = sock = DummySocket()
328334

329-
sock._buffer= BytesIO(
335+
sock._buffer = BytesIO(
330336
b"HTTP/1.1 201 No Content\r\n"
331337
b"Connection: close\r\n"
332338
b"Server: Socket\r\n"
@@ -349,7 +355,7 @@ def test_response_short_reads(self):
349355
c = HTTP11Connection('httpbin.org')
350356
c._sock = sock = DummySocket()
351357

352-
sock._buffer= BytesIO(
358+
sock._buffer = BytesIO(
353359
b"HTTP/1.1 200 OK\r\n"
354360
b"Content-Length: 15\r\n"
355361
b"\r\n"
@@ -382,6 +388,7 @@ def test_request_with_file_body_in_text_mode(self):
382388
# file and monkeypatching out 'os.fstat'. This makes it look like a
383389
# real file.
384390
FstatRval = namedtuple('FstatRval', ['st_size'])
391+
385392
def fake_fstat(*args):
386393
return FstatRval(16)
387394

@@ -404,6 +411,7 @@ def fake_fstat(*args):
404411
def test_request_with_unicode_generator_body(self):
405412
c = HTTP11Connection('httpbin.org')
406413
c._sock = DummySocket()
414+
407415
def body():
408416
yield u'hi'
409417
yield u'there'
@@ -453,20 +461,34 @@ def test_exception_raised_for_illegal_body_type(self):
453461

454462
with pytest.raises(ValueError) as exc_info:
455463
body = 1234
456-
# content-length set so body type is set to BODY_FLAT. value doesn't matter
457-
c.request('GET', '/get', body=body, headers={'content-length': str(len(str(body)))})
458-
assert 'Request body must be a bytestring, a file-like object returning bytestrings ' \
459-
'or an iterable of bytestrings. Got: {}'.format(type(body)) in str(exc_info)
464+
# content-length set so body type is set to BODY_FLAT. value
465+
# doesn't matter
466+
c.request(
467+
'GET',
468+
'/get',
469+
body=body,
470+
headers={'content-length': str(len(str(body)))}
471+
)
472+
assert 'Request body must be a bytestring, a file-like object ' \
473+
'returning bytestrings or an iterable of bytestrings. ' \
474+
'Got: {}'.format(type(body)) in str(exc_info)
460475

461476
def test_exception_raised_for_illegal_elements_in_iterable_body(self):
462477
c = HTTP11Connection('httpbin.org')
463478

464479
rogue_element = 123
465480
with pytest.raises(ValueError) as exc_info:
466-
# content-length set so body type is set to BODY_FLAT. value doesn't matter
481+
# content-length set so body type is set to BODY_FLAT. value
482+
# doesn't matter
467483
body = ['legal1', 'legal2', rogue_element]
468-
c.request('GET', '/get', body=body, headers={'content-length': str(len(map(str, body)))})
469-
assert 'Elements in iterable body must be bytestrings. Illegal element: {}'.format(rogue_element)\
484+
c.request(
485+
'GET',
486+
'/get',
487+
body=body,
488+
headers={'content-length': str(len(map(str, body)))}
489+
)
490+
assert 'Elements in iterable body must be bytestrings. Illegal ' \
491+
'element: {}'.format(rogue_element) \
470492
in str(exc_info)
471493

472494
def test_exception_raised_for_filelike_body_not_returning_bytes(self):
@@ -477,9 +499,16 @@ def read(self, size):
477499
return 42
478500

479501
with pytest.raises(ValueError) as exc_info:
480-
# content-length set so body type is BODY_FLAT. value doesn't matter
481-
c.request('GET', '/get', body=RogueFile(), headers={'content-length': str(10)})
482-
assert 'File-like bodies must return bytestrings. Got: {}'.format(int) in str(exc_info)
502+
# content-length set so body type is BODY_FLAT. value doesn't
503+
# matter
504+
c.request(
505+
'GET',
506+
'/get',
507+
body=RogueFile(),
508+
headers={'content-length': str(10)}
509+
)
510+
assert 'File-like bodies must return bytestrings. ' \
511+
'Got: {}'.format(int) in str(exc_info)
483512

484513

485514
class TestHTTP11Response(object):
@@ -509,7 +538,7 @@ def test_response_as_context_manager(self):
509538
with r:
510539
assert r.read() == b''
511540

512-
assert r._sock == None
541+
assert r._sock is None
513542

514543
def test_response_transparently_decrypts_gzip(self):
515544
d = DummySocket()
@@ -525,7 +554,10 @@ def test_response_transparently_decrypts_gzip(self):
525554

526555
def test_response_transparently_decrypts_real_deflate(self):
527556
d = DummySocket()
528-
headers = {b'content-encoding': [b'deflate'], b'connection': [b'close']}
557+
headers = {
558+
b'content-encoding': [b'deflate'],
559+
b'connection': [b'close'],
560+
}
529561
r = HTTP11Response(200, 'OK', headers, d, None)
530562
c = zlib_compressobj(wbits=zlib.MAX_WBITS)
531563
body = c.compress(b'this is test data')

0 commit comments

Comments
 (0)