def test_pack_byte_array():
    bytestrings = [b"foo", b"bar\x00" * 256 + b"z"]

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

    b = pack_byte_array(bytestrings)
    assert b == expected

    b = pack_byte_array([])
    assert b == b''

    with pytest.raises(TypeError):
        pack_byte_array(tuple(bytestrings))

    with pytest.raises(TypeError):
        pack_byte_array(bytestrings + [u"foo"])

    with pytest.raises(TypeError):
        pack_byte_array(b"foo")
Example #2
0
def test_pack_byte_array():
    bytestrings = [b"foo", b"bar\x00" * 256 + b"z"]

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

    b = pack_byte_array(bytestrings)
    assert b == expected

    b = pack_byte_array([])
    assert b == b''

    with pytest.raises(TypeError):
        pack_byte_array(tuple(bytestrings))

    with pytest.raises(TypeError):
        pack_byte_array(bytestrings + [u"foo"])

    with pytest.raises(TypeError):
        pack_byte_array(b"foo")