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

Commit a974eec

Browse files
committed
update test
introduced FrameEncoderMixin helper class. fix waits for not displaying unwanted EOF errors.
1 parent 085975f commit a974eec

File tree

2 files changed

+80
-74
lines changed

2 files changed

+80
-74
lines changed

test/test_hyper.py

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def frame_buffer():
4848

4949

5050
class TestHyperConnection(object):
51+
5152
def test_connections_accept_hosts_and_ports(self):
5253
c = HTTP20Connection(host='www.google.com', port=8080)
5354
assert c.host == 'www.google.com'
@@ -499,6 +500,7 @@ def test_headers_with_continuation(self):
499500

500501
def test_send_tolerate_peer_gone(self):
501502
class ErrorSocket(DummySocket):
503+
502504
def sendall(self, data):
503505
raise socket.error(errno.EPIPE)
504506

@@ -700,7 +702,8 @@ def test_incrementing_window_after_close(self):
700702
assert len(originally_sent_data) + 1 == len(c._sock.queue)
701703

702704

703-
class TestServerPush(object):
705+
class FrameEncoderMixin(object):
706+
704707
def setup_method(self, method):
705708
self.frames = []
706709
self.encoder = Encoder()
@@ -732,6 +735,9 @@ def add_data_frame(self, stream_id, data, end_stream=False):
732735
frame.flags.add('END_STREAM')
733736
self.frames.append(frame)
734737

738+
739+
class TestServerPush(FrameEncoderMixin):
740+
735741
def request(self, enable_push=True):
736742
self.conn = HTTP20Connection('www.google.com', enable_push=enable_push)
737743
self.conn._sock = DummySocket()
@@ -957,6 +963,7 @@ def test_pushed_requests_ignore_unexpected_headers(self):
957963

958964

959965
class TestResponse(object):
966+
960967
def test_status_is_stripped_from_headers(self):
961968
headers = HTTPHeaderMap([(':status', '200')])
962969
resp = HTTP20Response(headers, None)
@@ -1107,6 +1114,7 @@ def test_response_version(self):
11071114

11081115

11091116
class TestHTTP20Adapter(object):
1117+
11101118
def test_adapter_reuses_connections(self):
11111119
a = HTTP20Adapter()
11121120
conn1 = a.get_connection('http2bin.org', 80, 'http')
@@ -1130,6 +1138,7 @@ def test_adapter_accept_client_certificate(self):
11301138

11311139

11321140
class TestUtilities(object):
1141+
11331142
def test_combining_repeated_headers(self):
11341143
test_headers = [
11351144
(b'key1', b'val1'),
@@ -1303,44 +1312,14 @@ def test_resetting_streams_after_close(self):
13031312
c._single_read()
13041313

13051314

1306-
class TestUpgradingPush(object):
1315+
class TestUpgradingPush(FrameEncoderMixin):
13071316
http101 = (b"HTTP/1.1 101 Switching Protocols\r\n"
13081317
b"Connection: upgrade\r\n"
13091318
b"Upgrade: h2c\r\n"
13101319
b"\r\n")
13111320

1312-
def setup_method(self, method):
1313-
self.frames = [SettingsFrame(0)] # Server side preface
1314-
self.encoder = Encoder()
1315-
self.conn = None
1316-
1317-
def add_push_frame(self, stream_id, promised_stream_id, headers,
1318-
end_block=True):
1319-
frame = PushPromiseFrame(stream_id)
1320-
frame.promised_stream_id = promised_stream_id
1321-
frame.data = self.encoder.encode(headers)
1322-
if end_block:
1323-
frame.flags.add('END_HEADERS')
1324-
self.frames.append(frame)
1325-
1326-
def add_headers_frame(self, stream_id, headers, end_block=True,
1327-
end_stream=False):
1328-
frame = HeadersFrame(stream_id)
1329-
frame.data = self.encoder.encode(headers)
1330-
if end_block:
1331-
frame.flags.add('END_HEADERS')
1332-
if end_stream:
1333-
frame.flags.add('END_STREAM')
1334-
self.frames.append(frame)
1335-
1336-
def add_data_frame(self, stream_id, data, end_stream=False):
1337-
frame = DataFrame(stream_id)
1338-
frame.data = data
1339-
if end_stream:
1340-
frame.flags.add('END_STREAM')
1341-
self.frames.append(frame)
1342-
13431321
def request(self, enable_push=True):
1322+
self.frames = [SettingsFrame(0)] + self.frames # Server side preface
13441323
self.conn = HTTPConnection('www.google.com', enable_push=enable_push)
13451324
self.conn._conn._sock = DummySocket()
13461325
self.conn._conn._sock.buffer = BytesIO(
@@ -1487,6 +1466,7 @@ def test_reset_pushed_streams_when_push_disabled(self):
14871466

14881467
# Some utility classes for the tests.
14891468
class NullEncoder(object):
1469+
14901470
@staticmethod
14911471
def encode(headers):
14921472

@@ -1503,6 +1483,7 @@ def to_str(v):
15031483

15041484

15051485
class FixedDecoder(object):
1486+
15061487
def __init__(self, result):
15071488
self.result = result
15081489

@@ -1511,6 +1492,7 @@ def decode(self, headers):
15111492

15121493

15131494
class DummySocket(object):
1495+
15141496
def __init__(self):
15151497
self.queue = []
15161498
self._buffer = BytesIO()
@@ -1548,6 +1530,7 @@ def fill(self):
15481530

15491531

15501532
class DummyStream(object):
1533+
15511534
def __init__(self, data, trailers=None):
15521535
self.data = data
15531536
self.data_frames = []

0 commit comments

Comments
 (0)