Ejemplo n.º 1
0
def test_element_combining():
    test_scalar_1 = bflat.dumps({"foo": 1})
    test_scalar_2 = bflat.dumps({"foo": "bar"})
    test_array = bflat.dumps({"foo": [1.2, 2.3, -3.4]})

    assert {"foo": [1, "bar"]} == bflat.loads(test_scalar_1 + test_scalar_2)
    assert {"foo": [1, 1.2, 2.3, -3.4]} == bflat.loads(test_scalar_1 + test_array)
    assert {"foo": ["bar", 1.2, 2.3, -3.4]} == bflat.loads(test_scalar_2 + test_array)
    assert {"foo": [1.2, 2.3, -3.4, 1]} == bflat.loads(test_array + test_scalar_1)
    assert {"foo": [1.2, 2.3, -3.4, 1, "bar"]} == bflat.loads(test_array + test_scalar_1 + test_scalar_2)
Ejemplo n.º 2
0
def test_encode_int_array():
    data = [
        0, -1, 1, 127, 128, -127, -128, -32767, -32768, -65535, -65536,
        sys.maxint, -1 * sys.maxint
    ]
    data = {"values": data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 3
0
def test_encode_double_array():
    data = [
        0.0, -1.0, 1.0, 127.0, 128.01, -127.001, -128.0001, -32767.1, -32768.1,
        -65535.01, -65536.001, sys.maxint - 0.001, -1.01 * sys.maxint
    ]
    data = {"values": data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 4
0
def test_encode_doubles():
    data = [
        0.0, -1.0, 1.0, 127.0, 128.01, -127.001, -128.0001, -32767.1, -32768.1,
        -65535.01, -65536.001, sys.maxint - 0.001, -1.01 * sys.maxint
    ]
    data = dict([(str(i), data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 5
0
def test_encode_ints():
    data = [
        0, -1, 1, 127, 128, -127, -128, -32767, -32768, -65535, -65536,
        sys.maxint, -1 * sys.maxint
    ]
    data = dict([(str(i), data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 6
0
def test_element_combining():
    test_scalar_1 = bflat.dumps({"foo": 1})
    test_scalar_2 = bflat.dumps({"foo": "bar"})
    test_array = bflat.dumps({"foo": [1.2, 2.3, -3.4]})

    assert {"foo": [1, "bar"]} == bflat.loads(test_scalar_1 + test_scalar_2)
    assert {
        "foo": [1, 1.2, 2.3, -3.4]
    } == bflat.loads(test_scalar_1 + test_array)
    assert {
        "foo": ["bar", 1.2, 2.3, -3.4]
    } == bflat.loads(test_scalar_2 + test_array)
    assert {
        "foo": [1.2, 2.3, -3.4, 1]
    } == bflat.loads(test_array + test_scalar_1)
    assert {"foo":[1.2,2.3,-3.4,1,"bar"]} == \
           bflat.loads(test_array+test_scalar_1+test_scalar_2)
Ejemplo n.º 7
0
def test_scalar_double_string_double():
    test_data = "\x3e\x64\x6f\x75\x62\x6c\x65\xcd\xcc\xcc\xcc\xcc\xdc\x5e\x40\x08\x0f\x6c\x6f\x6e\x67\x20\x73\x74\x72\x69\x6e\x67\x20\x74\x61\x67\x2c\x74\x68\x65\x20\x71\x75\x69\x63\x6b\x20\x62\x72\x6f\x77\x6e\x20\x66\x6f\x78\x20\x6a\x75\x6d\x70\x65\x64\x20\x6f\x76\x65\x72\x20\x74\x68\x65\x20\x6c\x61\x7a\x79\x20\x64\x6f\x67\x38\x0e\x61\x6e\x6f\x74\x68\x65\x72\x20\x64\x6f\x75\x62\x6c\x65\x8f\xc2\xf5\x28\x5c\xff\x5e\xc0"
    data = bflat.loads(test_data)
    print data
    assert data == {
        "double": 123.45,
        "long string tag": "the quick brown fox jumped over the lazy dog",
        "another double": -123.99,
    }
Ejemplo n.º 8
0
def test_scalar_double_string_double():
    test_data = '\x3e\x64\x6f\x75\x62\x6c\x65\xcd\xcc\xcc\xcc\xcc\xdc\x5e\x40\x08\x0f\x6c\x6f\x6e\x67\x20\x73\x74\x72\x69\x6e\x67\x20\x74\x61\x67\x2c\x74\x68\x65\x20\x71\x75\x69\x63\x6b\x20\x62\x72\x6f\x77\x6e\x20\x66\x6f\x78\x20\x6a\x75\x6d\x70\x65\x64\x20\x6f\x76\x65\x72\x20\x74\x68\x65\x20\x6c\x61\x7a\x79\x20\x64\x6f\x67\x38\x0e\x61\x6e\x6f\x74\x68\x65\x72\x20\x64\x6f\x75\x62\x6c\x65\x8f\xc2\xf5\x28\x5c\xff\x5e\xc0'
    data = bflat.loads(test_data)
    print data
    assert data == {
        "double": 123.45,
        "long string tag": "the quick brown fox jumped over the lazy dog",
        "another double": -123.99
    }
Ejemplo n.º 9
0
def test_long_tag_name():
    # BFLAT encoding of {"this is a longer tag name":1}
    test_data = "\x28\x19\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\x6C\x6F\x6E\x67\x65\x72\x20\x74\x61\x67\x20\x6E\x61\x6D\x65\x01\x00\x00\x00"
    data = bflat.loads(test_data)
    print data
    assert data == {"this is a longer tag name": 1}
Ejemplo n.º 10
0
def test_long_tag_name():
    # BFLAT encoding of {"this is a longer tag name":1}
    test_data = '\x28\x19\x74\x68\x69\x73\x20\x69\x73\x20\x61\x20\x6C\x6F\x6E\x67\x65\x72\x20\x74\x61\x67\x20\x6E\x61\x6D\x65\x01\x00\x00\x00'
    data = bflat.loads(test_data)
    print data
    assert data == {"this is a longer tag name": 1}
Ejemplo n.º 11
0
def test_unicode():
    data = {"data":[u'xxx',u'',u'12345']}
    expected = {"data":['xxx','','12345']}
    assert expected == bflat.loads(bflat.dumps(data))
Ejemplo n.º 12
0
def test_encode_string_array():
    data = ["","\"","zz","zzz","zzzz","\x00\x01\x02dddd","zzz",""]
    data = {"values":data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 13
0
def test_encode_int_array():
    data = [0,-1,1,127,128,-127,-128,-32767,-32768,-65535,-65536,sys.maxint, -1*sys.maxint]
    data = {"values":data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 14
0
def test_encode_doubles():
    data = [0.0,-1.0,1.0,127.0,128.01,-127.001,-128.0001,-32767.1,-32768.1,-65535.01,-65536.001,sys.maxint - 0.001, -1.01*sys.maxint]
    data = dict([(str(i),data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 15
0
def test_binary_array():
    test_data = '\x96\x62\x69\x6e\x61\x72\x79\x06\x00\x01\x61\x03\x61\x61\x61\x04\x61\x61\x61\x61\x01\x61\x00'
    data = bflat.loads(test_data)
    print data
    assert data == {"binary": ["", "a", "aaa", "aaaa", "a", ""]}
Ejemplo n.º 16
0
def test_binary_array():
    test_data = "\x96\x62\x69\x6e\x61\x72\x79\x06\x00\x01\x61\x03\x61\x61\x61\x04\x61\x61\x61\x61\x01\x61\x00"
    data = bflat.loads(test_data)
    print data
    assert data == {"binary": ["", "a", "aaa", "aaaa", "a", ""]}
Ejemplo n.º 17
0
def test_encode_strings():
    data = ["", "\"", "zz", "zzz", "zzzz", "\x00\x01\x02dddd", "zzz", ""]
    data = dict([(str(i), data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 18
0
def test_null_string_double():
    test_data = '\x04\x6e\x75\x6c\x6c\x08\x10\x73\x74\x72\x69\x6e\x67\x20\x67\x6f\x65\x73\x20\x68\x65\x72\x65\x01\x61\x3e\x64\x6f\x75\x62\x6c\x65\x73\x68\x91\xed\x7c\xff\x23\x40'
    data = bflat.loads(test_data)
    print data
    assert data == {'null': None, 'string goes here': 'a', 'double': 9.999}
Ejemplo n.º 19
0
def test_leb128_array():
    test_data = "\xce\x6c\x65\x62\x31\x32\x38\x09\x00\x7f\x01\x81\x7f\xff\x00\x80\x7f\x80\x01\x80\x80\x7c\x80\x80\x04"
    data = bflat.loads(test_data)
    assert data == {"leb128": [0, -1, 1, -127, 127, -128, 128, -65536, 65536]}
Ejemplo n.º 20
0
def test_leb128_array():
    test_data = '\xce\x6c\x65\x62\x31\x32\x38\x09\x00\x7f\x01\x81\x7f\xff\x00\x80\x7f\x80\x01\x80\x80\x7c\x80\x80\x04'
    data = bflat.loads(test_data)
    assert data == {"leb128": [0, -1, 1, -127, 127, -128, 128, -65536, 65536]}
Ejemplo n.º 21
0
def test_null_string_double():
    test_data = "\x04\x6e\x75\x6c\x6c\x08\x10\x73\x74\x72\x69\x6e\x67\x20\x67\x6f\x65\x73\x20\x68\x65\x72\x65\x01\x61\x3e\x64\x6f\x75\x62\x6c\x65\x73\x68\x91\xed\x7c\xff\x23\x40"
    data = bflat.loads(test_data)
    print data
    assert data == {"null": None, "string goes here": "a", "double": 9.999}
Ejemplo n.º 22
0
def test_encode_string_array():
    data = ["", "\"", "zz", "zzz", "zzzz", "\x00\x01\x02dddd", "zzz", ""]
    data = {"values": data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 23
0
def test_encode_ints():
    data = [0,-1,1,127,128,-127,-128,-32767,-32768,-65535,-65536,sys.maxint, -1*sys.maxint]
    data = dict([(str(i),data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 24
0
def test_big_strings():
    for i in xrange(16):
        data = {"t" * (2**i): "d" * (2**i)}
        assert bflat.loads(bflat.dumps(data)) == data
Ejemplo n.º 25
0
def test_encode_strings():
    data = ["","\"","zz","zzz","zzzz","\x00\x01\x02dddd","zzz",""]
    data = dict([(str(i),data[i]) for i in range(len(data))])
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 26
0
def test_unicode():
    data = {"data": [u'xxx', u'', u'12345']}
    expected = {"data": ['xxx', '', '12345']}
    assert expected == bflat.loads(bflat.dumps(data))
Ejemplo n.º 27
0
def test_encode_double_array():
    data = [0.0,-1.0,1.0,127.0,128.01,-127.001,-128.0001,-32767.1,-32768.1,-65535.01,-65536.001,sys.maxint - 0.001, -1.01*sys.maxint]
    data = {"values":data}
    encoded = bflat.dumps(data)
    assert bflat.loads(encoded) == data
Ejemplo n.º 28
0
def test_bools():
    data = {"value_1": True, "value_2": False}
    expected = {"value_1": 1, "value_2": 0}
    assert expected == bflat.loads(bflat.dumps(data))
Ejemplo n.º 29
0
def test_big_strings():
    for i in xrange(16):
        data = {"t"*(2**i):"d"*(2**i)}
        assert bflat.loads(bflat.dumps(data)) == data
Ejemplo n.º 30
0
def test_scalar_int_32():
    test_data = "\x2b\x66\x6f\x6f\x01\x00\x00\x00"
    data = bflat.loads(test_data)
    print data
    assert data == {"foo": 1}
Ejemplo n.º 31
0
def test_bools():
    data = {"value_1":True,"value_2":False}
    expected = {"value_1":1, "value_2":0}
    assert expected == bflat.loads(bflat.dumps(data))
Ejemplo n.º 32
0
def test_scalar_int_32():
    test_data = '\x2b\x66\x6f\x6f\x01\x00\x00\x00'
    data = bflat.loads(test_data)
    print data
    assert data == {"foo": 1}