Skip to content

Commit

Permalink
fix: json report needs 'no class' and 'no function' also
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jul 11, 2024
1 parent e47e7e7 commit 92d96b9
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 156 deletions.
61 changes: 37 additions & 24 deletions coverage/jsonreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,35 +126,48 @@ def report_one_file(
_convert_branch_arcs(analysis.missing_branch_arcs()),
)

for region in file_reporter.code_regions():
if region.kind not in reported_file:
reported_file[region.kind] = {}
num_lines = len(file_reporter.source().splitlines())
num_lines = len(file_reporter.source().splitlines())
for noun, plural in file_reporter.code_region_kinds():
reported_file[plural] = region_data = {}
outside_lines = set(range(1, num_lines + 1))
outside_lines -= region.lines
narrowed_analysis = analysis.narrow(region.lines)
narrowed_nums = narrowed_analysis.numbers
narrowed_summary = self.make_summary(narrowed_nums)
reported_file[region.kind][region.name] = {
"executed_lines": sorted(narrowed_analysis.executed),
"summary": narrowed_summary,
"missing_lines": sorted(narrowed_analysis.missing),
"excluded_lines": sorted(narrowed_analysis.excluded),
}
if self.config.json_show_contexts:
contexts = coverage_data.contexts_by_lineno(narrowed_analysis.filename)
reported_file[region.kind][region.name]["contexts"] = contexts
if coverage_data.has_arcs():
narrowed_summary.update(self.make_branch_summary(narrowed_nums))
reported_file[region.kind][region.name]["executed_branches"] = list(
_convert_branch_arcs(narrowed_analysis.executed_branch_arcs()),
)
reported_file[region.kind][region.name]["missing_branches"] = list(
_convert_branch_arcs(narrowed_analysis.missing_branch_arcs()),
for region in file_reporter.code_regions():
if region.kind != noun:
continue
outside_lines -= region.lines
region_data[region.name] = self.make_region_data(
coverage_data,
analysis.narrow(region.lines),
)

region_data[""] = self.make_region_data(
coverage_data,
analysis.narrow(outside_lines),
)
return reported_file

def make_region_data(self, coverage_data: CoverageData, narrowed_analysis: Analysis) -> JsonObj:
"""Create the data object for one region of a file."""
narrowed_nums = narrowed_analysis.numbers
narrowed_summary = self.make_summary(narrowed_nums)
this_region = {
"executed_lines": sorted(narrowed_analysis.executed),
"summary": narrowed_summary,
"missing_lines": sorted(narrowed_analysis.missing),
"excluded_lines": sorted(narrowed_analysis.excluded),
}
if self.config.json_show_contexts:
contexts = coverage_data.contexts_by_lineno(narrowed_analysis.filename)
this_region["contexts"] = contexts
if coverage_data.has_arcs():
narrowed_summary.update(self.make_branch_summary(narrowed_nums))
this_region["executed_branches"] = list(
_convert_branch_arcs(narrowed_analysis.executed_branch_arcs()),
)
this_region["missing_branches"] = list(
_convert_branch_arcs(narrowed_analysis.missing_branch_arcs()),
)
return this_region


def _convert_branch_arcs(
branch_arcs: dict[TLineNo, list[TLineNo]],
Expand Down
Loading

0 comments on commit 92d96b9

Please sign in to comment.