diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-08-07 11:53:27 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-08-07 11:53:27 -0400 |
commit | 1035b301586737bd44d6a8a9739e3cce53406622 (patch) | |
tree | 1427819040c2210ae8e14c694e23d2802dcded00 /coverage | |
parent | 515479de68afb93dd0829a30ff191dff707e0892 (diff) | |
download | python-coveragepy-1035b301586737bd44d6a8a9739e3cce53406622.tar.gz |
Combining twice shouldn't lose data. #412, #516
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/cmdline.py | 2 | ||||
-rw-r--r-- | coverage/control.py | 12 | ||||
-rw-r--r-- | coverage/data.py | 8 |
3 files changed, 18 insertions, 4 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py index 09e8232..a83d619 100644 --- a/coverage/cmdline.py +++ b/coverage/cmdline.py @@ -483,7 +483,7 @@ class CoverageScript(object): if options.append: self.coverage.load() data_dirs = args or None - self.coverage.combine(data_dirs) + self.coverage.combine(data_dirs, strict=True) self.coverage.save() return OK diff --git a/coverage/control.py b/coverage/control.py index cc66196..32fb30c 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -791,7 +791,7 @@ class Coverage(object): self.get_data() self.data_files.write(self.data, suffix=self.data_suffix) - def combine(self, data_paths=None): + def combine(self, data_paths=None, strict=False): """Combine together a number of similarly-named coverage data files. All coverage data files whose name starts with `data_file` (from the @@ -803,9 +803,15 @@ class Coverage(object): directory indicated by the current data file (probably the current directory) will be combined. + If `strict` is true, then it is an error to attempt to combine when + there are no data files to combine. + .. versionadded:: 4.0 The `data_paths` parameter. + .. versionadded:: 4.3 + The `strict` parameter. + """ self._init() self.get_data() @@ -818,7 +824,9 @@ class Coverage(object): for pattern in paths[1:]: aliases.add(pattern, result) - self.data_files.combine_parallel_data(self.data, aliases=aliases, data_paths=data_paths) + self.data_files.combine_parallel_data( + self.data, aliases=aliases, data_paths=data_paths, strict=strict, + ) def get_data(self): """Get the collected data and reset the collector. diff --git a/coverage/data.py b/coverage/data.py index 60e104d..94d8330 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -666,7 +666,7 @@ class CoverageDataFiles(object): filename += "." + suffix data.write_file(filename) - def combine_parallel_data(self, data, aliases=None, data_paths=None): + def combine_parallel_data(self, data, aliases=None, data_paths=None, strict=False): """Combine a number of data files together. Treat `self.filename` as a file prefix, and combine the data from all @@ -686,6 +686,9 @@ class CoverageDataFiles(object): cannot be read, a warning will be issued, and the file will not be deleted. + If `strict` is true, and no files are found to combine, an error is + raised. + """ # Because of the os.path.abspath in the constructor, data_dir will # never be an empty string. @@ -703,6 +706,9 @@ class CoverageDataFiles(object): else: raise CoverageException("Couldn't combine from non-existent path '%s'" % (p,)) + if strict and not files_to_combine: + raise CoverageException("No data to combine") + for f in files_to_combine: new_data = CoverageData() try: |