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
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
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
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
def test_empty_write_buffer(): buff = WriteBuffer(10) assert buff.length == 0 assert buff.capacity == 10 assert buff.value == b''