示例#1
0
def test_reader_and_writer_noorder(spec, value):
    """Test serialization and deserialization for types
    that have no guaranteed order."""
    protocol = BinaryProtocol()

    buffer = WriteBuffer()
    spec.write_to(protocol.writer(buffer), value)
    result = spec.read_from(protocol.reader(ReadBuffer(buffer.value)))

    assert result == value
示例#2
0
def test_simple_write():
    buff = WriteBuffer(10)
    buff.write_bytes(b'hello ')
    buff.write_bytes(b'world')

    assert buff.value == b'hello world'
    assert buff.length == 11
示例#3
0
def test_write_clear():
    buff = WriteBuffer(10)
    buff.write_bytes(b'foo')
    buff.clear()

    assert buff.value == b''
    assert buff.capacity == 10
    assert buff.length == 0
示例#4
0
def test_reader_and_writer(typ, bs, spec, value):
    """Test serialization and deserialization of all samples."""
    bs = bytes(bytearray(bs))

    protocol = BinaryProtocol()

    result = protocol.deserialize_value(typ, bs)
    assert value == result

    result = protocol.serialize_value(value)
    assert bs == result

    buffer = ReadBuffer(bs)
    deserialized = spec.read_from(protocol.reader(buffer))
    buffer = WriteBuffer()
    spec.write_to(protocol.writer(buffer), deserialized)

    assert bs == buffer.value
示例#5
0
def test_empty_write_buffer():
    buff = WriteBuffer(10)
    assert buff.length == 0
    assert buff.capacity == 10
    assert buff.value == b''