diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-18 14:09:54 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2015-07-18 14:09:54 -0400 |
commit | f749a4bd0a01b452e3378cf85c8e760be9bb1ade (patch) | |
tree | 6bc6929b8a9ecf913767131a80f5207b3ac61e51 /coverage/collector.py | |
parent | efc976cfe783bff8af548e60c6146b489dde96e4 (diff) | |
download | python-coveragepy-f749a4bd0a01b452e3378cf85c8e760be9bb1ade.tar.gz |
Refactor collector->data; data has only one of lines and arcs.
Now the collector communicates directly with the data, and control is less
involved. In the data, when measuring arcs, only arcs are stored. Lines
are calculated as needed. This saves space in the data file, and is faster.
Diffstat (limited to 'coverage/collector.py')
-rw-r--r-- | coverage/collector.py | 52 |
1 files changed, 15 insertions, 37 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 57c3560..eec8703 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -3,6 +3,8 @@ import os, sys from coverage import env +from coverage.backward import iitems +from coverage.files import abs_file from coverage.misc import CoverageException from coverage.pytracer import PyTracer @@ -20,7 +22,7 @@ except ImportError: # exception here causes all sorts of other noise in unittest. sys.stderr.write( "*** COVERAGE_TEST_TRACER is 'c' but can't import CTracer!\n" - ) + ) sys.exit(1) CTracer = None @@ -46,7 +48,8 @@ class Collector(object): # the top, and resumed when they become the top again. _collectors = [] - def __init__(self, + def __init__( + self, should_trace, check_include, timid, branch, warn, concurrency, ): """Create a collector. @@ -289,45 +292,20 @@ class Collector(object): else: self._start_tracer() - def get_line_data(self): - """Return the line data collected. + def save_data(self, covdata): + """Save the collected data to a `CoverageData`. - Data is { filename: { lineno: None, ...}, ...} + Also resets the collector. """ - if self.branch: - # If we were measuring branches, then we have to re-build the dict - # to show line data. We'll use the first lines of all the arcs, - # if they are actual lines. We don't need the second lines, because - # the second lines will also be first lines, sometimes to exits. - line_data = {} - for f, arcs in self.data.items(): - line_data[f] = dict( - (l1, None) for l1, _ in arcs.keys() if l1 > 0 - ) - return line_data - else: - return self.data - - def get_arc_data(self): - """Return the arc data collected. - - Data is { filename: { (l1, l2): None, ...}, ...} + def abs_file_dict(d): + """Return a dict like d, but with keys modified by `abs_file`.""" + return dict((abs_file(k), v) for k, v in iitems(d)) - Note that no data is collected or returned if the Collector wasn't - created with `branch` true. - - """ if self.branch: - return self.data + covdata.add_arcs(abs_file_dict(self.data)) else: - return {} - - def get_plugin_data(self): - """Return the mapping of source files to plugins. + covdata.add_lines(abs_file_dict(self.data)) + covdata.add_plugins(abs_file_dict(self.plugin_data)) - Returns: - dict: { filename: plugin_name, ... } - - """ - return self.plugin_data + self.reset() |