Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_trace.py @ 64926:12e0dffef7bd 2.7
Merged revisions 84994 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r84994 | alexander.belopolsky | 2010-09-24 14:03:12 -0400 (Fri, 24 Sep 2010) | 1 line
Issue #9936: Fixed executable lines' search in the trace module.
........
| author | Alexander Belopolsky <alexander.belopolsky@gmail.com> |
|---|---|
| date | Fri, 24 Sep 2010 18:14:18 +0000 |
| parents | 205ff2b02c77 |
| children | 05c58b3d6d39 |
line wrap: on
line diff
--- a/Lib/test/test_trace.py Thu Sep 23 19:55:24 2010 +0000 +++ b/Lib/test/test_trace.py Fri Sep 24 18:14:18 2010 +0000 @@ -186,7 +186,6 @@ } self.assertEqual(tracer.results().counts, expected) - class TestRunExecCounts(unittest.TestCase): """A simple sanity test of line-counting, via runctx (exec)""" def setUp(self): @@ -283,8 +282,9 @@ rmtree(TESTFN) unlink(TESTFN) - def _coverage(self, tracer): - tracer.run('from test import test_pprint; test_pprint.test_main()') + def _coverage(self, tracer, + cmd='from test import test_pprint; test_pprint.test_main()'): + tracer.run(cmd) r = tracer.results() r.write_results(show_missing=True, summary=True, coverdir=TESTFN) @@ -311,6 +311,25 @@ files = os.listdir(TESTFN) self.assertEquals(files, []) + def test_issue9936(self): + tracer = trace.Trace(trace=0, count=1) + modname = 'test.tracedmodules.testmod' + # Ensure that the module is executed in import + if modname in sys.modules: + del sys.modules[modname] + cmd = ("import test.tracedmodules.testmod as t;" + "t.func(0); t.func2();") + with captured_stdout() as stdout: + self._coverage(tracer, cmd) + stdout.seek(0) + stdout.readline() + coverage = {} + for line in stdout: + lines, cov, module = line.split()[:3] + coverage[module] = (int(lines), int(cov[:-1])) + self.assertIn(modname, coverage) + self.assertEqual(coverage[modname], (5, 100)) + def test_main(): run_unittest(__name__)
