summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/data.py10
-rw-r--r--tests/test_data.py14
2 files changed, 22 insertions, 2 deletions
diff --git a/coverage/data.py b/coverage/data.py
index 7e14a695..de68dba1 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -601,15 +601,23 @@ class CoverageDataFiles(object):
re-map paths to match the local machine's.
If `data_dirs` is provided, then it combines the data files from each
- directory into a single file.
+ directory into a single file. If `data_dirs` is not provided, then the
+ directory portion of `self.filename` is used as the directory to search
+ for data files.
+
+ Every data file found and combined is then deleted from disk.
"""
+ # Because of the os.path.abspath in the constructor, data_dir will
+ # never be an empty string.
data_dir, local = os.path.split(self.filename)
localdot = local + '.*'
data_dirs = data_dirs or [data_dir]
files_to_combine = []
for d in data_dirs:
+ if not os.path.isdir(d):
+ raise CoverageException("Couldn't combine from non-existent directory '%s'" % (d,))
pattern = os.path.join(os.path.abspath(d), localdot)
files_to_combine.extend(glob.glob(pattern))
diff --git a/tests/test_data.py b/tests/test_data.py
index c2bb9a0f..ce49bcbf 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -670,10 +670,22 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
os.makedirs('cov2')
covdata2.write_file('cov2/.coverage.2')
+ # This data won't be included.
+ covdata_xxx = CoverageData()
+ covdata_xxx.set_arcs(ARCS_3)
+ covdata_xxx.write_file('.coverage.xxx')
+
covdata3 = CoverageData()
- self.data_files.combine_parallel_data(covdata3, data_dirs=['cov1/', 'cov2/'])
+ self.data_files.combine_parallel_data(covdata3, data_dirs=['cov1', 'cov2'])
self.assert_line_counts(covdata3, SUMMARY_1_2)
self.assert_measured_files(covdata3, MEASURED_FILES_1_2)
self.assert_doesnt_exist("cov1/.coverage.1")
self.assert_doesnt_exist("cov2/.coverage.2")
+ self.assert_exists(".coverage.xxx")
+
+ def test_combining_from_nonexistent_directories(self):
+ covdata = CoverageData()
+ msg = "Couldn't combine from non-existent directory 'xyzzy'"
+ with self.assertRaisesRegex(CoverageException, msg):
+ self.data_files.combine_parallel_data(covdata, data_dirs=['xyzzy'])