summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-10-12 07:33:51 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-10-12 07:33:51 -0400
commitca039838a5c2f98c4566c7796aa42f4561c8eac3 (patch)
treefd0647ff04a0ce96198846b30a5c2c430533437d
parentf7a939107f419b3dade8fcfb173af3f1d9b9dd14 (diff)
downloadpython-coveragepy-git-ca039838a5c2f98c4566c7796aa42f4561c8eac3.tar.gz
Don't write arcs if there are none, and an ad-hoc data viewer.
-rw-r--r--coverage/data.py31
-rw-r--r--test/test_data.py5
2 files changed, 27 insertions, 9 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 1744a7fb..26dc5aa1 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -107,8 +107,10 @@ class CoverageData:
data = {}
data['lines'] = self.line_data()
- data['arcs'] = self.arc_data()
-
+ arcs = self.arc_data()
+ if arcs:
+ data['arcs'] = arcs
+
if self.collector:
data['collector'] = self.collector
@@ -123,16 +125,21 @@ class CoverageData:
"""Read the coverage data from `filename`."""
self.lines, self.arcs = self._read_file(filename)
+ def raw_data(self, filename):
+ """Return the raw pickled data from `filename`."""
+ fdata = open(filename, 'rb')
+ try:
+ data = pickle.load(fdata)
+ finally:
+ fdata.close()
+ return data
+
def _read_file(self, filename):
"""Return the stored coverage data from the given file."""
lines = {}
arcs = {}
try:
- fdata = open(filename, 'rb')
- try:
- data = pickle.load(fdata)
- finally:
- fdata.close()
+ data = self.raw_data(filename)
if isinstance(data, dict):
# Unpack the 'lines' item.
lines = dict([
@@ -207,3 +214,13 @@ class CoverageData:
for filename, lines in self.lines.items():
summ[filename_fn(filename)] = len(lines)
return summ
+
+if __name__ == '__main__':
+ # Ad-hoc: show the raw data in a data file.
+ import pprint, sys
+ covdata = CoverageData()
+ if sys.argv[1:]:
+ fname = sys.argv[1]
+ else:
+ fname = covdata.filename
+ pprint.pprint(covdata.raw_data(fname))
diff --git a/test/test_data.py b/test/test_data.py
index b6bc978a..640f4f07 100644
--- a/test/test_data.py
+++ b/test/test_data.py
@@ -95,8 +95,9 @@ 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(), [])
-
+ # If not measuring branches, there's no arcs entry.
+ self.assertEqual(data.get('arcs', 'not there'), 'not there')
+
def test_file_format_with_arcs(self):
# Write with CoverageData, then read the pickle explicitly.
covdata = CoverageData()