Exemplo n.º 1
0
def test_feed_tail_split():
    buffer = Buffer(bytes([0, 0]))
    buffer.feed(bytes([1, 2, 3, 0]))
    assert not buffer.is_message_ready
    buffer.feed(bytes([0]))
    assert buffer.is_message_ready
    assert buffer.get_message() == bytes([1, 2, 3, 0, 0])
Exemplo n.º 2
0
def test_feed_shorter_than_tail():
    buffer = Buffer(bytes([0, 0]))
    buffer.feed(bytes([1]))
    buffer.feed(bytes([2]))
    buffer.feed(bytes([3]))
    buffer.feed(bytes([0]))
    assert not buffer.is_message_ready
    buffer.feed(bytes([0]))
    assert buffer.is_message_ready
    assert buffer.get_message() == bytes([1, 2, 3, 0, 0])
Exemplo n.º 3
0
async def test_buffered_read(state, session, chunk_size):
    buffer = Buffer(TAIL)

    log.info("Testing buffered read with chunk_size=%d", chunk_size)
    cmd = GetNumberOfZonesCommand(state).raw
    await session.write(cmd)
    state.increment_frame_number()

    # this is the code under test
    while not buffer.is_message_ready:
        chunk = await session.read(chunk_size)
        buffer.feed(chunk)
    res = buffer.get_message()

    number_of_zones = GetNumberOfZonesResponse(res).number
    log.info("Got number_of_zones=%d ", number_of_zones)
Exemplo n.º 4
0
def test_reset():
    buffer = Buffer(bytes([0, 0]))
    buffer.feed(bytes([5, 5, 5]))
    buffer.reset()
    buffer.feed(bytes([1, 2, 3, 0, 0]))
    assert buffer.get_message() == bytes([1, 2, 3, 0, 0])
Exemplo n.º 5
0
def test_feed_get_message_incomplete():
    buffer = Buffer(bytes([0, 0]))
    buffer.feed(bytes([1, 2, 3, 0]))
    with pytest.raises(expected_exception=ValueError):
        assert buffer.get_message()