summaryrefslogtreecommitdiff
path: root/tests
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
parent0e8b701b7ff23608d759188876ac3c9bf8669a47 (diff)
downloadpython-coveragepy-git-b3d626c3936d11c189b8e810ccb93ceaa019b156.tar.gz
Combining twice shouldn't lose data. #412, #516
Diffstat (limited to 'tests')
-rw-r--r--tests/test_api.py31
-rw-r--r--tests/test_cmdline.py10
-rw-r--r--tests/test_process.py12
3 files changed, 43 insertions, 10 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."""
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 1e72c4f4..3b982ebe 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -190,20 +190,20 @@ class CmdLineTest(BaseCmdLineTest):
# coverage combine with args
self.cmd_executes("combine datadir1", """\
.coverage()
- .combine(["datadir1"])
+ .combine(["datadir1"], strict=True)
.save()
""")
# coverage combine, appending
self.cmd_executes("combine --append datadir1", """\
.coverage()
.load()
- .combine(["datadir1"])
+ .combine(["datadir1"], strict=True)
.save()
""")
# coverage combine without args
self.cmd_executes("combine", """\
.coverage()
- .combine(None)
+ .combine(None, strict=True)
.save()
""")
@@ -211,12 +211,12 @@ class CmdLineTest(BaseCmdLineTest):
# https://bitbucket.org/ned/coveragepy/issues/385/coverage-combine-doesnt-work-with-rcfile
self.cmd_executes("combine --rcfile cov.ini", """\
.coverage(config_file='cov.ini')
- .combine(None)
+ .combine(None, strict=True)
.save()
""")
self.cmd_executes("combine --rcfile cov.ini data1 data2/more", """\
.coverage(config_file='cov.ini')
- .combine(["data1", "data2/more"])
+ .combine(["data1", "data2/more"], strict=True)
.save()
""")
diff --git a/tests/test_process.py b/tests/test_process.py
index 53d2362a..f7f46ab0 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -95,6 +95,17 @@ class ProcessTest(CoverageTest):
data.read_file(".coverage")
self.assertEqual(data.line_counts()['b_or_c.py'], 7)
+ # Running combine again should fail, because there are no parallel data
+ # files to combine.
+ status, out = self.run_command_status("coverage combine")
+ self.assertEqual(status, 1)
+ self.assertEqual(out, "No data to combine\n")
+
+ # And the originally combined data is still there.
+ data = coverage.CoverageData()
+ data.read_file(".coverage")
+ self.assertEqual(data.line_counts()['b_or_c.py'], 7)
+
def test_combine_parallel_data_with_a_corrupt_file(self):
self.make_b_or_c_py()
out = self.run_command("coverage run -p b_or_c.py b")
@@ -732,7 +743,6 @@ class ProcessTest(CoverageTest):
inst.start()
import foo
inst.stop()
- inst.combine()
inst.save()
""")
out = self.run_command("python run_twice.py")