Skip to content

Commit 3ff14b1

Browse files
committed
feat: function/class index pages skip covered if told to
1 parent 7235b80 commit 3ff14b1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

coverage/html.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def report(self, morfs: Iterable[TMorf] | None) -> float:
282282

283283
for fr, analysis in get_analysis_to_report(self.coverage, morfs):
284284
ftr = FileToReport(fr, analysis)
285-
if self.should_report_file(ftr):
285+
if self.should_report(analysis):
286286
files_to_report.append(ftr)
287287
else:
288288
file_be_gone(os.path.join(self.directory, ftr.html_filename))
@@ -340,10 +340,10 @@ def make_local_static_report_files(self) -> None:
340340
assert self.config.extra_css is not None
341341
shutil.copyfile(self.config.extra_css, os.path.join(self.directory, self.extra_css))
342342

343-
def should_report_file(self, ftr: FileToReport) -> bool:
344-
"""Determine if we'll report this file."""
343+
def should_report(self, analysis: Analysis) -> bool:
344+
"""Determine if we'll report this file or region."""
345345
# Get the numbers for this file.
346-
nums = ftr.analysis.numbers
346+
nums = analysis.numbers
347347
self.all_files_nums.append(nums)
348348

349349
if self.skip_covered:
@@ -510,10 +510,13 @@ class PageData:
510510
)
511511

512512
for region in region_list:
513-
if not region.lines:
514-
continue
515513
outside_lines -= region.lines
516514
analysis = ftr.analysis.narrow(region.lines)
515+
# TODO: should_report updates counts that could instead be
516+
# collected in PageData, and PageData could be used for
517+
# index.html also.
518+
if not self.should_report(analysis):
519+
continue
517520
region_kinds[noun].summaries.append(IndexInfo(
518521
url=f"{ftr.html_filename}#t{region.start}",
519522
description=f"{ftr.fr.relative_filename()}:{region.name}",
@@ -522,12 +525,13 @@ class PageData:
522525
region_kinds[noun].totals += analysis.numbers
523526

524527
analysis = ftr.analysis.narrow(outside_lines)
525-
region_kinds[noun].summaries.append(IndexInfo(
526-
url=ftr.html_filename,
527-
description=f"{ftr.fr.relative_filename()} (no {noun})",
528-
nums=analysis.numbers,
529-
))
530-
region_kinds[noun].totals += analysis.numbers
528+
if self.should_report(analysis):
529+
region_kinds[noun].summaries.append(IndexInfo(
530+
url=ftr.html_filename,
531+
description=f"{ftr.fr.relative_filename()} (no {noun})",
532+
nums=analysis.numbers,
533+
))
534+
region_kinds[noun].totals += analysis.numbers
531535

532536
for noun, region_data in region_kinds.items():
533537
html = index_tmpl.render({

0 commit comments

Comments
 (0)