Exemple #1
0
    def test_socket_error_on_readline(self, monkeypatch):
        monkeypatch.setattr(hyper.common.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        with pytest.raises(ConnectionResetError):
            b.readline()
Exemple #2
0
    def test_socket_error_on_readline(self, monkeypatch):
        monkeypatch.setattr(
            hyper.common.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)

        with pytest.raises(ConnectionResetError):
            b.readline()
Exemple #3
0
    def test_socket_readline_too_long(self, monkeypatch):
        monkeypatch.setattr(hyper.common.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        b._buffer_view[0:b._buffer_size] = b'0' * b._buffer_size
        b._bytes_in_buffer = b._buffer_size

        with pytest.raises(LineTooLongError):
            b.readline()
Exemple #4
0
    def test_socket_readline_too_long(self, monkeypatch):
        monkeypatch.setattr(
            hyper.common.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)

        b._buffer_view[0:b._buffer_size] = b'0' * b._buffer_size
        b._bytes_in_buffer = b._buffer_size

        with pytest.raises(LineTooLongError):
            b.readline()
Exemple #5
0
    def test_readline_from_buffer(self, monkeypatch):
        monkeypatch.setattr(hyper.common.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])
        b._buffer_view[0:len(combined)] = combined
        b._bytes_in_buffer += len(combined)

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three
Exemple #6
0
    def test_readline_from_buffer(self, monkeypatch):
        monkeypatch.setattr(
            hyper.common.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])
        b._buffer_view[0:len(combined)] = combined
        b._bytes_in_buffer += len(combined)

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three
Exemple #7
0
    def test_readline_from_socket(self, monkeypatch):
        monkeypatch.setattr(hyper.common.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])

        for i in range(0, len(combined), 5):
            s.inbound_packets.append(combined[i:i + 5])

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three
Exemple #8
0
    def test_readline_from_socket(self, monkeypatch):
        monkeypatch.setattr(
            hyper.common.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])

        for i in range(0, len(combined), 5):
            s.inbound_packets.append(combined[i:i+5])

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three
Exemple #9
0
    def test_readline_both(self, monkeypatch):
        monkeypatch.setattr(hyper.common.bufsocket.select, 'select',
                            dummy_select)
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])

        split_index = int(len(combined) / 2)

        b._buffer_view[0:split_index] = combined[0:split_index]
        b._bytes_in_buffer += split_index

        for i in range(split_index, len(combined), 5):
            s.inbound_packets.append(combined[i:i + 5])

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three
Exemple #10
0
    def test_readline_both(self, monkeypatch):
        monkeypatch.setattr(
            hyper.common.bufsocket.select, 'select', dummy_select
        )
        s = DummySocket()
        b = BufferedSocket(s)

        one = b'hi there\r\n'
        two = b'this is another line\r\n'
        three = b'\r\n'
        combined = b''.join([one, two, three])

        split_index = int(len(combined) / 2)

        b._buffer_view[0:split_index] = combined[0:split_index]
        b._bytes_in_buffer += split_index

        for i in range(split_index, len(combined), 5):
            s.inbound_packets.append(combined[i:i+5])

        assert b.readline().tobytes() == one
        assert b.readline().tobytes() == two
        assert b.readline().tobytes() == three