summaryrefslogtreecommitdiff
path: root/coverage/control.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-08-07 21:20:54 -0400
committerNed Batchelder <ned@nedbatchelder.com>2010-08-07 21:20:54 -0400
commitf8e9e89ebd94af2f963c1f699d864e69cdf55975 (patch)
treea36849423952753b63d6349f5e8d079bc6d24397 /coverage/control.py
parentdbfef08d72e6e7f6a44ce1fdade7181dfd3b6750 (diff)
downloadpython-coveragepy-git-f8e9e89ebd94af2f963c1f699d864e69cdf55975.tar.gz
Use some strange self.os stuff to hold references to modules so we'll have them available when called from atexit(). Fixes issue #71, I think.
Diffstat (limited to 'coverage/control.py')
-rw-r--r--coverage/control.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 7ab046cb..b7dfa0a8 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -29,7 +29,6 @@ class coverage(object):
cov.html_report(directory='covhtml')
"""
-
def __init__(self, data_file=None, data_suffix=None, cover_pylib=None,
auto_data=False, timid=None, branch=None, config_file=True,
source=None, omit=None, include=None):
@@ -164,6 +163,10 @@ class coverage(object):
# Only _harvest_data once per measurement cycle.
self._harvested = False
+ self.socket = socket
+ self.os = os
+ self.random = random
+
def _canonical_dir(self, f):
"""Return the canonical directory of the file `f`."""
return os.path.split(self.file_locator.canonical_filename(f))[0]
@@ -185,6 +188,9 @@ class coverage(object):
should not.
"""
+ if os is None:
+ return False
+
if filename.startswith('<'):
# Lots of non-file execution is represented with artificial
# filenames like "<string>", "<doctest readme.txt[0]>", or
@@ -366,13 +372,13 @@ class coverage(object):
def save(self):
"""Save the collected coverage data to the data file."""
data_suffix = self.data_suffix
- if data_suffix and not isinstance(data_suffix, string_class):
+ if data_suffix is True:
# If data_suffix was a simple true value, then make a suffix with
# plenty of distinguishing information. We do this here in
# `save()` at the last minute so that the pid will be correct even
# if the process forks.
data_suffix = "%s.%s.%06d" % (
- socket.gethostname(), os.getpid(), random.randint(0, 99999)
+ self.socket.gethostname(), self.os.getpid(), self.random.randint(0, 99999)
)
self._harvest_data()