diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-12 06:30:49 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-12 06:30:49 -0400 |
commit | e8492d3d616a16859afd817e7aaf5c180801f60f (patch) | |
tree | b9ba45d4f95bc3555008b7e2bf1c48888177175b | |
parent | a42bc67e8e32ac70086be25d18944af879e5fc97 (diff) | |
download | python-coveragepy-git-e8492d3d616a16859afd817e7aaf5c180801f60f.tar.gz |
Report lines properly when measuring branches; Use None for the placeholder value throughout.
-rw-r--r-- | coverage/collector.py | 32 | ||||
-rw-r--r-- | coverage/data.py | 15 |
2 files changed, 34 insertions, 13 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 4743ad52..4aec4700 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -49,7 +49,7 @@ class PyTracer: if frame == self.last_exc_back: # Someone forgot a return event. if self.arcs and self.cur_file_data: - self.cur_file_data[(self.last_line, 0)] = True + self.cur_file_data[(self.last_line, 0)] = None self.cur_file_data, self.last_line = self.data_stack.pop() self.last_exc_back = None @@ -70,13 +70,13 @@ class PyTracer: # Record an executed line. if self.cur_file_data is not None: if self.arcs: - self.cur_file_data[(self.last_line, frame.f_lineno)] = True + self.cur_file_data[(self.last_line, frame.f_lineno)] = None else: - self.cur_file_data[frame.f_lineno] = True + self.cur_file_data[frame.f_lineno] = None self.last_line = frame.f_lineno elif event == 'return': if self.arcs and self.cur_file_data: - self.cur_file_data[(self.last_line, 0)] = True + self.cur_file_data[(self.last_line, 0)] = None # Leaving this function, pop the filename stack. self.cur_file_data, self.last_line = self.data_stack.pop() elif event == 'exception': @@ -221,15 +221,31 @@ class Collector: threading.settrace(self._installation_trace) def get_line_data(self): - """Return the { filename: { lineno: True, ...}, ...} data collected.""" + """Return the line data collected. + + Data is { filename: { lineno: None, ...}, ...} + + """ if self.branch: - return [(f,l) for f,l,_ in self.data.keys() if l] + # If we were measuring branches, then we have to re-build the dict + # to show line data. + line_data = {} + for f, arcs in self.data.items(): + line_data[f] = ldf = {} + for l1, _ in arcs: + if l1: + ldf[l1] = None + return line_data else: return self.data def get_arc_data(self): - """Return the (filename, (from_line, to_line)) arc data collected.""" + """Return the arc data collected. + + Data is { filename: { (l1, l2): None, ...}, ...} + + """ if self.branch: - return self.data.keys() + return self.data else: return [] diff --git a/coverage/data.py b/coverage/data.py index fd6256e1..b61adcd6 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -55,7 +55,7 @@ class CoverageData: # executed: # # { - # 'filename1.py': { 12: True, 47: True, ... }, + # 'filename1.py': { 12: None, 47: None, ... }, # ... # } # @@ -128,7 +128,7 @@ class CoverageData: if isinstance(data, dict): # Unpack the 'lines' item. lines = dict([ - (f, dict.fromkeys(linenos, True)) + (f, dict.fromkeys(linenos, None)) for f, linenos in data['lines'].items() ]) except Exception: @@ -150,15 +150,20 @@ class CoverageData: def add_line_data(self, line_data): """Add executed line data. - `line_data` is { filename: { lineno: True, ... }, ...} + `line_data` is { filename: { lineno: None, ... }, ...} """ for filename, linenos in line_data.items(): self.lines.setdefault(filename, {}).update(linenos) def add_arc_data(self, arc_data): - for filename, arc in arc_data: - self.arcs.setdefault(filename, {})[arc_data] = True + """Add measured arc data. + + `arc_data` is { filename: { (l1,l2): None, ... }, ...} + + """ + for filename, arcs in arc_data.items(): + self.arcs.setdefault(filename, {}).update(arcs) def executed_files(self): """A list of all files that had been measured as executed.""" |