Exemple #1
0
def test_basic():
    descs = {"fun": fun}
    ds = DocStorage().from_dict(descs)
    t = Tracer(ds)
    t.start_tracing()
    fun(1, ("g", 3), 8)
    fun(2.0, ("a", 1.0), "a")
    t.end_tracing()
    desc = ds.descs["fun"]
    inputcells = desc.inputcells
    assert len(inputcells) == 3
    assert isinstance(inputcells[0], model.SomeUnion)
    assert isinstance(inputcells[1], model.SomeTuple)
    assert isinstance(inputcells[2], model.SomeUnion)
    assert isinstance(desc.retval, model.SomeString)
    cs = sorted(desc.call_sites.keys())
    assert len(cs) == 2
    f_name = cut_pyc(__file__)
    assert len(cs[0]) == 1
    assert len(cs[1]) == 1
    assert cs[1][0].filename == f_name
    # lines are counted from 0
    num = test_basic.func_code.co_firstlineno
    assert cs[1][0].lineno == num + 4 or cs[1][0].lineno == num + 5
    assert cs[0][0].filename == f_name
    assert cs[0][0].lineno == num + 5 or cs[0][0].lineno == num + 4
    if 0:
        pds = PermaDocStorage(DocStorageAccessor(ds))
        assert pds.get_function_names() == ["fun"]
        sig = pds.get_function_signature("fun")
        assert sig[0][0][0] == "a"
        assert isinstance(sig[0][0][1], model.SomeUnion)
        assert len(pds.get_function_callpoints("fun")) == 2
Exemple #2
0
def test_while_call():
    ds = DocStorage().from_dict({"other_fun": other_fun})
    t = Tracer(ds)
    t.start_tracing()
    for x in xrange(8):
        other_fun()
    t.end_tracing()
    desc = ds.descs["other_fun"]
    assert len(desc.call_sites.keys()) == 1
    # assert isinstance(desc.call_sites.values()[0][0], py.code.Frame)
    if 0:
        pds = PermaDocStorage(DocStorageAccessor(ds))
        assert len(pds.get_function_callpoints("other_fun")) == 1
Exemple #3
0
def test_class():
    descs = {"AClass": AClass}
    ds = DocStorage().from_dict(descs)
    t = Tracer(ds)
    t.start_tracing()
    s = AClass()
    s.exposed_method(1, 2.0, [1, 2, 3])
    t.end_tracing()
    desc = ds.descs["AClass"]
    inputcells = desc.fields["__init__"].inputcells
    assert len(inputcells) == 2
    assert isinstance(inputcells[0], model.SomeInstance)
    # assert inputcells[0].classdef.classdesc.pyobj is SomeClass
    # XXX: should work
    assert isinstance(inputcells[1], model.SomeString)
    f_name = __file__
    if f_name.endswith(".pyc"):
        f_name = f_name[:-1]
    cs = sorted(desc.fields["__init__"].call_sites.keys())
    assert len(cs) == 1
    assert len(cs[0]) == 1
    assert cs[0][0].filename == f_name
    assert cs[0][0].lineno == test_class.func_code.co_firstlineno + 4
    # method check
    assert sorted(desc.getfields()) == ["__init__", "exposed_method"]
    inputcells = desc.fields["exposed_method"].inputcells
    assert len(inputcells) == 4
    assert isinstance(inputcells[0], model.SomeInstance)
    # assert inputcells[0].classdef.classdesc.pyobj is SomeClass
    # XXX should work
    assert isinstance(inputcells[1], model.SomeInt)
    assert isinstance(inputcells[2], model.SomeFloat)
    assert isinstance(inputcells[3], model.SomeList)
    assert isinstance(desc.fields["exposed_method"].retval, model.SomeString)
    if 0:
        pds = PermaDocStorage(DocStorageAccessor(ds))
        assert pds.get_class_names() == ["AClass"]
        assert len(pds.get_function_signature("AClass.exposed_method")[0]) == 4