Exemplo n.º 1
0
def test_unpack_byte_array():
    bytestrings = [b"foo", b"bar\x00" * 256 + b"z"]

    packed = b''.join(struct.pack('<L', len(b)) + b for b in bytestrings)

    seq = unpack_byte_array(packed, len(bytestrings))
    assert list(seq) == bytestrings

    # Extra bytes silently ignored
    seq = unpack_byte_array(packed, len(bytestrings) - 1)
    assert list(seq) == bytestrings[:-1]
    seq = unpack_byte_array(packed + b'\x00', len(bytestrings))
    assert list(seq) == bytestrings
    seq = unpack_byte_array(packed + b'\x01\x02\x03\x04', len(bytestrings))
    assert list(seq) == bytestrings
Exemplo n.º 2
0
def test_unpack_byte_array():
    bytestrings = [b"foo", b"bar\x00" * 256 + b"z"]

    packed = b''.join(struct.pack('<L', len(b)) + b for b in bytestrings)

    seq = unpack_byte_array(packed, len(bytestrings))
    assert seq == bytestrings

    def check_invalid_length(b, n):
        with pytest.raises(RuntimeError):
            unpack_byte_array(b, n)

    check_invalid_length(packed, len(bytestrings) + 1)
    check_invalid_length(packed[:-1], len(bytestrings))
    check_invalid_length(packed[:-1], len(bytestrings))

    # Extra bytes silently ignored
    seq = unpack_byte_array(packed, len(bytestrings) - 1)
    assert seq == bytestrings[:-1]
    seq = unpack_byte_array(packed + b'\x00', len(bytestrings))
    assert seq == bytestrings
    seq = unpack_byte_array(packed + b'\x01\x02\x03\x04', len(bytestrings))
    assert seq == bytestrings
Exemplo n.º 3
0
def test_unpack_byte_array():
    bytestrings = [b"foo", b"bar\x00" * 256 + b"z"]

    packed = b''.join(struct.pack('<L', len(b)) + b
                      for b in bytestrings)

    seq = unpack_byte_array(packed, len(bytestrings))
    assert seq == bytestrings

    def check_invalid_length(b, n):
        with pytest.raises(RuntimeError):
            unpack_byte_array(b, n)

    check_invalid_length(packed, len(bytestrings) + 1)
    check_invalid_length(packed[:-1], len(bytestrings))
    check_invalid_length(packed[:-1], len(bytestrings))

    # Extra bytes silently ignored
    seq = unpack_byte_array(packed, len(bytestrings) - 1)
    assert seq == bytestrings[:-1]
    seq = unpack_byte_array(packed + b'\x00', len(bytestrings))
    assert seq == bytestrings
    seq = unpack_byte_array(packed + b'\x01\x02\x03\x04', len(bytestrings))
    assert seq == bytestrings
Exemplo n.º 4
0
 def check_invalid_length(b, n):
     with pytest.raises(RuntimeError):
         unpack_byte_array(b, n)
Exemplo n.º 5
0
 def check_invalid_length(b, n):
     with pytest.raises(RuntimeError):
         unpack_byte_array(b, n)