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

Commit d018249

Browse files
committed
Code coverage of readline.
1 parent 455d696 commit d018249

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

hyper/http20/bufsocket.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ def readline(self):
150150
Read up to a newline from the network and returns it. The implicit
151151
maximum line length is the buffer size of the buffered socket.
152152
153+
Note that, unlike recv, this method absolutely *does* block until it
154+
can read the line.
155+
153156
:returns: A ``memoryview`` object containing the appropriate number of
154157
bytes. The data *must* be copied out by the caller before the next
155158
call to this function.

test/test_socket.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
66
Test the BufferedSocket implementation in hyper.
77
"""
8+
import pytest
9+
810
import hyper.http20.bufsocket
911
from hyper.http20.bufsocket import BufferedSocket
12+
from hyper.http20.exceptions import ConnectionResetError, LineTooLongError
1013

1114
# Patch the select method in bufsocket to make sure that it always returns
1215
# the dummy socket as readable.
@@ -181,6 +184,29 @@ def test_readline_both(self, monkeypatch):
181184
assert b.readline().tobytes() == two
182185
assert b.readline().tobytes() == three
183186

187+
def test_socket_error_on_readline(self, monkeypatch):
188+
monkeypatch.setattr(
189+
hyper.http20.bufsocket.select, 'select', dummy_select
190+
)
191+
s = DummySocket()
192+
b = BufferedSocket(s)
193+
194+
with pytest.raises(ConnectionResetError):
195+
b.readline()
196+
197+
def test_socket_readline_too_long(self, monkeypatch):
198+
monkeypatch.setattr(
199+
hyper.http20.bufsocket.select, 'select', dummy_select
200+
)
201+
s = DummySocket()
202+
b = BufferedSocket(s)
203+
204+
b._buffer_view[0:b._buffer_size] = b'0' * b._buffer_size
205+
b._bytes_in_buffer = b._buffer_size
206+
207+
with pytest.raises(LineTooLongError):
208+
b.readline()
209+
184210

185211
class DummySocket(object):
186212
def __init__(self):

0 commit comments

Comments
 (0)