コード例 #1
0
def construct_dynamic_graph(src):
    lifted = astunparse.unparse(expr_lifter.lift_expressions(src))
    tracer = dynamic_tracer.DynamicDataTracer(loop_bound=None)
    tracer.run(lifted)
    grapher = graph_builder.DynamicTraceToGraph(
        ignore_unknown=True,
        memory_refinement=graph_builder.MemoryRefinementStrategy.IGNORE_BASE)
    graph = grapher.run(tracer)
    return graph
コード例 #2
0
def test_function_called_by_user():
    tracer = dt.DynamicDataTracer()
    tracer.file_path = __file__
    helper = BasicTracer(tracer._called_by_user, trace_inside_call=True)
    import pandas as pd
    with helper:
        pd.DataFrame([(1, 2)])
    assert helper.result_acc[0] and (
        not helper.result_acc[1]
    ), 'First is call made by user, second is not (its call to np._amax in np source)'
コード例 #3
0
def test_basic_programs(_input_fun):
    test_inputs = _input_fun()
    if len(test_inputs) == 2:
        src, expected_checks = test_inputs
        loop_bound = None
    else:
        src, expected_checks, loop_bound = test_inputs

    tracer = dt.DynamicDataTracer(loop_bound=loop_bound)
    src = textwrap.dedent(src)
    tracer.run(src)

    print(list(map(str, tracer.trace_events)))
    assert len(tracer.trace_events) == len(
        expected_checks), 'The event and checks are mismatched.'
    for event, check in zip(tracer.trace_events, expected_checks):
        check(event)
コード例 #4
0
def test_function_defined_by_user():
    # make tracer think current file is user file
    tracer = dt.DynamicDataTracer()
    tracer.file_path = __file__
    helper = BasicTracer(tracer._defined_by_user)
    with helper:

        def f():
            return 2

        f()
    assert helper.result_acc[0], 'Function was defined by user in test file'

    helper.clear()
    with helper:
        # calling any function that defined by us in this file
        ast.parse('1')
    assert not helper.result_acc[
        0], 'Function was not defined by user in this test file'
コード例 #5
0
def test_get_load_references_from_line(_input, expected):
    tracer = dt.DynamicDataTracer()
    refs = tracer.get_load_references_from_line(_input)
    assert refs == set(expected), 'Load references do not match'