Пример #1
0
def test_2():
    d = {
        datetime: "value",
        "required": True,
        "validate": datetime,
    }
    ls = sorted(list(walkdict(d)))
    exp = [("$datetime", "value"),
           ("required", True),
           ("validate", datetime), ]
    assert ls == sorted(exp)
Пример #2
0
def test_2():
    d = {
        datetime: "value",
        "required": True,
        "validate": datetime,
    }
    ls = sorted(list(walkdict(d)))
    exp = [
        ("$datetime", "value"),
        ("required", True),
        ("validate", datetime),
    ]
    assert ls == sorted(exp)
Пример #3
0
def test_1():
    d = {
        "dict": "value",
        "key": {
            "inner": "inner-value"
        },
        "list": [1, 2, 3, 4]
    }
    ls = sorted(list(walkdict(d)))
    exp = [("dict", "value"),
           ("key.inner", "inner-value"),
           ("list.[0]", 1),
           ("list.[1]", 2),
           ("list.[2]", 3),
           ("list.[3]", 4), ]
    assert ls == sorted(exp)
Пример #4
0
def do_profile():
    import cProfile as profile
    from timeit import timeit

    for (k, v) in walkdict(dd):
        print "'%s' -> '%s'" % (k, v)

    print "walkdict_rec",\
        timeit("list(walkdict_rec('',dd))",
               "from __main__ import walkdict_rec,dd", number=100)
    print "walkdict    ",\
        timeit("list(walkdict(dd))",
               "from __main__ import walkdict,dd", number=100)
    print "walkdict_rec"
    profile.run("for i in range(300):list(walkdict_rec('',ddd))")
    print "walkdict    "
    profile.run("for i in range(300):list(walkdict(ddd))")
Пример #5
0
def do_profile():
    import cProfile as profile
    from timeit import timeit

    for (k, v) in walkdict(dd):
        print "'%s' -> '%s'" % (k, v)

    print "walkdict_rec",\
        timeit("list(walkdict_rec('',dd))",
               "from __main__ import walkdict_rec,dd", number=100)
    print "walkdict    ",\
        timeit("list(walkdict(dd))",
               "from __main__ import walkdict,dd", number=100)
    print "walkdict_rec"
    profile.run("for i in range(300):list(walkdict_rec('',ddd))")
    print "walkdict    "
    profile.run("for i in range(300):list(walkdict(ddd))")
Пример #6
0
def test_1():
    d = {
        "dict": "value",
        "key": {
            "inner": "inner-value"
        },
        "list": [1, 2, 3, 4]
    }
    ls = sorted(list(walkdict(d)))
    exp = [
        ("dict", "value"),
        ("key.inner", "inner-value"),
        ("list.[0]", 1),
        ("list.[1]", 2),
        ("list.[2]", 3),
        ("list.[3]", 4),
    ]
    assert ls == sorted(exp)
Пример #7
0
def test_3():
    d = {
        "dict": "value",
        "list-dict": [
            {
                "desc": "desc-str",
            },
            {
                "desc": "desc-str",
            },
        ],
    }

    ls = sorted(list(walkdict(d)))
    exp = [("dict", "value"),
           ("list-dict.[0].desc", "desc-str"),
           ("list-dict.[1].desc", "desc-str"), ]
    assert ls == sorted(exp)
Пример #8
0
def test_3():
    d = {
        "dict": "value",
        "list-dict": [
            {
                "desc": "desc-str",
            },
            {
                "desc": "desc-str",
            },
        ],
    }

    ls = sorted(list(walkdict(d)))
    exp = [
        ("dict", "value"),
        ("list-dict.[0].desc", "desc-str"),
        ("list-dict.[1].desc", "desc-str"),
    ]
    assert ls == sorted(exp)
Пример #9
0
def test_deep_dict_list():
    # assert no error
    list(walkdict(ddd))
Пример #10
0
def test_walkdict_eq_walkdict_rec():
    assert sorted(list(walkdict(dd))) == sorted(list(walkdict_rec("", dd)))
Пример #11
0
def test_walkdict_eq_walkdict_rec():
    assert sorted(list(walkdict(dd))) == sorted(list(walkdict_rec("", dd)))
Пример #12
0
def test_deep_dict_list():
    # assert no error
    list(walkdict(ddd))