[Python-checkins] r84996 - in python/branches/release27-maint: Lib/test/test_trace.py Lib/test/tracedmodules/testmod.py Lib/trace.py Misc/NEWS

alexander.belopolsky python-checkins at python.org
Fri Sep 24 20:14:18 CEST 2010


Author: alexander.belopolsky
Date: Fri Sep 24 20:14:18 2010
New Revision: 84996

Log:
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.
........


Modified:
   python/branches/release27-maint/   (props changed)
   python/branches/release27-maint/Lib/test/test_trace.py
   python/branches/release27-maint/Lib/test/tracedmodules/testmod.py
   python/branches/release27-maint/Lib/trace.py
   python/branches/release27-maint/Misc/NEWS

Modified: python/branches/release27-maint/Lib/test/test_trace.py
==============================================================================
--- python/branches/release27-maint/Lib/test/test_trace.py	(original)
+++ python/branches/release27-maint/Lib/test/test_trace.py	Fri Sep 24 20:14:18 2010
@@ -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__)

Modified: python/branches/release27-maint/Lib/test/tracedmodules/testmod.py
==============================================================================
--- python/branches/release27-maint/Lib/test/tracedmodules/testmod.py	(original)
+++ python/branches/release27-maint/Lib/test/tracedmodules/testmod.py	Fri Sep 24 20:14:18 2010
@@ -1,3 +1,9 @@
 def func(x):
     b = x + 1
     return b + 2
+
+def func2():
+    """Test function for issue 9936 """
+    return (1,
+            2,
+            3)

Modified: python/branches/release27-maint/Lib/trace.py
==============================================================================
--- python/branches/release27-maint/Lib/trace.py	(original)
+++ python/branches/release27-maint/Lib/trace.py	Fri Sep 24 20:14:18 2010
@@ -58,7 +58,7 @@
 import tokenize
 import inspect
 import gc
-
+import dis
 try:
     import cPickle
     pickle = cPickle
@@ -379,13 +379,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
-
-    lineno = code.co_firstlineno
-    for li in line_increments:
-        lineno += li
+    for _, lineno in dis.findlinestarts(code):
         if lineno not in strs:
             linenos[lineno] = 1
 

Modified: python/branches/release27-maint/Misc/NEWS
==============================================================================
--- python/branches/release27-maint/Misc/NEWS	(original)
+++ python/branches/release27-maint/Misc/NEWS	Fri Sep 24 20:14:18 2010
@@ -43,6 +43,8 @@
 Library
 -------
 
+- Issue #9936: Fixed executable lines' search in the trace module.
+
 - Issue #9928: Properly initialize the types exported by the bz2 module.
 
 - Issue #9854: The default read() implementation in io.RawIOBase now


More information about the Python-checkins mailing list