Beispiel #1
0
def test_len():
    data = b"\x00\x0c\xe3\x83\x9c\xe3\x83\xbc\xe3\x83\xab\xe3\x83\x88"
    stream = ByteStream(data)
    assert stream.tell() == 0

    # read 1 byte
    assert stream.seek(0) == 0
    assert len(stream) == len(data)
    expected_length = len(data)
    for i in range(len(data)):
        read = stream.read(1)
        expected_length -= len(read)
        assert len(stream) == expected_length

    # read 3 byte
    assert stream.seek(0) == 0
    assert len(stream) == len(data)
    expected_length = len(data)
    for i in range(0, len(data), 3):
        read = stream.read(3)
        expected_length -= len(read)
        assert len(stream) == expected_length
Beispiel #2
0
def test_read():
    data = b"\x00\x0c\xe3\x83\x9c\xe3\x83\xbc\xe3\x83\xab\xe3\x83\x88"
    stream = ByteStream(data)
    assert stream.tell() == 0

    assert stream.read() == data
    assert stream.tell() == len(data)

    # read 0 bytes
    assert stream.seek(0) == 0
    assert stream.read(0) == ""
    assert stream.tell() == 0

    # read 1 byte
    assert stream.seek(0) == 0
    for i in range(len(data)):
        assert stream.read(1) == data[i:i+1]
        assert stream.tell() == i + 1

    # read 3 bytes
    assert stream.seek(0) == 0
    for i in range(0, len(data), 3):
        assert stream.read(3) == data[i:i+3]
        assert stream.tell() == min(i + 3, len(data))