Index: Lib/trace.py =================================================================== --- Lib/trace.py (revision 66380) +++ Lib/trace.py (working copy) @@ -116,7 +116,7 @@ self._mods = modules or [] self._dirs = dirs or [] - self._dirs = map(os.path.normpath, self._dirs) + self._dirs = [os.path.normpath(d) for d in self._dirs] self._ignore = { '': 1 } def names(self, filename, modulename): @@ -367,9 +367,7 @@ """Return dict where keys are lines in the line number table.""" linenos = {} - line_increments = [ord(c) for c in code.co_lnotab[1::2]] - table_length = len(line_increments) - docstring = False + line_increments = code.co_lnotab[1::2] lineno = code.co_firstlineno for li in line_increments: Index: Lib/test/test_coverage.py =================================================================== --- Lib/test/test_coverage.py (revision 0) +++ Lib/test/test_coverage.py (revision 0) @@ -0,0 +1,45 @@ +# Testing the trace module + +from test.support import run_unittest, TESTFN, rmtree, unlink, captured_stdout +import unittest +import trace +import os, sys + +class TestCoverage(unittest.TestCase): + def tearDown(self): + rmtree(TESTFN) + unlink(TESTFN) + + def _coverage(self, tracer): + tracer.run('from test import test_pprint; test_pprint.test_main()') + r=tracer.results() + r.write_results(show_missing=True, summary=True, coverdir=TESTFN) + + def test_coverage(self): + tracer=trace.Trace(trace=0, count=1) + with captured_stdout() as stdout: + self._coverage(tracer) + stdout = stdout.getvalue() + self.assertTrue("pprint.py" in stdout) + self.assertTrue("unittest.py" in stdout) + files = os.listdir(TESTFN) + self.assertTrue("pprint.cover" in files) + self.assertTrue("unittest.cover" in files) + + def test_coverage_ignore(self): + # Ignore all files, nothing should be traced nor printed + tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], + trace=0, count=1) + with captured_stdout() as stdout: + self._coverage(tracer) + self.assertEquals(stdout.getvalue(), "") + if os.path.exists(TESTFN): + files = os.listdir(TESTFN) + self.assertEquals(files, []) + + +def test_main(): + run_unittest(__name__) + +if __name__ == "__main__": + test_main() Index: Lib/test/test_cmd.py =================================================================== --- Lib/test/test_cmd.py (revision 66380) +++ Lib/test/test_cmd.py (working copy) @@ -173,7 +173,7 @@ def test_coverage(coverdir): tracer=trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0, count=1) - tracer.run('reload(cmd);test_main()') + tracer.run('import imp; imp.reload(cmd);test_main()') r=tracer.results() print("Writing coverage results...") r.write_results(show_missing=True, summary=True, coverdir=coverdir)