def test_write_empty_struct(): b = TMemoryBuffer() trans = TCyBufferedTransport(b) b = proto.TCyBinaryProtocol(trans) item = TItem() b.write_struct(item) b.write_message_end() assert "00" == hexlify(trans.getvalue())
def test_write_message_begin_no_strict(): b = TMemoryBuffer() trans = TCyBufferedTransport(b) b = proto.TCyBinaryProtocol(trans, strict_write=False) b.write_message_begin("test", TType.STRING, 1) b.write_message_end() assert "00 00 00 04 74 65 73 74 0b 00 00 00 01" == \ hexlify(trans.getvalue())
def test_write_struct(): b = TMemoryBuffer() trans = TCyBufferedTransport(b) b = proto.TCyBinaryProtocol(trans) item = TItem(id=123, phones=["123456", "abcdef"]) b.write_struct(item) b.write_message_end() assert ("08 00 01 00 00 00 7b 0f 00 02 0b 00 00 00 02 00 00 00 " "06 31 32 33 34 35 36 00 00 00 06 61 62 63 64 65 66 00") == \ hexlify(trans.getvalue())
def test_write_wrong_arg_type(): trans = TCyBufferedTransport(TMemoryBuffer()) b = proto.TCyBinaryProtocol(trans) item = TItem(id="wrong type", phones=["123456", "abcdef"]) try: b.write_struct(item) except Exception: pass b.write_message_end() item2 = TItem(id=123, phones=["123456", "abcdef"]) b.write_struct(item2) b.write_message_end() assert ("08 00 01 00 00 00 7b 0f 00 02 0b 00 00 00 02 00 00 00 " "06 31 32 33 34 35 36 00 00 00 06 61 62 63 64 65 66 00") == \ hexlify(trans.getvalue())