class TestRunExecCounts(unittest.TestCase): """A simple sanity test of line-counting, via runctx (exec)""" def setUp(self): self.my_py_filename = fix_ext_py(__file__) self.addCleanup(sys.settrace, sys.gettrace()) 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])
class TestRunExecCounts(unittest.TestCase): """A simple sanity test of line-counting, via runctx (exec)""" def setUp(self): self.my_py_filename = fix_ext_py(__file__) self.addCleanup(sys.settrace, sys.gettrace()) def test_exec_counts(self): self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0) code = '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 } for k in expected.keys(): self.assertEqual(self.tracer.results().counts[k], expected[k])