Пример #1
0
def test_depth_limit(LineMatcher, tracer_impl, depth):
    buff = StringIO()
    from sample7 import one
    tracer = tracer_impl()
    predicate = When(Q(depth_lt=depth), CallPrinter(stream=buff))
    try:
        tracer.trace(predicate)
        one()
    finally:
        tracer.stop()
    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "* call      => one()",
        "* line         for i in range(1):  # one",
        "* line         two()",
        "* call         => two()",
        "* return       <= two: None",
        "* line         for i in range(1):  # one",
        "* return    <= one: None",
    ])
    if depth < 3:
        assert 'three' not in output
    if depth < 4:
        assert 'four' not in output
    if depth < 5:
        assert 'five' not in output
Пример #2
0
def test_stack_printer(LineMatcher):
    buff = StringIO()
    with trace(Q(function="five", action=StackPrinter(stream=buff))):
        from sample7 import one
        one()

    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "*sample7.py:30:five <= no frames available (detached=True)",
    ])
def test_stack_printer_2(LineMatcher):
    buff = StringIO()
    with trace(Q(function="five", action=StackPrinter(limit=2, stream=buff))):
        from sample7 import one
        one()

    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "*sample7.py:??:five <= tests/sample7.py:??:four <= tests/sample7.py:??:three <= tests/sample7.py:??:two <= tests/sample7.py:?:one <= tests/test_integration.py:???:test_stack_printer*",
    ])
Пример #4
0
def test_from_predicate_line_no_predicate(LineMatcher):
    buff = StringIO()
    from sample7 import one
    with trace(From(Q(fullsource_has='in_five')), action=CallPrinter(stream=buff)):
        one()
    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "* line *    for i in range(1):  # five",
        "* line *    return i",
    ])
    assert 'four' not in output
    assert 'three' not in output
    assert 'two' not in output
    assert 'one' not in output
Пример #5
0
def test_from_predicate(LineMatcher):
    buff = StringIO()
    from sample7 import one
    with trace(From(Q(function='five'), CallPrinter(stream=buff))):
        one()
    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "* call      => five()",
        "* line         for i in range(1):  # five",
        "* line         return i",
        "* return    <= five: 0",
    ])
    assert 'four' not in output
    assert 'three' not in output
    assert 'two' not in output
    assert 'one' not in output
Пример #6
0
def test_from_predicate_with_subpredicate(LineMatcher):
    buff = StringIO()
    from sample7 import one
    with trace(From(Q(source_has='# two'), Q(depth_lt=1)), action=CallPrinter(stream=buff)):
        one()
    output = buff.getvalue()
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        '* line      for i in range(1):  # two',
        '* line      three()',
        '* call      => three()',
        '* return    <= three: None',
        '* line      for i in range(1):  # two',
    ])
    assert 'five' not in output
    assert 'four' not in output
    assert 'one()' not in output
    assert '# one' not in output
    assert len(lm.lines) == 5
def test_backlog(LineMatcher, stack):
    buff = StringIO()
    from sample7args import one
    with trace(Backlog(fullsource_has='return i',
                       size=19,
                       stack=stack,
                       vars=False,
                       action=DebugCallPrinter(
                           ' ['
                           'backlog'
                           ']', stream=buff)).filter(~Q(function='six')),
               action=DebugCallPrinter(stream=buff)):
        one()
        one(
        )  # make sure Backlog is reusable (doesn't have storage side-effects)
    output = buff.getvalue()
    import re
    print(re.sub(r'([\[\]])', r'[\1]', output))
    # print(output)
    lm = LineMatcher(output.splitlines())
    lm.fnmatch_lines([
        "depth=0 calls=-1 *sample7args.py:*   call      => one(a=?, b=?, c=?) [[]backlog[]]",
        "depth=1 calls=?? *sample7args.py:*   line         two() [[]backlog[]]",
        "depth=1 calls=?? *sample7args.py:*   call         => two(a=?, b=?, c=?) [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            for i in range(1):  # two [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            three() [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   call            => three(a=?, b=?, c=?) [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               for i in range(1):  # three [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               four() [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   call               => four(a=?, b=?, c=?) [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  for i in range(1):  # four [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  five() [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   call                  => five(a=?, b=?, c=?) [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     a = b = c[[]'side'[]] = in_five = 'effect' [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     for i in range(1):  # five [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     return i  # five",
        "depth=4 calls=?? *sample7args.py:*   return                <= five: 0",
        "depth=0 calls=-1 *sample7args.py:*   call      => one(a=?, b=?, c=?) [[]backlog[]]",
        "depth=1 calls=?? *sample7args.py:*   line         two() [[]backlog[]]",
        "depth=1 calls=?? *sample7args.py:*   call         => two(a=?, b=?, c=?) [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            for i in range(1):  # two [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   line            three() [[]backlog[]]",
        "depth=2 calls=?? *sample7args.py:*   call            => three(a=?, b=?, c=?) [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               for i in range(1):  # three [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   line               four() [[]backlog[]]",
        "depth=3 calls=?? *sample7args.py:*   call               => four(a=?, b=?, c=?) [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  for i in range(1):  # four [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  a = b = c[[]'side'[]] = 'effect' [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   line                  five() [[]backlog[]]",
        "depth=4 calls=?? *sample7args.py:*   call                  => five(a=?, b=?, c=?) [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     six() [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     a = b = c[[]'side'[]] = in_five = 'effect' [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     for i in range(1):  # five [[]backlog[]]",
        "depth=5 calls=?? *sample7args.py:*   line                     return i  # five",
        "depth=4 calls=?? *sample7args.py:*   return                <= five: 0",
    ])