Exemplo n.º 1
0
def test_pack_string():
    b = BytesIO()
    proto.write_val(b, TType.STRING, "hello world!")
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = BytesIO()
    proto.write_val(b, TType.STRING, u("你好世界"))
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
Exemplo n.º 2
0
def test_pack_string():
    b, proto = gen_proto()
    proto.write_val(TType.STRING, "hello world!")
    assert "0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
           hexlify(b.getvalue())

    b1, proto1 = gen_proto()
    proto1.write_val(TType.STRING, "你好世界")
    assert "0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
           hexlify(b1.getvalue())
Exemplo n.º 3
0
def test_write_string():
    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, "hello world!")
    b.flush()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, u("你好世界"))
    b.flush()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
Exemplo n.º 4
0
def test_pack_container_bool():
    b, proto = gen_proto()
    proto.write_val(TType.LIST, [True, False, True], TType.BOOL)
    assert "31 01 02 01" == hexlify(b.getvalue())

    b, proto = gen_proto()
    proto.write_val(TType.MAP, {"a": True}, (TType.STRING, TType.BOOL))
    assert "01 81 01 61 01" == hexlify(b.getvalue())

    b, proto = gen_proto()
    proto.write_val(TType.MAP, {"a": [True, False]},
                    (TType.STRING, (TType.LIST, TType.BOOL)))
    assert "01 89 01 61 21 01 02" == hexlify(b.getvalue())
Exemplo n.º 5
0
def test_write_message_begin_no_strict():
    trans = TCyMemoryBuffer()
    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())
Exemplo n.º 6
0
def test_write_empty_struct():
    trans = TCyMemoryBuffer()
    b = proto.TCyBinaryProtocol(trans)
    item = TItem()
    b.write_struct(item)
    b.write_message_end()
    assert "00" == hexlify(trans.getvalue())
Exemplo n.º 7
0
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())
Exemplo n.º 8
0
def test_write_struct_recur():
    b, proto = gen_proto()
    item1 = TItem(id=123, phones=["123456", "abcdef"])
    item2 = TItem(id=456, phones=["123456", "abcdef"])
    pkg = TPkg(id=123, items=[item1, item2])
    proto.write_val(TType.STRUCT, pkg)
    assert ("15 f6 01 19 2c 15 f6 01 19 28 06 31 32 33 34 35 36 06 61 62 63 "
            "64 65 66 00 15 90 07 19 28 06 31 32 33 34 35 36 06 61 62 63 64 "
            "65 66 00 00" == hexlify(b.getvalue()))
Exemplo n.º 9
0
def test_write_struct():
    trans = TCyMemoryBuffer()
    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())
Exemplo n.º 10
0
def test_write_wrong_arg_type():
    trans = TCyMemoryBuffer()
    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())
Exemplo n.º 11
0
def test_write_struct2():
    b, proto = gen_proto()
    item = TItem(id=123, phones=["123456", "abcdef"])
    proto.write_val(TType.STRUCT, item)
    assert ("15 f6 01 19 28 06 31 32 33 34 "
            "35 36 06 61 62 63 64 65 66 00" == hexlify(b.getvalue()))
Exemplo n.º 12
0
def test_write_message_begin():
    b, proto = gen_proto()
    proto.write_message_begin("test", 2, 1)
    assert "82 41 01 04 74 65 73 74" == \
           hexlify(b.getvalue())
Exemplo n.º 13
0
def test_pack_map():
    b, proto = gen_proto()
    proto.write_val(TType.MAP, {'a': 2}, (TType.STRING, TType.I16))
    assert "01 84 01 61 04" == hexlify(b.getvalue())
Exemplo n.º 14
0
def test_pack_list():
    b, proto = gen_proto()
    proto.write_val(TType.LIST, [1, 2, 3, 4, 5], TType.I16)
    assert "54 02 04 06 08 0a" == hexlify(b.getvalue())
Exemplo n.º 15
0
def test_pack_i32():
    b, proto = gen_proto()
    proto.write_val(TType.I32, 1234567890)
    assert "a4 8b b0 99 09" == hexlify(b.getvalue())
Exemplo n.º 16
0
def test_pack_byte():
    b, proto = gen_proto()
    proto.write_val(TType.BYTE, 77)
    assert "4d" == hexlify(b.getvalue())
Exemplo n.º 17
0
def test_pack_double():
    b = BytesIO()
    proto.write_val(b, TType.DOUBLE, 1234567890.1234567890)
    assert "41 d2 65 80 b4 87 e6 b7" == hexlify(b.getvalue())
Exemplo n.º 18
0
def test_pack_i64():
    b = BytesIO()
    proto.write_val(b, TType.I64, 1234567890123456789)
    assert "11 22 10 f4 7d e9 81 15" == hexlify(b.getvalue())
Exemplo n.º 19
0
def test_pack_i32():
    b = BytesIO()
    proto.write_val(b, TType.I32, 1234567890)
    assert "49 96 02 d2" == hexlify(b.getvalue())
Exemplo n.º 20
0
def test_pack_i16():
    b = BytesIO()
    proto.write_val(b, TType.I16, 12345)
    assert "30 39" == hexlify(b.getvalue())
Exemplo n.º 21
0
def test_pack_i8():
    b = BytesIO()
    proto.write_val(b, TType.I08, 123)
    assert "7b" == hexlify(b.getvalue())
Exemplo n.º 22
0
def test_write_empty_struct():
    b = BytesIO()
    item = TItem()
    proto.TBinaryProtocol(b).write_struct(item)
    assert "00" == hexlify(b.getvalue())
Exemplo n.º 23
0
def test_write_empty_struct():
    b, proto = gen_proto()
    item = TItem()
    proto.write_struct(item)
    assert "00" == hexlify(b.getvalue())
Exemplo n.º 24
0
def test_pack_double():
    b, proto = gen_proto()
    proto.write_val(TType.DOUBLE, 1234567890.1234567890)
    assert "b7 e6 87 b4 80 65 d2 41" == hexlify(b.getvalue())
Exemplo n.º 25
0
def test_pack_i16():
    b, proto = gen_proto()
    proto.write_val(TType.I16, 12345)
    assert "f2 c0 01" == hexlify(b.getvalue())
Exemplo n.º 26
0
def test_write_i64():
    b = TCyMemoryBuffer()
    proto.write_val(b, TType.I64, 1234567890123456789)
    b.flush()
    assert "11 22 10 f4 7d e9 81 15" == hexlify(b.getvalue())
Exemplo n.º 27
0
def test_pack_i64():
    b, proto = gen_proto()
    proto.write_val(TType.I64, 1234567890123456789)
    assert "aa 84 cc de 8f bd 88 a2 22" == hexlify(b.getvalue())
Exemplo n.º 28
0
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())
Exemplo n.º 29
0
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())
Exemplo n.º 30
0
def test_pack_bool():
    b, proto = gen_proto()
    proto.write_bool(True)
    assert "01" == hexlify(b.getvalue())