示例#1
0
def test_callprinter_indent(LineMatcher):
    from sample6 import bar
    out = StringIO()
    with trace(action=CallPrinter(stream=out)):
        bar()

    lm = LineMatcher(out.getvalue().splitlines())
    lm.fnmatch_lines([
        "*sample6.py:1     call      => bar()",
        "*sample6.py:2     line         foo()",
        "*sample6.py:5     call         => foo()",
        "*sample6.py:6     line            try:",
        "*sample6.py:7     line            asdf()",
        "*sample6.py:16    call            => asdf()",
        "*sample6.py:17    line               raise Exception()",
        "*sample6.py:17    exception        ! asdf: (<*Exception'>, Exception(), <traceback object at *>)",
        "*sample6.py:17    return          <= asdf: None",
        "*sample6.py:7     exception     ! foo: (<*Exception'>, Exception(), <traceback object at *>)",
        "*sample6.py:8     line            except:",
        "*sample6.py:9     line            pass",
        "*sample6.py:10    line            try:",
        "*sample6.py:11    line            asdf()",
        "*sample6.py:16    call            => asdf()",
        "*sample6.py:17    line               raise Exception()",
        "*sample6.py:17    exception        ! asdf: (<*Exception'>, Exception(), <traceback object at *>)",
        "*sample6.py:17    return          <= asdf: None",
        "*sample6.py:11    exception     ! foo: (<*Exception'>, Exception(), <traceback object at *>)",
        "*sample6.py:12    line            except:",
        "*sample6.py:13    line            pass",
        "*sample6.py:13    return       <= foo: None",
        "*sample6.py:2     return    <= bar: None",
    ])
示例#2
0
def test_tracing_reinstall(LineMatcher):
    lines = StringIO()
    with hunter.trace(CodePrinter(stream=lines)):

        def foo():
            a = 2
            sys.settrace(sys.gettrace())
            a = 3

        def bar():
            a = 1
            foo()
            a = 4

        bar()
    print(lines.getvalue())
    lm = LineMatcher(lines.getvalue().splitlines())
    lm.fnmatch_lines([
        "*test_hunter.py:*   call              def bar():",
        "*test_hunter.py:*   line                  a = 1",
        "*test_hunter.py:*   line                  foo()",
        "*test_hunter.py:*   call              def foo():",
        "*test_hunter.py:*   line                  a = 2",
        "*test_hunter.py:*   line                  sys.settrace(sys.gettrace())",
        "*test_hunter.py:*   line                  a = 3",
        "*test_hunter.py:*   return                a = 3",
        "*                   ...       return value: None",
        "*test_hunter.py:*   line                  a = 4",
        "*test_hunter.py:*   return                a = 4",
        "*                   ...       return value: None",
    ])
示例#3
0
 def foo():
     gen = bar()
     next(gen)
     while True:
         try:
             gen.send('foo')
         except StopIteration:
             break
     list(i for i in range(2))
     x = [i for i in range(2)]
示例#4
0
 def foo():
     bar()
     return 1