Ejemplo n.º 1
0
def test_profile_samples():
    for name, events in traces.items():
        trace = StubTrace()
        trace.events = wrap_events(events, "name", "python:traceback")
        root = ProfileTree("root")
        build_profile(trace, root)
        check_profile(root, exp_stats[name])
Ejemplo n.º 2
0
def test_profile():
    root = ProfileTree("root")
    trace = [["a", "b", "c"], ["a", "c"]]
    # (path, total, self, children)
    exp = [ ("/root", 2, 0, 2),
            ("/root/a", 2, 0, 2),
            ("/root/a/b", 1, 0, 1),
            ("/root/a/b/c", 1, 1, 0),
            ("/root/a/c", 1, 1, 0) ]
    for ev in trace:
        leaf = root.get_or_create_branch(ev)
        leaf.value += 1
    act = make_path_stats(root.preorder)
    check_list(exp, act)

    items = []
    for e in exp:
       items.append(StatItem(e[0], e[1], e[2], e[3]))
    rms = profile_rms_error(items, root)
    assert(rms < 0.0000001)
Ejemplo n.º 3
0
def test_property_value():
    root = ProfileTree("foo")
    root.value += 1
    assert(root.value == 1)
Ejemplo n.º 4
0
def test_create():
    root = ProfileTree("root")
    ev = ["foo", "bar", "baz"]
    root.get_or_create_branch(ev)
    exp = [("root", 0), ("foo", 1), ("bar", 2), ("baz", 3)]
    check_list(exp, make_key_depth(root.preorder))
Ejemplo n.º 5
0
def test_tree():
    n00 = ProfileTree(0)
    n10 = ProfileTree(10)
    n11 = ProfileTree(11)
    n12 = ProfileTree(12)
    n20 = ProfileTree(20)
    n21 = ProfileTree(21)
    n22 = ProfileTree(22)

    n00.add_child(n10)
    n00.add_child(n11)
    n00.add_child(n12)

    n10.add_child(n20)
    n10.add_child(n21)
    n10.add_child(n22)

    exp = [(0, 0), (10, 1), (20, 2), (21, 2), (22, 2), (11, 1), (12, 1)]
    check_list(exp, make_key_depth(n00.preorder))
Ejemplo n.º 6
0
def test_print():
    assert("(42: 0)" == str(ProfileTree(42)))