def test_exec_counts(self):
self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0)
code = r'''traced_func_loop(2, 5)'''
code = compile(code, __file__, 'exec')
self.tracer.runctx(code, globals(), vars())
firstlineno = get_firstlineno(traced_func_loop)
expected = {
(self.my_py_filename, firstlineno + 1): 1,
(self.my_py_filename, firstlineno + 2): 6,
(self.my_py_filename, firstlineno + 3): 5,
(self.my_py_filename, firstlineno + 4): 1,
}
# When used through 'run', some other spurious counts are produced, like
# the settrace of threading, which we ignore, just making sure that the
# counts fo traced_func_loop were right.
#
for k in expected.keys():
self.assertEqual(self.tracer.results().counts[k], expected[k])
评论列表
文章目录