Esempio n. 1
0
def test_pack_regular_map():
    buffer = io.BytesIO()
    packed = pack(collections.OrderedDict(
        [("a", 1),("b", 1), ("c", 3), ("d", 4), ("e", 5), ("f", 6), ("g", 7), ("h", 8), ("i", 9),
         ("j", 0), ("k", 1), ("l", 2), ("m", 3), ("n", 4), ("o", 5), ("p", 6)]), buffer).getvalue()
    output = get_hexbytes(packed)
    print(output)
    assert output.lower() == "0xD80x100x810x610x10x810x620x10x810x630x30x810x640x40x810x650x50x810x660x60x810x670x70x810x680x80x810x690x90x810x6A0x00x810x6B0x10x810x6C0x20x810x6D0x30x810x6E0x40x810x6F0x50x810x700x6".lower()
Esempio n. 2
0
def test_pack_neg_float():
    buffer = io.BytesIO()
    packed = pack(-1.1, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xC10xBF0xF10x990x990x990x990x990x9A'.lower()
Esempio n. 3
0
def test_pack_max_int():
    buffer = io.BytesIO()
    packed = pack(9223372036854775807, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xCB0x7F0xFF0xFF0xFF0xFF0xFF0xFF0xFF'.lower()
Esempio n. 4
0
def test_pack_min_int():
    buffer = io.BytesIO()
    packed = pack(-9223372036854775808, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xCB0x800x00x00x00x00x00x00x0'.lower()
Esempio n. 5
0
def test_pack_int32():
    buffer = io.BytesIO()
    packed = pack(40000, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xca0x00x00x9c0x40'.lower()
Esempio n. 6
0
def test_pack_int16():
    buffer = io.BytesIO()
    packed = pack(1234, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xC90x40xD2'.lower()
Esempio n. 7
0
def test_pack_int8():
    buffer = io.BytesIO()
    packed = pack(-128, buffer).getvalue()
    output = get_hexbytes(packed)
    # TODO test value
    assert output.lower() == '0xC80x80'.lower()
Esempio n. 8
0
def test_pack_empty_list():
    buffer = io.BytesIO()
    packed = pack([], buffer).getvalue()
    val = hex(packed[0])
    assert val.lower() == '0x90'.lower()
Esempio n. 9
0
def test_pack_false():
    buffer = io.BytesIO()
    packed = pack(False, buffer).getvalue()
    marker = hex(packed[0])
    assert marker.lower() == '0xc2'
Esempio n. 10
0
def test_pack_empty_map():
    buffer = io.BytesIO()
    packed = pack({}, buffer).getvalue()
    val = hex(packed[0])
    assert val.lower() == '0xA0'.lower()
Esempio n. 11
0
def test_pack_tiny_map():
    buffer = io.BytesIO()
    packed = pack({"a":1}, buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xA10x810x610x1'.lower()
Esempio n. 12
0
def test_pack_null():
    buffer = io.BytesIO()
    packed = pack(None, buffer).getvalue()
    marker = hex(packed[0])
    assert marker.lower() == '0xc0'
Esempio n. 13
0
def test_pack_regular_list():
    buffer = io.BytesIO()
    packed = pack([1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0], buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xD40x140x10x20x30x40x50x60x70x80x90x00x10x20x30x40x50x60x70x80x90x0'.lower()
Esempio n. 14
0
def test_pack_tiny_list():
    buffer = io.BytesIO()
    packed = pack([1,2,3], buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0x930x10x20x3'.lower()
Esempio n. 15
0
def test_pack_tiny_string():
    buffer = io.BytesIO()
    packed = pack('MyClient/1.0', buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0x8C0x4D0x790x430x6C0x690x650x6E0x740x2F0x310x2E0x30'.lower()
Esempio n. 16
0
def test_pack_tiny_int():
    buffer = io.BytesIO()
    packed = pack(42, buffer).getvalue()
    val = hex(packed[0])
    assert val.lower() == '0x2A'.lower()
Esempio n. 17
0
def test_pack_regular_string():
    buffer = io.BytesIO()
    packed = pack('abcdefghijklmnopqrstuvwxyz', buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xD00x1A0x610x620x630x640x650x660x670x680x690x6A0x6B0x6C0x6D0x6E0x6F0x700x710x720x730x740x750x760x770x780x790x7A'.lower()
Esempio n. 18
0
def test_pack_special_string():
    buffer = io.BytesIO()
    packed = pack("En å flöt över ängen", buffer).getvalue()
    output = get_hexbytes(packed)
    assert output.lower() == '0xD00x180x450x6E0x200xC30xA50x200x660x6C0xC30xB60x740x200xC30xB60x760x650x720x200xC30xA40x6E0x670x650x6E'.lower()