DebugClients/Python3/coverage/summary.py

changeset 4489
d0d6e4ad31bd
parent 3495
fac17a82b431
child 5051
3586ebd9fac8
--- a/DebugClients/Python3/coverage/summary.py	Sun Oct 04 13:35:09 2015 +0200
+++ b/DebugClients/Python3/coverage/summary.py	Sun Oct 04 22:37:56 2015 +0200
@@ -1,10 +1,13 @@
+# 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 .report import Reporter
-from .results import Numbers
-from .misc import NotPython
+from coverage.report import Reporter
+from coverage.results import Numbers
+from coverage.misc import NotPython, CoverageException
 
 
 class SummaryReporter(Reporter):
@@ -20,16 +23,18 @@
         `outfile` is a file object to write the summary to.
 
         """
-        self.find_code_units(morfs)
+        self.find_file_reporters(morfs)
 
         # Prepare the formatting strings
-        max_name = max([len(cu.name) for cu in self.code_units] + [5])
+        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 BrMiss"
+            header += " Branch BrPart"
             fmt_coverage += " %6d %6d"
         width100 = Numbers.pc_str_width()
         header += "%*s" % (width100+4, "Cover")
@@ -49,38 +54,61 @@
         outfile.write(rule)
 
         total = Numbers()
+        skipped_count = 0
 
-        for cu in self.code_units:
+        for fr in self.file_reporters:
             try:
-                analysis = self.coverage._analyze(cu)
+                analysis = self.coverage._analyze(fr)
                 nums = analysis.numbers
-                args = (cu.name, nums.n_statements, nums.n_missing)
+
+                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_missing_branches)
+                    args += (nums.n_branches, nums.n_partial_branches)
                 args += (nums.pc_covered_str,)
                 if self.config.show_missing:
-                    args += (analysis.missing_formatted(),)
+                    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 KeyboardInterrupt:                   # pragma: not covered
-                raise
-            except:
+            except Exception:
                 report_it = not self.config.ignore_errors
                 if report_it:
                     typ, msg = sys.exc_info()[:2]
-                    if typ is NotPython and not cu.should_be_python():
+                    # 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 % (cu.name, typ.__name__, msg))
+                    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_missing_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)
 
-        return total.pc_covered
+        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

eric ide

mercurial