@@ -79,9 +79,6 @@ def _unsettrace():
79
79
80
80
PRAGMA_NOCOVER = "#pragma NO COVER"
81
81
82
- # Simple rx to find lines with no code.
83
- rx_blank = re .compile (r'^\s*(#.*)?$' )
84
-
85
82
class _Ignore :
86
83
def __init__ (self , modules = None , dirs = None ):
87
84
self ._mods = set () if not modules else set (modules )
@@ -284,16 +281,15 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
284
281
lnotab = _find_executable_linenos (filename )
285
282
else :
286
283
lnotab = {}
287
- if lnotab :
288
- source = linecache .getlines (filename )
289
- coverpath = os .path .join (dir , modulename + ".cover" )
290
- with open (filename , 'rb' ) as fp :
291
- encoding , _ = tokenize .detect_encoding (fp .readline )
292
- n_hits , n_lines = self .write_results_file (coverpath , source ,
293
- lnotab , count , encoding )
294
- if summary and n_lines :
295
- percent = int (100 * n_hits / n_lines )
296
- sums [modulename ] = n_lines , percent , modulename , filename
284
+ source = linecache .getlines (filename )
285
+ coverpath = os .path .join (dir , modulename + ".cover" )
286
+ with open (filename , 'rb' ) as fp :
287
+ encoding , _ = tokenize .detect_encoding (fp .readline )
288
+ n_hits , n_lines = self .write_results_file (coverpath , source ,
289
+ lnotab , count , encoding )
290
+ if summary and n_lines :
291
+ percent = int (100 * n_hits / n_lines )
292
+ sums [modulename ] = n_lines , percent , modulename , filename
297
293
298
294
299
295
if summary and sums :
@@ -312,6 +308,7 @@ def write_results(self, show_missing=True, summary=False, coverdir=None):
312
308
313
309
def write_results_file (self , path , lines , lnotab , lines_hit , encoding = None ):
314
310
"""Return a coverage results file in path."""
311
+ # ``lnotab`` is a dict of executable lines, or a line number "table"
315
312
316
313
try :
317
314
outfile = open (path , "w" , encoding = encoding )
@@ -330,17 +327,13 @@ def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
330
327
outfile .write ("%5d: " % lines_hit [lineno ])
331
328
n_hits += 1
332
329
n_lines += 1
333
- elif rx_blank .match (line ):
334
- outfile .write (" " )
335
- else :
336
- # lines preceded by no marks weren't hit
337
- # Highlight them if so indicated, unless the line contains
330
+ elif lineno in lnotab and not PRAGMA_NOCOVER in line :
331
+ # Highlight never-executed lines, unless the line contains
338
332
# #pragma: NO COVER
339
- if lineno in lnotab and not PRAGMA_NOCOVER in line :
340
- outfile .write (">>>>>> " )
341
- n_lines += 1
342
- else :
343
- outfile .write (" " )
333
+ outfile .write (">>>>>> " )
334
+ n_lines += 1
335
+ else :
336
+ outfile .write (" " )
344
337
outfile .write (line .expandtabs (8 ))
345
338
346
339
return n_hits , n_lines
0 commit comments