summaryrefslogtreecommitdiff
path: root/coverage/results.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/results.py')
-rw-r--r--coverage/results.py51
1 files changed, 36 insertions, 15 deletions
diff --git a/coverage/results.py b/coverage/results.py
index 85071fe3..ae22e1c3 100644
--- a/coverage/results.py
+++ b/coverage/results.py
@@ -2,8 +2,8 @@
import os
-from coverage.backward import set, sorted # pylint: disable-msg=W0622
-from coverage.misc import format_lines, NoSource
+from coverage.backward import iitems, set, sorted # pylint: disable=W0622
+from coverage.misc import format_lines, join_regex, NoSource
from coverage.parser import CodeParser
@@ -25,7 +25,7 @@ class Analysis(object):
self.parser = CodeParser(
text=source, filename=self.filename,
- exclude=self.coverage.exclude_re
+ exclude=self.coverage._exclude_regex('exclude')
)
self.statements, self.excluded = self.parser.parse_source()
@@ -35,11 +35,19 @@ class Analysis(object):
self.missing = sorted(set(self.statements) - set(exec1))
if self.coverage.data.has_arcs():
+ self.no_branch = self.parser.lines_matching(
+ join_regex(self.coverage.config.partial_list),
+ join_regex(self.coverage.config.partial_always_list)
+ )
n_branches = self.total_branches()
mba = self.missing_branch_arcs()
- n_missing_branches = sum([len(v) for v in mba.values()])
+ n_partial_branches = sum(
+ [len(v) for k,v in iitems(mba) if k not in self.missing]
+ )
+ n_missing_branches = sum([len(v) for k,v in iitems(mba)])
else:
- n_branches = n_missing_branches = 0
+ n_branches = n_partial_branches = n_missing_branches = 0
+ self.no_branch = set()
self.numbers = Numbers(
n_files=1,
@@ -47,6 +55,7 @@ class Analysis(object):
n_excluded=len(self.excluded),
n_missing=len(self.missing),
n_branches=n_branches,
+ n_partial_branches=n_partial_branches,
n_missing_branches=n_missing_branches,
)
@@ -64,7 +73,8 @@ class Analysis(object):
def arc_possibilities(self):
"""Returns a sorted list of the arcs in the code."""
- return self.parser.arcs()
+ arcs = self.parser.arcs()
+ return arcs
def arcs_executed(self):
"""Returns a sorted list of the arcs actually executed in the code."""
@@ -77,7 +87,11 @@ class Analysis(object):
"""Returns a sorted list of the arcs in the code not executed."""
possible = self.arc_possibilities()
executed = self.arcs_executed()
- missing = [p for p in possible if p not in executed]
+ missing = [
+ p for p in possible
+ if p not in executed
+ and p[0] not in self.no_branch
+ ]
return sorted(missing)
def arcs_unpredicted(self):
@@ -89,14 +103,15 @@ class Analysis(object):
# trouble, and here is where it's the least burden to remove them.
unpredicted = [
e for e in executed
- if e not in possible and e[0] != e[1]
+ if e not in possible
+ and e[0] != e[1]
]
return sorted(unpredicted)
def branch_lines(self):
"""Returns a list of line numbers that have more than one exit."""
exit_counts = self.parser.exit_counts()
- return [l1 for l1,count in exit_counts.items() if count > 1]
+ return [l1 for l1,count in iitems(exit_counts) if count > 1]
def total_branches(self):
"""How many total branches are there?"""
@@ -153,13 +168,14 @@ class Numbers(object):
_near100 = 99.0
def __init__(self, n_files=0, n_statements=0, n_excluded=0, n_missing=0,
- n_branches=0, n_missing_branches=0
+ n_branches=0, n_partial_branches=0, n_missing_branches=0
):
self.n_files = n_files
self.n_statements = n_statements
self.n_excluded = n_excluded
self.n_missing = n_missing
self.n_branches = n_branches
+ self.n_partial_branches = n_partial_branches
self.n_missing_branches = n_missing_branches
def set_precision(cls, precision):
@@ -193,8 +209,9 @@ class Numbers(object):
def _get_pc_covered_str(self):
"""Returns the percent covered, as a string, without a percent sign.
- The important thing here is that "0" only be returned when it's truly
- zero, and "100" only be returned when it's truly 100.
+ Note that "0" is only returned when the value is truly zero, and "100"
+ is only returned when the value is truly 100. Rounding can never
+ result in either "0" or "100".
"""
pc = self.pc_covered
@@ -222,12 +239,16 @@ class Numbers(object):
nums.n_excluded = self.n_excluded + other.n_excluded
nums.n_missing = self.n_missing + other.n_missing
nums.n_branches = self.n_branches + other.n_branches
- nums.n_missing_branches = (self.n_missing_branches +
- other.n_missing_branches)
+ nums.n_partial_branches = (
+ self.n_partial_branches + other.n_partial_branches
+ )
+ nums.n_missing_branches = (
+ self.n_missing_branches + other.n_missing_branches
+ )
return nums
def __radd__(self, other):
# Implementing 0+Numbers allows us to sum() a list of Numbers.
if other == 0:
return self
- raise NotImplemented
+ return NotImplemented