aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonan Lamy <ronan.lamy@gmail.com>2019-08-02 18:03:38 +0100
committerRonan Lamy <ronan.lamy@gmail.com>2019-08-02 18:03:38 +0100
commite85a213f4b603b90ead7014092a610910418d79a (patch)
treee225e89eda45be45cd6a2e6cb298e91a3750b068 /lib-python/3/trace.py
parentFix v3.6.1 import so that the process described in stdlib-upgrade.txt works a... (diff)
downloadpypy-e85a213f4b603b90ead7014092a610910418d79a.tar.gz
pypy-e85a213f4b603b90ead7014092a610910418d79a.tar.bz2
pypy-e85a213f4b603b90ead7014092a610910418d79a.zip
Update to git tag v3.6.9
Diffstat (limited to 'lib-python/3/trace.py')
-rwxr-xr-xlib-python/3/trace.py45
1 files changed, 19 insertions, 26 deletions
diff --git a/lib-python/3/trace.py b/lib-python/3/trace.py
index ae154615fa..e5fa94fc94 100755
--- a/lib-python/3/trace.py
+++ b/lib-python/3/trace.py
@@ -79,9 +79,6 @@ else:
PRAGMA_NOCOVER = "#pragma NO COVER"
-# Simple rx to find lines with no code.
-rx_blank = re.compile(r'^\s*(#.*)?$')
-
class _Ignore:
def __init__(self, modules=None, dirs=None):
self._mods = set() if not modules else set(modules)
@@ -284,16 +281,15 @@ class CoverageResults:
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:
@@ -312,11 +308,12 @@ class CoverageResults:
def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
"""Return a coverage results file in path."""
+ # ``lnotab`` is a dict of executable lines, or a line number "table"
try:
outfile = open(path, "w", encoding=encoding)
except OSError as err:
- print(("trace: Could not open %r for writing: %s"
+ print(("trace: Could not open %r for writing: %s "
"- skipping" % (path, err)), file=sys.stderr)
return 0, 0
@@ -330,17 +327,13 @@ class CoverageResults:
outfile.write("%5d: " % lines_hit[lineno])
n_hits += 1
n_lines += 1
- elif rx_blank.match(line):
- outfile.write(" ")
- else:
- # lines preceded by no marks weren't hit
- # Highlight them if so indicated, unless the line contains
+ elif lineno in lnotab and not PRAGMA_NOCOVER in line:
+ # Highlight never-executed lines, unless the line contains
# #pragma: NO COVER
- if lineno in lnotab and not PRAGMA_NOCOVER in line:
- outfile.write(">>>>>> ")
- n_lines += 1
- else:
- outfile.write(" ")
+ outfile.write(">>>>>> ")
+ n_lines += 1
+ else:
+ outfile.write(" ")
outfile.write(line.expandtabs(8))
return n_hits, n_lines
@@ -662,7 +655,7 @@ def main():
grp = parser.add_argument_group('Filters',
'Can be specified multiple times')
grp.add_argument('--ignore-module', action='append', default=[],
- help='Ignore the given module(s) and its submodules'
+ help='Ignore the given module(s) and its submodules '
'(if it is a package). Accepts comma separated list of '
'module names.')
grp.add_argument('--ignore-dir', action='append', default=[],
@@ -710,7 +703,7 @@ def main():
if opts.filename is None:
parser.error('filename is missing: required with the main options')
- sys.argv = opts.filename, *opts.arguments
+ sys.argv = [opts.filename, *opts.arguments]
sys.path[0] = os.path.dirname(opts.filename)
t = Trace(opts.count, opts.trace, countfuncs=opts.listfuncs,