Commit 402392bd authored by Alexander Belopolsky's avatar Alexander Belopolsky

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.
........
parent a4c8ecd3
...@@ -166,7 +166,6 @@ class TestLineCounts(unittest.TestCase): ...@@ -166,7 +166,6 @@ class TestLineCounts(unittest.TestCase):
} }
self.assertEqual(tracer.results().counts, expected) self.assertEqual(tracer.results().counts, expected)
class TestRunExecCounts(unittest.TestCase): class TestRunExecCounts(unittest.TestCase):
"""A simple sanity test of line-counting, via runctx (exec)""" """A simple sanity test of line-counting, via runctx (exec)"""
def setUp(self): def setUp(self):
...@@ -263,8 +262,9 @@ class TestCoverage(unittest.TestCase): ...@@ -263,8 +262,9 @@ class TestCoverage(unittest.TestCase):
rmtree(TESTFN) rmtree(TESTFN)
unlink(TESTFN) unlink(TESTFN)
def _coverage(self, tracer): def _coverage(self, tracer,
tracer.run('from test import test_pprint; test_pprint.test_main()') cmd='from test import test_pprint; test_pprint.test_main()'):
tracer.run(cmd)
r = tracer.results() r = tracer.results()
r.write_results(show_missing=True, summary=True, coverdir=TESTFN) r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
...@@ -291,6 +291,25 @@ class TestCoverage(unittest.TestCase): ...@@ -291,6 +291,25 @@ class TestCoverage(unittest.TestCase):
files = os.listdir(TESTFN) files = os.listdir(TESTFN)
self.assertEquals(files, []) 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(): def test_main():
run_unittest(__name__) run_unittest(__name__)
......
def func(x): def func(x):
b = x + 1 b = x + 1
return b + 2 return b + 2
def func2():
"""Test function for issue 9936 """
return (1,
2,
3)
...@@ -59,7 +59,7 @@ import token ...@@ -59,7 +59,7 @@ import token
import tokenize import tokenize
import inspect import inspect
import gc import gc
import dis
import pickle import pickle
def usage(outfile): def usage(outfile):
...@@ -376,13 +376,7 @@ def find_lines_from_code(code, strs): ...@@ -376,13 +376,7 @@ def find_lines_from_code(code, strs):
"""Return dict where keys are lines in the line number table.""" """Return dict where keys are lines in the line number table."""
linenos = {} linenos = {}
line_increments = code.co_lnotab[1::2] for _, lineno in dis.findlinestarts(code):
table_length = len(line_increments)
docstring = False
lineno = code.co_firstlineno
for li in line_increments:
lineno += li
if lineno not in strs: if lineno not in strs:
linenos[lineno] = 1 linenos[lineno] = 1
......
...@@ -121,6 +121,8 @@ C-API ...@@ -121,6 +121,8 @@ C-API
Library Library
------- -------
- Issue #9936: Fixed executable lines' search in the trace module.
- Issue #9928: Properly initialize the types exported by the bz2 module. - Issue #9928: Properly initialize the types exported by the bz2 module.
- Issue #9854: The default read() implementation in io.RawIOBase now - Issue #9854: The default read() implementation in io.RawIOBase now
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment