Skip to content

Commit

Permalink
pythongh-112192: Increase the trace module coverage precision to one …
Browse files Browse the repository at this point in the history
…decimal (python#126972)
  • Loading branch information
rruuaanng authored Dec 3, 2024
1 parent dabcecf commit 12397a5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_regrtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def test_coverage(self):
output = self.run_tests("--coverage", test)
self.check_executed_tests(output, [test], stats=1)
regex = (r'lines +cov% +module +\(path\)\n'
r'(?: *[0-9]+ *[0-9]{1,2}% *[^ ]+ +\([^)]+\)+)+')
r'(?: *[0-9]+ *[0-9]{1,2}\.[0-9]% *[^ ]+ +\([^)]+\)+)+')
self.check_line(output, regex)

def test_wait(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_issue9936(self):
coverage = {}
for line in stdout:
lines, cov, module = line.split()[:3]
coverage[module] = (int(lines), int(cov[:-1]))
coverage[module] = (float(lines), float(cov[:-1]))
# XXX This is needed to run regrtest.py as a script
modname = trace._fullmodname(sys.modules[modname].__file__)
self.assertIn(modname, coverage)
Expand Down Expand Up @@ -553,7 +553,7 @@ def f():
stdout = stdout.decode()
self.assertEqual(status, 0)
self.assertIn('lines cov% module (path)', stdout)
self.assertIn(f'6 100% {modulename} ({filename})', stdout)
self.assertIn(f'6 100.0% {modulename} ({filename})', stdout)

def test_run_as_module(self):
assert_python_ok('-m', 'trace', '-l', '--module', 'timeit', '-n', '1')
Expand Down
7 changes: 3 additions & 4 deletions Lib/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,13 @@ def write_results(self, show_missing=True, summary=False, coverdir=None, *,
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
sums[modulename] = n_lines, n_hits, modulename, filename

if summary and sums:
print("lines cov% module (path)")
for m in sorted(sums):
n_lines, percent, modulename, filename = sums[m]
print("%5d %3d%% %s (%s)" % sums[m])
n_lines, n_hits, modulename, filename = sums[m]
print(f"{n_lines:5d} {n_hits/n_lines:.1%} {modulename} ({filename})")

if self.outfile:
# try and store counts and module info into self.outfile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In the :mod:`trace` module, increase the coverage precision (``cov%``) to one decimal.

0 comments on commit 12397a5

Please sign in to comment.