summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt5
-rw-r--r--coverage/data.py25
-rw-r--r--test/farm/run/run_chdir.py12
-rw-r--r--test/farm/run/src/chdir.py5
-rw-r--r--test/farm/run/src/subdir/placeholder0
5 files changed, 30 insertions, 17 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 1ef5734b..59a345d5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -15,6 +15,11 @@ Version 3.1, unreleased
- Added the --timid option to enable a simpler slower trace function that works
for DecoratorTools (including TurboGears) projects.
+- Scripts that change directory will still write .coverage files in the
+ directory where execution started (`issue 24`_).
+
+.. _issue 24: http://bitbucket.org/ned/coveragepy/issue/24
+
Version 3.0.1, 7 July 2009
--------------------------
diff --git a/coverage/data.py b/coverage/data.py
index eb8e776d..2fb635ee 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -37,12 +37,17 @@ class CoverageData:
`collector` is a string describing the coverage measurement software.
"""
- self.basename = basename
self.collector = collector
- self.suffix = suffix
self.use_file = True
- self.filename = None
+
+ # Construct the filename that will be used for data file storage, if we
+ # ever do any file storage.
+ self.filename = (basename or
+ os.environ.get(self.filename_env, self.filename_default))
+ if suffix:
+ self.filename += suffix
+ self.filename = os.path.abspath(self.filename)
# A map from canonical Python source file name to a dictionary in
# which there's an entry for each line number that has been
@@ -59,34 +64,21 @@ class CoverageData:
"""Set whether or not to use a disk file for data."""
self.use_file = use_file
- def _make_filename(self):
- """Construct the filename that will be used for data file storage."""
- assert self.use_file
- if not self.filename:
- self.filename = (self.basename or
- os.environ.get(self.filename_env, self.filename_default))
-
- if self.suffix:
- self.filename += self.suffix
-
def read(self):
"""Read coverage data from the coverage data file (if it exists)."""
data = {}
if self.use_file:
- self._make_filename()
data = self._read_file(self.filename)
self.lines = data
def write(self):
"""Write the collected coverage data to a file."""
if self.use_file:
- self._make_filename()
self.write_file(self.filename)
def erase(self):
"""Erase the data, both in this object, and from its file storage."""
if self.use_file:
- self._make_filename()
if self.filename and os.path.exists(self.filename):
os.remove(self.filename)
self.lines = {}
@@ -143,7 +135,6 @@ class CoverageData:
""" Treat self.filename as a file prefix, and combine the data from all
of the files starting with that prefix.
"""
- self._make_filename()
data_dir, local = os.path.split(self.filename)
for f in os.listdir(data_dir or '.'):
if f.startswith(local):
diff --git a/test/farm/run/run_chdir.py b/test/farm/run/run_chdir.py
new file mode 100644
index 00000000..f459f500
--- /dev/null
+++ b/test/farm/run/run_chdir.py
@@ -0,0 +1,12 @@
+copy("src", "out")
+run("""
+ coverage run chdir.py
+ coverage -r
+ """, rundir="out", outfile="stdout.txt")
+contains("out/stdout.txt",
+ "Line One",
+ "Line Two",
+ "chdir"
+ )
+doesnt_contain("out/stdout.txt", "No such file or directory")
+clean("out")
diff --git a/test/farm/run/src/chdir.py b/test/farm/run/src/chdir.py
new file mode 100644
index 00000000..23c5afa8
--- /dev/null
+++ b/test/farm/run/src/chdir.py
@@ -0,0 +1,5 @@
+import os
+print "Line One"
+os.chdir("subdir")
+print "Line Two"
+
diff --git a/test/farm/run/src/subdir/placeholder b/test/farm/run/src/subdir/placeholder
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/farm/run/src/subdir/placeholder