diff options
author | Ronan Lamy <ronan.lamy@gmail.com> | 2019-08-02 20:15:18 +0100 |
---|---|---|
committer | Ronan Lamy <ronan.lamy@gmail.com> | 2019-08-02 20:15:18 +0100 |
commit | 0da88c389c29d654211290b5c9dbd9684d2cd007 (patch) | |
tree | 2f90a83b9c0810d1f6c76e46edac8aa8caa317d8 /lib-python/3/trace.py | |
parent | Merge again from vendor/stdlib branch @ v3.6.1 (diff) | |
parent | Update to git tag v3.6.9 (diff) | |
download | pypy-0da88c389c29d654211290b5c9dbd9684d2cd007.tar.gz pypy-0da88c389c29d654211290b5c9dbd9684d2cd007.tar.bz2 pypy-0da88c389c29d654211290b5c9dbd9684d2cd007.zip |
Update stdlib to 3.6.9
Diffstat (limited to 'lib-python/3/trace.py')
-rwxr-xr-x | lib-python/3/trace.py | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/lib-python/3/trace.py b/lib-python/3/trace.py index 94a7e0b878..ce33715abc 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) @@ -289,16 +286,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: @@ -317,11 +313,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 @@ -335,17 +332,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 @@ -671,7 +664,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=[], @@ -719,7 +712,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, |