summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2015-07-30 07:14:54 -0400
committerNed Batchelder <nedbat@gmail.com>2015-07-30 07:14:54 -0400
commit31f58b1165dd67d443b1e5fd0403574774a23bfc (patch)
tree06bb807d8a377c95156bdc812c76be6819b50cf1
parent07233cf423384d0a5bb819382d2005e49d9d945c (diff)
parentc302b891209baf67abcdb1d49896397deea46f67 (diff)
downloadpython-coveragepy-git-31f58b1165dd67d443b1e5fd0403574774a23bfc.tar.gz
Merged in atodorov/coverage.py/combine_files_and_dirs (pull request #62)
Extend combine parameters to allow for file names and shell globs
-rw-r--r--coverage/cmdline.py8
-rw-r--r--coverage/data.py17
-rw-r--r--tests/test_data.py2
3 files changed, 18 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index 669c569e..499444ca 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -252,13 +252,13 @@ CMDS = {
),
'combine': CmdOptionParser("combine", GLOBAL_ARGS,
- usage = "<dir1> <dir2> ... <dirN>",
+ usage = "<path1> <path2> ... <pathN>",
description = "Combine data from multiple coverage files collected "
"with 'run -p'. The combined results are written to a single "
"file representing the union of the data. The positional "
- "arguments are directories from which the data files should be "
- "combined. By default, only data files in the current directory "
- "are combined."
+ "arguments are files or directories or shell globs "
+ "representing the data files which should be combined. "
+ "By default, only data files in the current directory are combined."
),
'debug': CmdOptionParser("debug", GLOBAL_ARGS,
diff --git a/coverage/data.py b/coverage/data.py
index de68dba1..4e7d999e 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -616,12 +616,21 @@ class CoverageDataFiles(object):
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))
+ if os.path.isfile(d):
+ files_to_combine.append(os.path.abspath(d))
+ elif os.path.isdir(d):
+ pattern = os.path.join(os.path.abspath(d), localdot)
+ files_to_combine.extend(glob.glob(pattern))
+ else:
+ files = glob.glob(d)
+ if not files:
+ raise CoverageException("Couldn't combine from non-existing path '%s'" % (d,))
+ files_to_combine.extend(files)
+
for f in files_to_combine:
+ if not os.path.isfile(f):
+ raise CoverageException("Couldn't combine from non-existing file '%s'" % (f,))
new_data = CoverageData()
new_data.read_file(f)
data.update(new_data, aliases=aliases)
diff --git a/tests/test_data.py b/tests/test_data.py
index ce49bcbf..a67a27ca 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -686,6 +686,6 @@ class CoverageDataFilesTest(DataTestHelpers, CoverageTest):
def test_combining_from_nonexistent_directories(self):
covdata = CoverageData()
- msg = "Couldn't combine from non-existent directory 'xyzzy'"
+ msg = "Couldn't combine from non-existing path 'xyzzy'"
with self.assertRaisesRegex(CoverageException, msg):
self.data_files.combine_parallel_data(covdata, data_dirs=['xyzzy'])