MCPcopy Index your code
hub / github.com/python/cpython / write_results_file

Method write_results_file

Lib/trace.py:299–329  ·  view source on GitHub ↗

Return a coverage results file in path.

(self, path, lines, lnotab, lines_hit, encoding=None)

Source from the content-addressed store, hash-verified

297 print("Can't save counts files because %s" % err, file=sys.stderr)
298
299 def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
300 """Return a coverage results file in path."""
301 # ``lnotab`` is a dict of executable lines, or a line number "table"
302
303 try:
304 outfile = open(path, "w", encoding=encoding)
305 except OSError as err:
306 print(("trace: Could not open %r for writing: %s "
307 "- skipping" % (path, err)), file=sys.stderr)
308 return 0, 0
309
310 n_lines = 0
311 n_hits = 0
312 with outfile:
313 for lineno, line in enumerate(lines, 1):
314 # do the blank/comment match to try to mark more lines
315 # (help the reader find stuff that hasn't been covered)
316 if lineno in lines_hit:
317 outfile.write("%5d: " % lines_hit[lineno])
318 n_hits += 1
319 n_lines += 1
320 elif lineno in lnotab and not PRAGMA_NOCOVER in line:
321 # Highlight never-executed lines, unless the line contains
322 # #pragma: NO COVER
323 outfile.write(">>>>>> ")
324 n_lines += 1
325 else:
326 outfile.write(" ")
327 outfile.write(line.expandtabs(8))
328
329 return n_hits, n_lines
330
331def _find_lines_from_code(code, strs):
332 """Return dict where keys are lines in the line number table."""

Callers 1

write_resultsMethod · 0.95

Calls 4

enumerateFunction · 0.85
openFunction · 0.70
writeMethod · 0.45
expandtabsMethod · 0.45

Tested by

no test coverage detected