MCPcopy
hub / github.com/cool-RR/PySnooper / test_with_block

Function test_with_block

tests/test_pysnooper.py:1006–1136  ·  view source on GitHub ↗
(normalize)

Source from the content-addressed store, hash-verified

1004
1005@pytest.mark.parametrize("normalize", (True, False))
1006def test_with_block(normalize):
1007 # Testing that a single Tracer can handle many mixed uses
1008 snoop = pysnooper.snoop(normalize=normalize, color=False)
1009
1010 def foo(x):
1011 if x == 0:
1012 bar1(x)
1013 qux()
1014 return
1015
1016 with snoop:
1017 # There should be line entries for these three lines,
1018 # no line entries for anything else in this function,
1019 # but calls to all bar functions should be traced
1020 foo(x - 1)
1021 bar2(x)
1022 qux()
1023 int(4)
1024 bar3(9)
1025 return x
1026
1027 @snoop
1028 def bar1(_x):
1029 qux()
1030
1031 @snoop
1032 def bar2(_x):
1033 qux()
1034
1035 @snoop
1036 def bar3(_x):
1037 qux()
1038
1039 def qux():
1040 return 9 # not traced, mustn't show up
1041
1042 with mini_toolbox.OutputCapturer(stdout=False,
1043 stderr=True) as output_capturer:
1044 result = foo(2)
1045 assert result == 2
1046 output = output_capturer.string_io.getvalue()
1047 assert_output(
1048 output,
1049 (
1050 # In first with
1051 SourcePathEntry(),
1052 VariableEntry('x', '2'),
1053 VariableEntry('bar1'),
1054 VariableEntry('bar2'),
1055 VariableEntry('bar3'),
1056 VariableEntry('foo'),
1057 VariableEntry('qux'),
1058 VariableEntry('snoop'),
1059 LineEntry('foo(x - 1)'),
1060
1061 # In with in recursive call
1062 VariableEntry('x', '1'),
1063 VariableEntry('bar1'),

Callers

nothing calls this directly

Calls 9

assert_outputFunction · 0.85
SourcePathEntryClass · 0.85
VariableEntryClass · 0.85
LineEntryClass · 0.85
CallEntryClass · 0.85
ReturnEntryClass · 0.85
ReturnValueEntryClass · 0.85
ElapsedTimeEntryClass · 0.85
fooFunction · 0.70

Tested by

no test coverage detected