Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Lib/test/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,31 @@ def test_cover_files_written_no_highlight(self):
" print('unreachable')\n"
)

def test_summary_without_missing(self):
for options in ([], ['--missing']):
with self.subTest(options=options):
_, stdout, _ = assert_python_ok(
'-m', 'trace', '--count', '--summary', *options, self.codefile)
self.assertIn(b'3 66.7%', stdout)
with open(self.coverfile, encoding='iso-8859-15') as f:
self.assertEqual('>>>>>>' in f.read(), bool(options))

def test_summary_preserves_results_file_override(self):
seen = []

class Results(trace.CoverageResults):
def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
seen.append(bool(lnotab))
return super().write_results_file(path, lines, lnotab, lines_hit, encoding)

counts = {(self.codefile, 2): 1, (self.codefile, 3): 1}
results = Results(counts)
results.write_results()
with captured_stdout() as stdout:
results.write_results(show_missing=False, summary=True)
self.assertEqual(seen, [True, False])
self.assertIn('3 66.7%', stdout.getvalue())

def test_cover_files_written_with_highlight(self):
argv = '-m trace --count --missing'.split() + [self.codefile]
status, stdout, stderr = assert_python_ok(*argv)
Expand Down
7 changes: 7 additions & 0 deletions Lib/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +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:
if not show_missing:
executable = _find_executable_linenos(filename)
n_lines += sum(
lineno in executable and lineno not in count
and PRAGMA_NOCOVER not in line
for lineno, line in enumerate(source, 1)
)
sums[modulename] = n_lines, n_hits, modulename, filename

if summary and sums:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix coverage percentages reported by :mod:`trace` when
:option:`!--summary` is used without :option:`!--missing`.
Loading