summaryrefslogtreecommitdiff
path: root/coverage/data.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-03-20 08:27:30 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-03-20 08:27:30 -0400
commit7632f4c60b5fbc856beea7607ce2b448f6b5bbbc (patch)
tree6df71b122ddad823f028b3b36a42db34b87b7f0e /coverage/data.py
parente305b35c2a116b4195e79a1da9e6eab9b6013295 (diff)
downloadpython-coveragepy-git-7632f4c60b5fbc856beea7607ce2b448f6b5bbbc.tar.gz
Calculate the pid suffix for data files at the end of the process so that programs calling os.fork will collect data from both child and parent. Fixes issue #56.
Diffstat (limited to 'coverage/data.py')
-rw-r--r--coverage/data.py31
1 files changed, 14 insertions, 17 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 9359af12..1b883750 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -21,22 +21,11 @@ class CoverageData(object):
"""
- # Name of the data file (unless environment variable is set).
- filename_default = ".coverage"
-
- # Environment variable naming the data file.
- filename_env = "COVERAGE_FILE"
-
- def __init__(self, basename=None, suffix=None, collector=None):
+ def __init__(self, basename=None, collector=None):
"""Create a CoverageData.
`basename` is the name of the file to use for storing data.
- `suffix` is a suffix to append to the base file name. This can be used
- for multiple or parallel execution, so that many coverage data files
- can exist simultaneously. A dot will be used to join the base name and
- the suffix.
-
`collector` is a string describing the coverage measurement software.
"""
@@ -47,8 +36,6 @@ class CoverageData(object):
# Construct the filename that will be used for data file storage, if we
# ever do any file storage.
self.filename = basename or ".coverage"
- if suffix:
- self.filename += "." + suffix
self.filename = os.path.abspath(self.filename)
# A map from canonical Python source file name to a dictionary in
@@ -80,10 +67,20 @@ class CoverageData(object):
else:
self.lines, self.arcs = {}, {}
- def write(self):
- """Write the collected coverage data to a file."""
+ def write(self, suffix=None):
+ """Write the collected coverage data to a file.
+
+ `suffix` is a suffix to append to the base file name. This can be used
+ for multiple or parallel execution, so that many coverage data files
+ can exist simultaneously. A dot will be used to join the base name and
+ the suffix.
+
+ """
if self.use_file:
- self.write_file(self.filename)
+ filename = self.filename
+ if suffix:
+ filename += "." + suffix
+ self.write_file(filename)
def erase(self):
"""Erase the data, both in this object, and from its file storage."""