Example #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)
Example #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)
Example #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)
Example #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))")
Example #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))")
Example #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)
Example #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)
Example #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)
Example #9
0
def test_deep_dict_list():
    # assert no error
    list(walkdict(ddd))
Example #10
0
def test_walkdict_eq_walkdict_rec():
    assert sorted(list(walkdict(dd))) == sorted(list(walkdict_rec("", dd)))
Example #11
0
def test_walkdict_eq_walkdict_rec():
    assert sorted(list(walkdict(dd))) == sorted(list(walkdict_rec("", dd)))
Example #12
0
def test_deep_dict_list():
    # assert no error
    list(walkdict(ddd))