Exemplo 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)
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
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
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
0
def test_big_strings():
    for i in xrange(16):
        data = {"t"*(2**i):"d"*(2**i)}
        assert bflat.loads(bflat.dumps(data)) == data
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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))
Exemplo n.º 14
0
def test_unicode():
    data = {"data": [u'xxx', u'', u'12345']}
    expected = {"data": ['xxx', '', '12345']}
    assert expected == bflat.loads(bflat.dumps(data))
Exemplo n.º 15
0
def test_big_strings():
    for i in xrange(16):
        data = {"t" * (2**i): "d" * (2**i)}
        assert bflat.loads(bflat.dumps(data)) == data
Exemplo n.º 16
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
Exemplo n.º 17
0
def test_unicode():
    data = {"data":[u'xxx',u'',u'12345']}
    expected = {"data":['xxx','','12345']}
    assert expected == bflat.loads(bflat.dumps(data))
Exemplo n.º 18
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
Exemplo n.º 19
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))
Exemplo n.º 20
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