diff options
author | Alexander Todorov <atodorov@otb.bg> | 2015-07-29 19:55:43 +0300 |
---|---|---|
committer | Alexander Todorov <atodorov@otb.bg> | 2015-07-29 19:55:43 +0300 |
commit | a98ffc153e5dedb5fed97ed8cbf5fbad65a248bd (patch) | |
tree | b34218ae28102eace9609d6dc64efc36ef84a824 | |
parent | 24841ccad26b812b377aede975be1bb02e5a0fdb (diff) | |
download | python-coveragepy-a98ffc153e5dedb5fed97ed8cbf5fbad65a248bd.tar.gz |
extend combine parameters to allow for file names and shell globs
-rw-r--r-- | coverage/cmdline.py | 8 | ||||
-rw-r--r-- | coverage/data.py | 17 | ||||
-rw-r--r-- | tests/test_data.py | 2 |
3 files changed, 18 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 669c569..499444c 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 de68dba..4e7d999 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 ce49bcb..a67a27c 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']) |