[Python-checkins] cpython: Fixes #10541: regrtest -T is broken

alexander.belopolsky python-checkins at python.org
Sun Jun 29 23:56:40 CEST 2014


http://hg.python.org/cpython/rev/10cf594ace4b
changeset: 91467:10cf594ace4b
parent: 91464:394e6bda5a70
user: Alexander Belopolsky <alexander.belopolsky at gmail.com>
date: Sun Jun 29 17:44:05 2014 -0400
summary:
 Fixes #10541: regrtest -T is broken
 * makes test_trace tests restore the tracefunc after they run
 * write_results() in trace module will not terminate if lnotab
 cannot be found.
files:
 Lib/test/test_trace.py | 6 +++++-
 Lib/trace.py | 19 ++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -10,7 +10,6 @@
 
 from test.tracedmodules import testmod
 
-
 #------------------------------- Utilities -----------------------------------#
 
 def fix_ext_py(filename):
@@ -224,6 +223,11 @@
 self.addCleanup(sys.settrace, sys.gettrace())
 self.tracer = Trace(count=0, trace=0, countfuncs=1)
 self.filemod = my_file_and_modname()
+ self._saved_tracefunc = sys.gettrace()
+
+ def tearDown(self):
+ if self._saved_tracefunc is not None:
+ sys.settrace(self._saved_tracefunc)
 
 def test_simple_caller(self):
 self.tracer.runfunc(traced_func_simple_caller, 1)
diff --git a/Lib/trace.py b/Lib/trace.py
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -326,16 +326,17 @@
 lnotab = _find_executable_linenos(filename)
 else:
 lnotab = {}
+ if lnotab:
+ source = linecache.getlines(filename)
+ coverpath = os.path.join(dir, modulename + ".cover")
+ with open(filename, 'rb') as fp:
+ encoding, _ = tokenize.detect_encoding(fp.readline)
+ n_hits, n_lines = self.write_results_file(coverpath, source,
+ lnotab, count, encoding)
+ if summary and n_lines:
+ percent = int(100 * n_hits / n_lines)
+ sums[modulename] = n_lines, percent, modulename, filename
 
- source = linecache.getlines(filename)
- coverpath = os.path.join(dir, modulename + ".cover")
- with open(filename, 'rb') as fp:
- encoding, _ = tokenize.detect_encoding(fp.readline)
- n_hits, n_lines = self.write_results_file(coverpath, source,
- lnotab, count, encoding)
- if summary and n_lines:
- percent = int(100 * n_hits / n_lines)
- sums[modulename] = n_lines, percent, modulename, filename
 
 if summary and sums:
 print("lines cov% module (path)")
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /