Commits

Ned Batchelder committed 24b3b25

Commonalize the computation of total coverage percentage for a file.

Comments (0)

Files changed (3)

coverage/control.py

         """
         return format_lines(self.statements, self.missing)
 
+    def percent_covered(self):
+        """Returns a single percentage value for coverage."""
+        n_stm = len(self.statements)
+        n_mis = len(self.missing)
+        n_run = n_stm - n_mis
+        if n_stm > 0:
+            pc_cov = 100.0 * n_run / n_stm
+        else:
+            pc_cov = 100.0
+        return pc_cov
+
     def arc_possibilities(self):
         """Returns a sorted list of the arcs in the code."""
         return self.parser.arcs()
         n_exc = len(analysis.excluded)
         n_mis = len(analysis.missing)
         n_run = n_stm - n_mis
-        if n_stm > 0:
-            pc_cov = 100.0 * n_run / n_stm
-        else:
-            pc_cov = 100.0
-
+        pc_cov = analysis.percent_covered()
+        
         # These classes determine which lines are highlighted by default.
         c_run = " run hide"
         c_exc = " exc"

coverage/summary.py

                 analysis = self.coverage._analyze(cu)
                 n = len(analysis.statements)
                 m = n - len(analysis.missing)
-                if n > 0:
-                    pc = 100.0 * m / n
-                else:
-                    pc = 100.0
+                pc = analysis.percent_covered()
                 args = (cu.name, n, m, pc)
                 if self.show_missing:
                     args = args + (analysis.missing_formatted(),)