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

Function test_relative_time

tests/test_pysnooper.py:56–185  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55
56def test_relative_time():
57 snoop = pysnooper.snoop(relative_time=True, color=False)
58
59 def foo(x):
60 if x == 0:
61 bar1(x)
62 qux()
63 return
64
65 with snoop:
66 # There should be line entries for these three lines,
67 # no line entries for anything else in this function,
68 # but calls to all bar functions should be traced
69 foo(x - 1)
70 bar2(x)
71 qux()
72 int(4)
73 bar3(9)
74 return x
75
76 @snoop
77 def bar1(_x):
78 qux()
79
80 @snoop
81 def bar2(_x):
82 qux()
83
84 @snoop
85 def bar3(_x):
86 qux()
87
88 def qux():
89 time.sleep(0.1)
90 return 9 # not traced, mustn't show up
91
92 with mini_toolbox.OutputCapturer(stdout=False,
93 stderr=True) as output_capturer:
94 result = foo(2)
95 assert result == 2
96 output = output_capturer.string_io.getvalue()
97 assert_output(
98 output,
99 (
100 # In first with
101 SourcePathEntry(),
102 VariableEntry('x', '2'),
103 VariableEntry('bar1'),
104 VariableEntry('bar2'),
105 VariableEntry('bar3'),
106 VariableEntry('foo'),
107 VariableEntry('qux'),
108 VariableEntry('snoop'),
109 LineEntry('foo(x - 1)'),
110
111 # In with in recursive call
112 VariableEntry('x', '1'),
113 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