@@ -37,10 +37,10 @@ def write_items(self, items):
37
37
def _report_text (self , header , lines_values , total_line , end_lines ):
38
38
"""Internal method that prints report data in text format.
39
39
40
- `header` is a tuple with captions.
41
- `lines_values` is list of tuples of sortable values.
42
- `total_line` is a tuple with values of the total line.
43
- `end_lines` is a tuple of ending lines with information about skipped files.
40
+ `header` is a list with captions.
41
+ `lines_values` is list of lists of sortable values.
42
+ `total_line` is a list with values of the total line.
43
+ `end_lines` is a list of ending lines with information about skipped files.
44
44
45
45
"""
46
46
# Prepare the formatting strings, header, and column sorting.
@@ -90,15 +90,15 @@ def _report_text(self, header, lines_values, total_line, end_lines):
90
90
def _report_markdown (self , header , lines_values , total_line , end_lines ):
91
91
"""Internal method that prints report data in markdown format.
92
92
93
- `header` is a tuple with captions.
94
- `lines_values` is a sorted list of tuples containing coverage information.
95
- `total_line` is a tuple with values of the total line.
96
- `end_lines` is a tuple of ending lines with information about skipped files.
93
+ `header` is a list with captions.
94
+ `lines_values` is a sorted list of lists containing coverage information.
95
+ `total_line` is a list with values of the total line.
96
+ `end_lines` is a list of ending lines with information about skipped files.
97
97
98
98
"""
99
99
# Prepare the formatting strings, header, and column sorting.
100
- max_name = max ([ len (line [0 ].replace ("_" , "\\ _" )) for line in lines_values ] + [ 9 ] )
101
- max_name += 1
100
+ max_name = max (( len (line [0 ].replace ("_" , "\\ _" )) for line in lines_values ), default = 0 )
101
+ max_name = max ( max_name , len ( "**TOTAL**" )) + 1
102
102
formats = dict (
103
103
Name = "| {:{name_len}}|" ,
104
104
Stmts = "{:>9} |" ,
@@ -123,24 +123,23 @@ def _report_markdown(self, header, lines_values, total_line, end_lines):
123
123
# build string with line values
124
124
formats .update (dict (Cover = "{:>{n}}% |" ))
125
125
line_items = [
126
- formats [item ].format (str (value ).replace ("_" , "\\ _" ),
127
- name_len = max_name , n = max_n - 1 ) for item , value in zip (header , values )
126
+ formats [item ].format (str (value ).replace ("_" , "\\ _" ), name_len = max_name , n = max_n - 1 )
127
+ for item , value in zip (header , values )
128
128
]
129
129
self .write_items (line_items )
130
130
131
131
# Write the TOTAL line
132
132
formats .update (dict (Name = "|{:>{name_len}} |" , Cover = "{:>{n}} |" ))
133
133
total_line_items = []
134
134
for item , value in zip (header , total_line ):
135
- if value == '' :
135
+ if value == "" :
136
136
insert = value
137
137
elif item == "Cover" :
138
138
insert = f" **{ value } %**"
139
139
else :
140
140
insert = f" **{ value } **"
141
141
total_line_items += formats [item ].format (insert , name_len = max_name , n = max_n )
142
- total_row_str = "" .join (total_line_items )
143
- self .write (total_row_str )
142
+ self .write_items (total_line_items )
144
143
for end_line in end_lines :
145
144
self .write (end_line )
146
145
@@ -157,34 +156,37 @@ def report(self, morfs, outfile=None):
157
156
for fr , analysis in get_analysis_to_report (self .coverage , morfs ):
158
157
self .report_one_file (fr , analysis )
159
158
160
- # Prepare the formatting strings, header, and column sorting.
161
- header = ("Name" , "Stmts" , "Miss" ,)
159
+ if not self .total .n_files and not self .skipped_count :
160
+ raise NoDataError ("No data to report." )
161
+
162
+ # Prepare the header line and column sorting.
163
+ header = ["Name" , "Stmts" , "Miss" ]
162
164
if self .branches :
163
- header += ( "Branch" , "BrPart" ,)
164
- header += ( "Cover" ,)
165
+ header += [ "Branch" , "BrPart" ]
166
+ header += [ "Cover" ]
165
167
if self .config .show_missing :
166
- header += ( "Missing" ,)
168
+ header += [ "Missing" ]
167
169
168
170
column_order = dict (name = 0 , stmts = 1 , miss = 2 , cover = - 1 )
169
171
if self .branches :
170
172
column_order .update (dict (branch = 3 , brpart = 4 ))
171
173
172
- # `lines_values` is list of tuples of sortable values.
174
+ # `lines_values` is list of lists of sortable values.
173
175
lines_values = []
174
176
175
177
for (fr , analysis ) in self .fr_analysis :
176
178
nums = analysis .numbers
177
179
178
- args = ( fr .relative_filename (), nums .n_statements , nums .n_missing )
180
+ args = [ fr .relative_filename (), nums .n_statements , nums .n_missing ]
179
181
if self .branches :
180
- args += ( nums .n_branches , nums .n_partial_branches )
181
- args += ( nums .pc_covered_str ,)
182
+ args += [ nums .n_branches , nums .n_partial_branches ]
183
+ args += [ nums .pc_covered_str ]
182
184
if self .config .show_missing :
183
- args += ( analysis .missing_formatted (branches = True ),)
184
- args += ( nums .pc_covered ,)
185
+ args += [ analysis .missing_formatted (branches = True )]
186
+ args += [ nums .pc_covered ]
185
187
lines_values .append (args )
186
188
187
- # line- sorting.
189
+ # Line sorting.
188
190
sort_option = (self .config .sort or "name" ).lower ()
189
191
reverse = False
190
192
if sort_option [0 ] == '-' :
@@ -200,29 +202,24 @@ def report(self, morfs, outfile=None):
200
202
else :
201
203
lines_values .sort (key = lambda tup : (tup [sort_idx ], tup [0 ]), reverse = reverse )
202
204
203
- # calculate total if we had at least one file.
204
- total_line = ( "TOTAL" , self .total .n_statements , self .total .n_missing )
205
+ # Calculate total if we had at least one file.
206
+ total_line = [ "TOTAL" , self .total .n_statements , self .total .n_missing ]
205
207
if self .branches :
206
- total_line += ( self .total .n_branches , self .total .n_partial_branches )
207
- total_line += ( self .total .pc_covered_str ,)
208
+ total_line += [ self .total .n_branches , self .total .n_partial_branches ]
209
+ total_line += [ self .total .pc_covered_str ]
208
210
if self .config .show_missing :
209
- total_line += ( "" ,)
211
+ total_line += [ "" ]
210
212
211
- # create other final lines
213
+ # Create other final lines.
212
214
end_lines = []
213
- if not self .total .n_files and not self .skipped_count :
214
- raise NoDataError ("No data to report." )
215
-
216
215
if self .config .skip_covered and self .skipped_count :
217
216
file_suffix = 's' if self .skipped_count > 1 else ''
218
- fmt_skip_covered = (
217
+ end_lines . append (
219
218
f"\n { self .skipped_count } file{ file_suffix } skipped due to complete coverage."
220
219
)
221
- end_lines .append (fmt_skip_covered )
222
220
if self .config .skip_empty and self .empty_count :
223
- file_suffix = 's' if self .empty_count > 1 else ''
224
- fmt_skip_empty = f"\n { self .empty_count } empty file{ file_suffix } skipped."
225
- end_lines .append (fmt_skip_empty )
221
+ file_suffix = 's' if self .empty_count > 1 else ''
222
+ end_lines .append (f"\n { self .empty_count } empty file{ file_suffix } skipped." )
226
223
227
224
text_format = self .config .format or "text"
228
225
if text_format == "markdown" :
0 commit comments