Esempio n. 1
0
def test_garbage_before_async(id_code, data, junk):
    given = bytearray(junk) + create_async_packet(id_code, data)
    response_, consumed = parser(given)

    assert consumed == len(junk) + len(data) + 6
    assert response_.id_code == ID_CODE[id_code]
    assert response_.data == bytearray(data)
Esempio n. 2
0
def test_garbage_before_response(mrsp, seq, data, junk):
    given = bytearray(junk) + create_response(mrsp, seq, data)
    response_, consumed = parser(given)

    assert consumed == len(junk) + len(data) + 6
    assert response_.mrsp == MRSP[mrsp]
    assert response_.seq == seq
    assert response_.data == bytearray(data)
Esempio n. 3
0
def test_garbage_before_response(mrsp, seq, data, junk):
    given = bytearray(junk) + create_response(mrsp, seq, data)
    response_, consumed = parser(given)

    assert consumed == len(junk) + len(data) + 6
    assert response_.mrsp == MRSP[mrsp]
    assert response_.seq == seq
    assert response_.data == bytearray(data)
Esempio n. 4
0
    def _wait_for_ack(self, sequence):
        while True:
            try:
                response, consumed = parser(self._recv_buffer)
                self._recv_buffer = self._recv_buffer[consumed:]

                if getattr(response, 'seq', None) == sequence:
                    break
            except ValueError:
                self._recv_buffer.extend(self._connection.recv(1024))
Esempio n. 5
0
    def _wait_for_ack(self, sequence):
        while True:
            try:
                response, consumed = parser(self._recv_buffer)
                self._recv_buffer = self._recv_buffer[consumed:]

                if response.seq == sequence:
                    break
            except ValueError:
                self._recv_buffer.extend(self._connection.recv(1024))
Esempio n. 6
0
def test_valid_async_packet(id_code, data):
    response_, _ = parser(create_async_packet(id_code, data))

    assert response_.id_code == ID_CODE[id_code]
    assert response_.data == bytearray(data)
Esempio n. 7
0
def test_truncated_async_packet(id_code, data):
    given = create_async_packet(id_code, data)

    for i in range(len(given) - 1):
        with pytest.raises(ValueError):
            parser(given[:i])
Esempio n. 8
0
def test_valid_response(mrsp, seq, data):
    response_, _ = parser(create_response(mrsp, seq, data))

    assert response_.mrsp == MRSP[mrsp]
    assert response_.seq == seq
    assert response_.data == bytearray(data)
Esempio n. 9
0
def test_truncated_response(mrsp, seq, data):
    given = create_response(mrsp, seq, data)

    for i in range(len(given) - 1):
        with pytest.raises(ValueError):
            parser(given[:i])
Esempio n. 10
0
def test_valid_response(mrsp, seq, data):
    response_, _ = parser(create_response(mrsp, seq, data))

    assert response_.mrsp == MRSP[mrsp]
    assert response_.seq == seq
    assert response_.data == bytearray(data)
Esempio n. 11
0
def test_truncated_response(mrsp, seq, data):
    given = create_response(mrsp, seq, data)

    for i in range(len(given) - 1):
        with pytest.raises(ValueError):
            parser(given[:i])