def test_unknown_type_id(typ, bs): protocol = BinaryProtocol() with pytest.raises(ThriftProtocolError) as exc_info: protocol.deserialize_value(typ, bytes(bytearray(bs))) assert 'Unknown TType' in str(exc_info)
def test_input_too_short(typ, bs): """Test that EndOfInputError is raised when not enough bytes are available.""" protocol = BinaryProtocol() with pytest.raises(EndOfInputError) as exc_info: protocol.deserialize_value(typ, bytes(bytearray(bs))) assert 'bytes but got' in str(exc_info)
def test_input_too_short(typ, spec, bs): """Test that EndOfInputError is raised when not enough bytes are available.""" protocol = BinaryProtocol() with pytest.raises(EndOfInputError) as exc_info: s = bytes(bytearray(bs)) protocol.deserialize_value(typ, s) reader = protocol.reader(ReadBuffer(s)) spec.read_from(reader) assert 'bytes but got' in str(exc_info)
def test_input_too_short(typ, spec, bs): """Test that EndOfInputError is raised when not enough bytes are available.""" protocol = BinaryProtocol() with pytest.raises(EndOfInputError) as exc_info: s = bytes(bytearray(bs)) protocol.deserialize_value(typ, s) assert 'bytes but got' in str(exc_info) with pytest.raises(EndOfInputError) as exc_info: reader = protocol.reader(ReadBuffer(s)) spec.read_from(reader) assert 'bytes but got' in str(exc_info)
def test_reader_and_writer(typ, bs, 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
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