Exemplo n.º 1
0
def test_dyna_roundtrip_all_types():
    import datetime, decimal
    # dynamic uses dict, list, bytes, utf8, bool, svarint, float64, decimal, sched, complex
    # dynamic currently does NOT use int64, uvarint, stamp64
    data_dyna_types = [{
        1: 2
    }, [3, 4], b'foo', u'bar', True, -69, 2.318,
                       decimal.Decimal('3.8'),
                       datetime.datetime.now(), 4j, None]
    assert unpack(pack(data_dyna_types), 0) == data_dyna_types
Exemplo n.º 2
0
def test_dyna_unpack_dict():
    assert unpack(test1_buf, 0) == test1_data
Exemplo n.º 3
0
def test_dyna_unpack_header_only_invalid_type():
    hdr_buf = SBytes("05")  # no key, no data, bool type. (Error!)
    with pytest.raises(TypeError):
        assert unpack(hdr_buf, 0) == {}
Exemplo n.º 4
0
def test_dyna_unpack_header_only_dict():
    hdr_buf = SBytes("01")  # no key, no data, dict type.
    assert unpack(hdr_buf, 0) == {}
Exemplo n.º 5
0
def test_dyna_unpack_header_only_list():
    hdr_buf = SBytes("02")  # no key, no data, list type.
    assert unpack(hdr_buf, 0) == []
Exemplo n.º 6
0
def test_dyna_dict_none_key():
    c = {None: 3}  # annoyingly, this is allowed in python
    buf = pack(c)
    out = unpack(buf, 0)
    assert out == c  # but still works fine.
Exemplo n.º 7
0
def test_dyna_roundtrip_list():
    test_list = [1, 2, 3, 4, 5, u'a', u'b', b'xx']
    assert unpack(pack(test_list), 0) == test_list
Exemplo n.º 8
0
def test_dyna_roundtrip_dict():
    assert unpack(pack(test1_data), 0) == test1_data