@@ -126,35 +126,48 @@ def report_one_file(
126
126
_convert_branch_arcs (analysis .missing_branch_arcs ()),
127
127
)
128
128
129
- for region in file_reporter .code_regions ():
130
- if region .kind not in reported_file :
131
- reported_file [region .kind ] = {}
132
- num_lines = len (file_reporter .source ().splitlines ())
129
+ num_lines = len (file_reporter .source ().splitlines ())
130
+ for noun , plural in file_reporter .code_region_kinds ():
131
+ reported_file [plural ] = region_data = {}
133
132
outside_lines = set (range (1 , num_lines + 1 ))
134
- outside_lines -= region .lines
135
- narrowed_analysis = analysis .narrow (region .lines )
136
- narrowed_nums = narrowed_analysis .numbers
137
- narrowed_summary = self .make_summary (narrowed_nums )
138
- reported_file [region .kind ][region .name ] = {
139
- "executed_lines" : sorted (narrowed_analysis .executed ),
140
- "summary" : narrowed_summary ,
141
- "missing_lines" : sorted (narrowed_analysis .missing ),
142
- "excluded_lines" : sorted (narrowed_analysis .excluded ),
143
- }
144
- if self .config .json_show_contexts :
145
- contexts = coverage_data .contexts_by_lineno (narrowed_analysis .filename )
146
- reported_file [region .kind ][region .name ]["contexts" ] = contexts
147
- if coverage_data .has_arcs ():
148
- narrowed_summary .update (self .make_branch_summary (narrowed_nums ))
149
- reported_file [region .kind ][region .name ]["executed_branches" ] = list (
150
- _convert_branch_arcs (narrowed_analysis .executed_branch_arcs ()),
151
- )
152
- reported_file [region .kind ][region .name ]["missing_branches" ] = list (
153
- _convert_branch_arcs (narrowed_analysis .missing_branch_arcs ()),
133
+ for region in file_reporter .code_regions ():
134
+ if region .kind != noun :
135
+ continue
136
+ outside_lines -= region .lines
137
+ region_data [region .name ] = self .make_region_data (
138
+ coverage_data ,
139
+ analysis .narrow (region .lines ),
154
140
)
155
141
142
+ region_data ["" ] = self .make_region_data (
143
+ coverage_data ,
144
+ analysis .narrow (outside_lines ),
145
+ )
156
146
return reported_file
157
147
148
+ def make_region_data (self , coverage_data : CoverageData , narrowed_analysis : Analysis ) -> JsonObj :
149
+ """Create the data object for one region of a file."""
150
+ narrowed_nums = narrowed_analysis .numbers
151
+ narrowed_summary = self .make_summary (narrowed_nums )
152
+ this_region = {
153
+ "executed_lines" : sorted (narrowed_analysis .executed ),
154
+ "summary" : narrowed_summary ,
155
+ "missing_lines" : sorted (narrowed_analysis .missing ),
156
+ "excluded_lines" : sorted (narrowed_analysis .excluded ),
157
+ }
158
+ if self .config .json_show_contexts :
159
+ contexts = coverage_data .contexts_by_lineno (narrowed_analysis .filename )
160
+ this_region ["contexts" ] = contexts
161
+ if coverage_data .has_arcs ():
162
+ narrowed_summary .update (self .make_branch_summary (narrowed_nums ))
163
+ this_region ["executed_branches" ] = list (
164
+ _convert_branch_arcs (narrowed_analysis .executed_branch_arcs ()),
165
+ )
166
+ this_region ["missing_branches" ] = list (
167
+ _convert_branch_arcs (narrowed_analysis .missing_branch_arcs ()),
168
+ )
169
+ return this_region
170
+
158
171
159
172
def _convert_branch_arcs (
160
173
branch_arcs : dict [TLineNo , list [TLineNo ]],
0 commit comments