def test_read_struct(): b = BytesIO(b"\x08\x00\x01\x00\x00\x00{\x0f\x00\x02\x0b\x00\x00\x00" b"\x02\x00\x00\x00\x06123456\x00\x00\x00\x06abcdef\x00") _item = TItem(id=123, phones=["123456", "abcdef"]) _item2 = TItem() proto.TBinaryProtocol(b).read_struct(_item2) assert _item == _item2
def test_read_struct(): b = BytesIO(b'\x08\x00\x01\x00\x00\x00{\x0f\x00\x02\x0b\x00\x00\x00' b'\x02\x00\x00\x00\x06123456\x00\x00\x00\x06abcdef\x00') _item = TItem(id=123, phones=['123456', 'abcdef']) _item2 = TItem() proto.TBinaryProtocol(b).read_struct(_item2) assert_equal(_item, _item2)
def test_write_struct(): b = BytesIO() item = TItem(id=123, phones=["123456", "abcdef"]) proto.TBinaryProtocol(b).write_struct(item) 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(b.getvalue())
def test_write_struct(): b = BytesIO() item = TItem(id=123, phones=['123456', 'abcdef']) proto.TBinaryProtocol(b).write_struct(item) assert_equal( "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(b.getvalue()))
def test_write_message_begin_not_strict(): b = BytesIO() proto.TBinaryProtocol(b, strict_write=False) \ .write_message_begin("test", TType.STRING, 1) assert "00 00 00 04 74 65 73 74 0b 00 00 00 01" == \ hexlify(b.getvalue())
def test_write_message_begin(): b = BytesIO() proto.TBinaryProtocol(b).write_message_begin("test", TType.STRING, 1) assert "80 01 00 0b 00 00 00 04 74 65 73 74 00 00 00 01" == \ hexlify(b.getvalue())
def test_write_huge_struct(): b = BytesIO() item = TItem(id=12345, phones=["1234567890"] * 100000) proto.TBinaryProtocol(b).write_struct(item)
def test_read_empty_struct(): b = BytesIO(b"\x00") _item = TItem() _item2 = TItem() proto.TBinaryProtocol(b).read_struct(_item2) assert _item == _item2
def test_write_empty_struct(): b = BytesIO() item = TItem() proto.TBinaryProtocol(b).write_struct(item) assert "00" == hexlify(b.getvalue())
def test_read_message_begin_not_strict(): b = BytesIO(b"\x00\x00\x00\x04test\x0b\x00\x00\x00\x01") res = proto.TBinaryProtocol(b, strict_read=False).read_message_begin() assert res == ("test", TType.STRING, 1)
def test_read_message_begin(): b = BytesIO(b"\x80\x01\x00\x0b\x00\x00\x00\x04test\x00\x00\x00\x01") res = proto.TBinaryProtocol(b).read_message_begin() assert res == ("test", TType.STRING, 1)
def test_read_message_begin(): b = BytesIO(b'\x80\x01\x00\x0b\x00\x00\x00\x04test\x00\x00\x00\x01') res = proto.TBinaryProtocol(b).read_message_begin() assert_equal(res, ("test", TType.STRING, 1))
def test_write_message_begin(): b = BytesIO() proto.TBinaryProtocol(b).write_message_begin('test', TType.STRING, 1) assert_equal("80 01 00 0b 00 00 00 04 74 65 73 74 00 00 00 01", hexlify(b.getvalue()))