diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-12 07:06:15 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2009-10-12 07:06:15 -0400 |
commit | 8cd21bb4c90f5bd8c552df1eba895bdb99bc6dc6 (patch) | |
tree | 71813d14d9ac5f32ea770f8cb0a5e380492b1792 | |
parent | f03b0bf7492702ade97be7dca2b2d88c06433b85 (diff) | |
download | python-coveragepy-git-8cd21bb4c90f5bd8c552df1eba895bdb99bc6dc6.tar.gz |
Write the arcs to the data file.
-rw-r--r-- | coverage/collector.py | 2 | ||||
-rw-r--r-- | coverage/data.py | 19 | ||||
-rw-r--r-- | test/test_data.py | 21 |
3 files changed, 38 insertions, 4 deletions
diff --git a/coverage/collector.py b/coverage/collector.py index 4aec4700..aadbab77 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -248,4 +248,4 @@ class Collector: if self.branch: return self.data else: - return [] + return {} diff --git a/coverage/data.py b/coverage/data.py index b61adcd6..1744a7fb 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -16,7 +16,8 @@ class CoverageData: executed: { 'file1': [17,23,45], 'file2': [1,2,3], ... } - * arcs: TODO + * arcs: a dict mapping filenames to sorted lists of line number pairs: + { 'file1': [(17,23), (17,25), (25,26)], ... } """ @@ -93,6 +94,12 @@ class CoverageData: [(f, sorted(lmap.keys())) for f, lmap in self.lines.items()] ) + def arc_data(self): + """Return the map from filenames to lists of line number pairs.""" + return dict( + [(f, sorted(amap.keys())) for f, amap in self.arcs.items()] + ) + def write_file(self, filename): """Write the coverage data to `filename`.""" @@ -100,7 +107,8 @@ class CoverageData: data = {} data['lines'] = self.line_data() - + data['arcs'] = self.arc_data() + if self.collector: data['collector'] = self.collector @@ -129,7 +137,12 @@ class CoverageData: # Unpack the 'lines' item. lines = dict([ (f, dict.fromkeys(linenos, None)) - for f, linenos in data['lines'].items() + for f, linenos in data.get('lines', {}).items() + ]) + # Unpack the 'arcs' item. + arcs = dict([ + (f, dict.fromkeys(arcpairs, None)) + for f, arcpairs in data.get('arcs', {}).items() ]) except Exception: pass diff --git a/test/test_data.py b/test/test_data.py index 12dd80aa..b6bc978a 100644 --- a/test/test_data.py +++ b/test/test_data.py @@ -19,6 +19,9 @@ DATA_2 = { 'a.py': {1:None, 5:None}, 'c.py': {17:None} } SUMMARY_1_2 = { 'a.py':3, 'b.py':1, 'c.py':1 } EXECED_FILES_1_2 = [ 'a.py', 'b.py', 'c.py' ] +ARC_DATA_3 = { 'x.py': {(1,2):None, (2,3):None}, 'y.py': {(17,23):None} } +X_PY_ARCS_3 = [(1,2), (2,3)] +Y_PY_ARCS_3 = [(17,23)] class DataTest(CoverageTest): """Test cases for coverage.data.""" @@ -92,3 +95,21 @@ class DataTest(CoverageTest): self.assert_equal_sets(lines.keys(), EXECED_FILES_1) self.assert_equal_sets(lines['a.py'], A_PY_LINES_1) self.assert_equal_sets(lines['b.py'], B_PY_LINES_1) + self.assert_equal_sets(data['arcs'].keys(), []) + + def test_file_format_with_arcs(self): + # Write with CoverageData, then read the pickle explicitly. + covdata = CoverageData() + covdata.add_arc_data(ARC_DATA_3) + covdata.write() + + fdata = open(".coverage", 'rb') + try: + data = pickle.load(fdata) + finally: + fdata.close() + + self.assert_equal_sets(data['lines'].keys(), []) + arcs = data['arcs'] + self.assert_equal_sets(arcs['x.py'], X_PY_ARCS_3) + self.assert_equal_sets(arcs['y.py'], Y_PY_ARCS_3) |