diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/collector.py | 9 | ||||
-rw-r--r-- | coverage/control.py | 2 | ||||
-rw-r--r-- | coverage/data.py | 23 | ||||
-rw-r--r-- | coverage/parser.py | 4 | ||||
-rw-r--r-- | coverage/results.py | 8 |
5 files changed, 35 insertions, 11 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 6a2caf86..1a831c19 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -127,7 +127,9 @@ class Collector(object): tracing functions make the faster more sophisticated trace function not operate properly. - TODO: `branch` + If `branch` is true, then branches will be measured. This involves + collecting data on which statements followed each other (arcs). Use + `get_arc_data` to get the arc data. """ self.should_trace = should_trace @@ -245,7 +247,10 @@ class Collector(object): """Return the arc data collected. Data is { filename: { (l1, l2): None, ...}, ...} - + + Note that no data is collected or returned if the Collector wasn't + created with `branch` true. + """ if self.branch: return self.data diff --git a/coverage/control.py b/coverage/control.py index a9fe7b9a..23740ca4 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -49,7 +49,7 @@ class coverage(object): used. This is important for some environments where manipulation of tracing functions breaks the faster trace function. - TODO: `branch`. + If `branch` is true, then measure branch execution. """ from coverage import __version__ diff --git a/coverage/data.py b/coverage/data.py index 72ce38fd..452ce73d 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -62,7 +62,12 @@ class CoverageData(object): # self.lines = {} - self.arcs = {} # TODO + # A map from canonical Python source file name to a dictionary with an + # entry for each pair of line numbers forming an arc: + # + # { filename: { (l1,l2): None, ... }, ...} + # + self.arcs = {} def usefile(self, use_file=True): """Set whether or not to use a disk file for data.""" @@ -135,7 +140,12 @@ class CoverageData(object): return data def _read_file(self, filename): - """Return the stored coverage data from the given file.""" + """Return the stored coverage data from the given file. + + Returns two values, suitable for assigning to `self.lines` and + `self.arcs`. + + """ lines = {} arcs = {} try: @@ -156,8 +166,11 @@ class CoverageData(object): return lines, arcs def combine_parallel_data(self): - """ Treat self.filename as a file prefix, and combine the data from all - of the files starting with that prefix. + """Combine a number of data files together. + + Treat `self.filename` as a file prefix, and combine the data from all + of the data files starting with that prefix. + """ data_dir, local = os.path.split(self.filename) for f in os.listdir(data_dir or '.'): @@ -166,6 +179,8 @@ class CoverageData(object): new_lines, new_arcs = self._read_file(full_path) for filename, file_data in new_lines.items(): self.lines.setdefault(filename, {}).update(file_data) + for filename, file_data in new_arcs.items(): + self.arcs.setdefault(filename, {}).update(file_data) def add_line_data(self, line_data): """Add executed line data. diff --git a/coverage/parser.py b/coverage/parser.py index ee07c20c..9e0bd158 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -630,7 +630,9 @@ class AdHocMain(object): if exits > 1: m3 = str(exits) a = arc_chars.get(lineno, '').ljust(arc_width) - print("%4d %s%s%s%s%s %s" % (lineno, m0, m1, m2, m3, a, ltext)) + print("%4d %s%s%s%s%s %s" % + (lineno, m0, m1, m2, m3, a, ltext) + ) def arc_ascii_art(self, arcs): """Draw arcs as ascii art. diff --git a/coverage/results.py b/coverage/results.py index 6f4117a8..77c461ad 100644 --- a/coverage/results.py +++ b/coverage/results.py @@ -31,7 +31,6 @@ class Analysis(object): # Identify missing statements. executed = self.coverage.data.executed_lines(self.filename) - exec1 = [l for l in self.parser.first_lines(executed) if l in self.statements] exec1 = self.parser.first_lines(executed) self.missing = sorted(set(self.statements) - set(exec1)) @@ -100,6 +99,7 @@ class Analysis(object): return [l1 for l1,count in exit_counts.items() if count > 1] def total_branches(self): + """How many total branches are there?""" exit_counts = self.parser.exit_counts() return sum([count for count in exit_counts.values() if count > 1]) @@ -150,7 +150,8 @@ class Numbers(object): def _get_pc_covered(self): """Returns a single percentage value for coverage.""" if self.n_statements > 0: - pc_cov = 100.0 * (self.n_executed + self.n_executed_branches) / (self.n_statements + self.n_branches) + pc_cov = (100.0 * (self.n_executed + self.n_executed_branches) / + (self.n_statements + self.n_branches)) else: pc_cov = 100.0 return pc_cov @@ -163,7 +164,8 @@ 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_missing_branches = (self.n_missing_branches + + other.n_missing_branches) return nums def __radd__(self, other): |