Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: tools/telemetry/third_party/coverage/coverage/summary.py

Issue 1366913004: Add coverage Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/third_party/coverage/coverage/summary.py
diff --git a/tools/telemetry/third_party/coverage/coverage/summary.py b/tools/telemetry/third_party/coverage/coverage/summary.py
new file mode 100644
index 0000000000000000000000000000000000000000..25bb365efd465639ef52915b2db41af9dbb49774
--- /dev/null
+++ b/tools/telemetry/third_party/coverage/coverage/summary.py
@@ -0,0 +1,114 @@
+# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
+# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+
+"""Summary reporting"""
+
+import sys
+
+from coverage.report import Reporter
+from coverage.results import Numbers
+from coverage.misc import NotPython, CoverageException
+
+
+class SummaryReporter(Reporter):
+ """A reporter for writing the summary report."""
+
+ def __init__(self, coverage, config):
+ super(SummaryReporter, self).__init__(coverage, config)
+ self.branches = coverage.data.has_arcs()
+
+ def report(self, morfs, outfile=None):
+ """Writes a report summarizing coverage statistics per module.
+
+ `outfile` is a file object to write the summary to.
+
+ """
+ self.find_file_reporters(morfs)
+
+ # Prepare the formatting strings
+ max_name = max([len(fr.relative_filename()) for fr in self.file_reporters] + [5])
+ fmt_name = "%%- %ds " % max_name
+ fmt_err = "%s %s: %s\n"
+ fmt_skip_covered = "\n%s file%s skipped due to complete coverage.\n"
+
+ header = (fmt_name % "Name") + " Stmts Miss"
+ fmt_coverage = fmt_name + "%6d %6d"
+ if self.branches:
+ header += " Branch BrPart"
+ fmt_coverage += " %6d %6d"
+ width100 = Numbers.pc_str_width()
+ header += "%*s" % (width100+4, "Cover")
+ fmt_coverage += "%%%ds%%%%" % (width100+3,)
+ if self.config.show_missing:
+ header += " Missing"
+ fmt_coverage += " %s"
+ rule = "-" * len(header) + "\n"
+ header += "\n"
+ fmt_coverage += "\n"
+
+ if not outfile:
+ outfile = sys.stdout
+
+ # Write the header
+ outfile.write(header)
+ outfile.write(rule)
+
+ total = Numbers()
+ skipped_count = 0
+
+ for fr in self.file_reporters:
+ try:
+ analysis = self.coverage._analyze(fr)
+ nums = analysis.numbers
+
+ if self.config.skip_covered:
+ # Don't report on 100% files.
+ no_missing_lines = (nums.n_missing == 0)
+ no_missing_branches = (nums.n_partial_branches == 0)
+ if no_missing_lines and no_missing_branches:
+ skipped_count += 1
+ continue
+
+ args = (fr.relative_filename(), nums.n_statements, nums.n_missing)
+ if self.branches:
+ args += (nums.n_branches, nums.n_partial_branches)
+ args += (nums.pc_covered_str,)
+ if self.config.show_missing:
+ missing_fmtd = analysis.missing_formatted()
+ if self.branches:
+ branches_fmtd = analysis.arcs_missing_formatted()
+ if branches_fmtd:
+ if missing_fmtd:
+ missing_fmtd += ", "
+ missing_fmtd += branches_fmtd
+ args += (missing_fmtd,)
+ outfile.write(fmt_coverage % args)
+ total += nums
+ except Exception:
+ report_it = not self.config.ignore_errors
+ if report_it:
+ typ, msg = sys.exc_info()[:2]
+ # NotPython is only raised by PythonFileReporter, which has a
+ # should_be_python() method.
+ if typ is NotPython and not fr.should_be_python():
+ report_it = False
+ if report_it:
+ outfile.write(fmt_err % (fr.relative_filename(), typ.__name__, msg))
+
+ if total.n_files > 1:
+ outfile.write(rule)
+ args = ("TOTAL", total.n_statements, total.n_missing)
+ if self.branches:
+ args += (total.n_branches, total.n_partial_branches)
+ args += (total.pc_covered_str,)
+ if self.config.show_missing:
+ args += ("",)
+ outfile.write(fmt_coverage % args)
+
+ if not total.n_files and not skipped_count:
+ raise CoverageException("No data to report.")
+
+ if self.config.skip_covered and skipped_count:
+ outfile.write(fmt_skip_covered % (skipped_count, 's' if skipped_count > 1 else ''))
+
+ return total.n_statements and total.pc_covered
« no previous file with comments | « tools/telemetry/third_party/coverage/coverage/results.py ('k') | tools/telemetry/third_party/coverage/coverage/templite.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698