summaryrefslogtreecommitdiff
path: root/tests/test_api.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-08-07 11:53:27 -0400
committerNed Batchelder <ned@nedbatchelder.com>2016-08-07 11:53:27 -0400
commitb3d626c3936d11c189b8e810ccb93ceaa019b156 (patch)
treed25f408e9400368eb36baaab82139a4c47594b22 /tests/test_api.py
parent0e8b701b7ff23608d759188876ac3c9bf8669a47 (diff)
downloadpython-coveragepy-git-b3d626c3936d11c189b8e810ccb93ceaa019b156.tar.gz
Combining twice shouldn't lose data. #412, #516
Diffstat (limited to 'tests/test_api.py')
-rw-r--r--tests/test_api.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/test_api.py b/tests/test_api.py
index 27092098..9feea5bf 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -293,8 +293,8 @@ class ApiTest(CoverageTest):
self.check_code1_code2(cov)
- def make_corrupt_data_files(self):
- """Make some good and some bad data files."""
+ def make_good_data_files(self):
+ """Make some good data files."""
self.make_code1_code2()
cov = coverage.Coverage(data_suffix=True)
self.start_import_stop(cov, "code1")
@@ -304,12 +304,15 @@ class ApiTest(CoverageTest):
self.start_import_stop(cov, "code2")
cov.save()
+ def make_bad_data_file(self):
+ """Make one bad data file."""
self.make_file(".coverage.foo", """La la la, this isn't coverage data!""")
def test_combining_corrupt_data(self):
# If you combine a corrupt data file, then you will get a warning,
# and the file will remain.
- self.make_corrupt_data_files()
+ self.make_good_data_files()
+ self.make_bad_data_file()
cov = coverage.Coverage()
warning_regex = (
r"Couldn't read data from '.*\.coverage\.foo': "
@@ -324,6 +327,27 @@ class ApiTest(CoverageTest):
# The bad file still exists.
self.assert_exists(".coverage.foo")
+ def test_combining_twice(self):
+ self.make_good_data_files()
+ cov1 = coverage.Coverage()
+ cov1.combine()
+ cov1.save()
+ self.check_code1_code2(cov1)
+
+ cov2 = coverage.Coverage()
+ with self.assertRaisesRegex(CoverageException, r"No data to combine"):
+ cov2.combine(strict=True)
+
+ cov3 = coverage.Coverage()
+ cov3.combine()
+ # Now the data is empty!
+ _, statements, missing, _ = cov3.analysis("code1.py")
+ self.assertEqual(statements, [1])
+ self.assertEqual(missing, [1])
+ _, statements, missing, _ = cov3.analysis("code2.py")
+ self.assertEqual(statements, [1, 2])
+ self.assertEqual(missing, [1, 2])
+
class NamespaceModuleTest(CoverageTest):
"""Test PEP-420 namespace modules."""
@@ -344,7 +368,6 @@ class NamespaceModuleTest(CoverageTest):
cov.analysis(sys.modules['namespace'])
-
class UsingModulesMixin(object):
"""A mixin for importing modules from test/modules and test/moremodules."""