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

Function test_multi_thread_info

tests/test_pysnooper.py:219–300  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

217
218
219def test_multi_thread_info():
220
221 @pysnooper.snoop(thread_info=True, color=False)
222 def my_function(foo):
223 x = 7
224 y = 8
225 return y + x
226
227 def parse_call_content(line):
228 return line.split('{event:9} '.format(event='call'))[-1]
229
230 with mini_toolbox.OutputCapturer(stdout=False,
231 stderr=True) as output_capturer:
232 my_function('baba')
233 t1 = threading.Thread(target=my_function, name="test123",args=['bubu'])
234 t1.start()
235 t1.join()
236 t1 = threading.Thread(target=my_function, name="bibi",args=['bibi'])
237 t1.start()
238 t1.join()
239 output = output_capturer.string_io.getvalue()
240 calls = [line for line in output.split("\n") if "call" in line]
241 main_thread = calls[0]
242 assert parse_call_content(main_thread) == parse_call_content(calls[1])
243 assert parse_call_content(main_thread) == parse_call_content(calls[2])
244 thread_info_regex = '([0-9]+-{name}+[ ]+)'
245 assert_output(
246 output,
247 (
248 SourcePathEntry(),
249 VariableEntry('foo', value_regex="u?'baba'"),
250 CallEntry('def my_function(foo):',
251 thread_info_regex=thread_info_regex.format(
252 name="MainThread")),
253 LineEntry('x = 7',
254 thread_info_regex=thread_info_regex.format(
255 name="MainThread")),
256 VariableEntry('x', '7'),
257 LineEntry('y = 8',
258 thread_info_regex=thread_info_regex.format(
259 name="MainThread")),
260 VariableEntry('y', '8'),
261 LineEntry('return y + x',
262 thread_info_regex=thread_info_regex.format(
263 name="MainThread")),
264 ReturnEntry('return y + x'),
265 ReturnValueEntry('15'),
266 ElapsedTimeEntry(),
267 VariableEntry('foo', value_regex="u?'bubu'"),
268 CallEntry('def my_function(foo):',
269 thread_info_regex=thread_info_regex.format(
270 name="test123")),
271 LineEntry('x = 7',
272 thread_info_regex=thread_info_regex.format(
273 name="test123")),
274 VariableEntry('x', '7'),
275 LineEntry('y = 8',
276 thread_info_regex=thread_info_regex.format(

Callers

nothing calls this directly

Calls 10

my_functionFunction · 0.85
parse_call_contentFunction · 0.85
assert_outputFunction · 0.85
SourcePathEntryClass · 0.85
VariableEntryClass · 0.85
CallEntryClass · 0.85
LineEntryClass · 0.85
ReturnEntryClass · 0.85
ReturnValueEntryClass · 0.85
ElapsedTimeEntryClass · 0.85

Tested by

no test coverage detected