summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2010-01-03 10:23:06 -0500
committerNed Batchelder <ned@nedbatchelder.com>2010-01-03 10:23:06 -0500
commit2fd7773780de939169ca4ae8ad347f92785cd112 (patch)
tree24391041799b3d7e55b5cb1a60edfc9ee6cf9f08 /test
parentf34cffd56572c46015615d4e541c600fde6c5af4 (diff)
downloadpython-coveragepy-git-2fd7773780de939169ca4ae8ad347f92785cd112.tar.gz
Parallel mode can be set from the .coveragerc file.
Diffstat (limited to 'test')
-rw-r--r--test/coverage_coverage.py3
-rw-r--r--test/test_api.py2
-rw-r--r--test/test_cmdline.py32
-rw-r--r--test/test_coverage.py58
4 files changed, 75 insertions, 20 deletions
diff --git a/test/coverage_coverage.py b/test/coverage_coverage.py
index 5cfef04b..1e1cba02 100644
--- a/test/coverage_coverage.py
+++ b/test/coverage_coverage.py
@@ -23,7 +23,7 @@ def run_tests_with_coverage():
tracer = os.environ.get('COVERAGE_TEST_TRACER', 'c')
version = "%s%s" % sys.version_info[:2]
- suffix = ".%s_%s" % (version, tracer)
+ suffix = "%s_%s" % (version, tracer)
cov = coverage.coverage(config_file="covcov.ini", data_suffix=suffix)
# Cheap trick: the coverage code itself is excluded from measurement, but
@@ -66,7 +66,6 @@ def report_on_combined_files():
cov = coverage.coverage(config_file="covcov.ini")
cov.combine()
cov.save()
-
cov.html_report(directory=HTML_DIR)
diff --git a/test/test_api.py b/test/test_api.py
index 69eb6496..1f0ad838 100644
--- a/test/test_api.py
+++ b/test/test_api.py
@@ -238,7 +238,7 @@ class ApiTest(CoverageTest):
""")
self.assertSameElements(os.listdir("."), ["datatest3.py"])
- cov = coverage.coverage(data_file="cov.data", data_suffix=".14")
+ cov = coverage.coverage(data_file="cov.data", data_suffix="14")
cov.start()
self.import_module("datatest3") # pragma: recursive coverage
cov.stop() # pragma: recursive coverage
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index fda282bb..9196873f 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -1,6 +1,6 @@
"""Test cmdline.py for coverage."""
-import os, re, shlex, sys, textwrap, unittest
+import os, pprint, re, shlex, sys, textwrap, unittest
import mock
import coverage
@@ -14,7 +14,7 @@ class CmdLineTest(CoverageTest):
run_in_temp_dir = False
INIT_LOAD = """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True)
.load()\n"""
def model_object(self):
@@ -47,14 +47,24 @@ class CmdLineTest(CoverageTest):
m2 = self.model_object()
code_obj = compile(code, "<code>", "exec")
eval(code_obj, globals(), { 'm2': m2 })
- self.assertEqual(m1.method_calls, m2.method_calls)
+ self.assert_same_method_calls(m1, m2)
def cmd_executes_same(self, args1, args2):
"""Assert that the `args1` executes the same as `args2`."""
m1, r1 = self.mock_command_line(args1)
m2, r2 = self.mock_command_line(args2)
self.assertEqual(r1, r2)
- self.assertEqual(m1.method_calls, m2.method_calls)
+ self.assert_same_method_calls(m1, m2)
+
+ def assert_same_method_calls(self, m1, m2):
+ """Assert that `m1.method_calls` and `m2.method_calls` are the same."""
+ # Use a real equality comparison, but if it fails, use a nicer assert
+ # so we can tell what's going on. We have to use the real == first due
+ # to CmdOptionParser.__eq__
+ if m1.method_calls != m2.method_calls:
+ pp1 = pprint.pformat(m1.method_calls)
+ pp2 = pprint.pformat(m2.method_calls)
+ self.assertMultiLineEqual(pp1+'\n', pp2+'\n')
def cmd_help(self, args, help_msg=None, topic=None, ret=ERR):
"""Run a command line, and check that it prints the right help.
@@ -83,7 +93,7 @@ class ClassicCmdLineTest(CmdLineTest):
def testErase(self):
# coverage -e
self.cmd_executes("-e", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True)
.erase()
""")
self.cmd_executes_same("-e", "--erase")
@@ -93,7 +103,7 @@ class ClassicCmdLineTest(CmdLineTest):
# -x calls coverage.load first.
self.cmd_executes("-x foo.py", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True)
.load()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -102,7 +112,7 @@ class ClassicCmdLineTest(CmdLineTest):
""")
# -e -x calls coverage.erase first.
self.cmd_executes("-e -x foo.py", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -111,7 +121,7 @@ class ClassicCmdLineTest(CmdLineTest):
""")
# --timid sets a flag, and program arguments get passed through.
self.cmd_executes("-x --timid foo.py abc 123", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=True, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=True, branch=None, config_file=True)
.load()
.start()
.run_python_file('foo.py', ['foo.py', 'abc', '123'])
@@ -137,7 +147,7 @@ class ClassicCmdLineTest(CmdLineTest):
def testCombine(self):
# coverage -c
self.cmd_executes("-c", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True)
.load()
.combine()
.save()
@@ -440,7 +450,7 @@ class NewCmdLineTest(CmdLineTest):
self.cmd_executes_same("run --timid f.py", "-e -x --timid f.py")
self.cmd_executes_same("run", "-x")
self.cmd_executes("run --branch foo.py", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=True, config_file=True)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=True, config_file=True)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -448,7 +458,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run --rcfile=myrc.rc foo.py", """\
- .coverage(cover_pylib=None, data_suffix=False, timid=None, branch=None, config_file="myrc.rc")
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file="myrc.rc")
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
diff --git a/test/test_coverage.py b/test/test_coverage.py
index 772075e4..f8991406 100644
--- a/test/test_coverage.py
+++ b/test/test_coverage.py
@@ -1680,6 +1680,14 @@ class ModuleTest(CoverageTest):
class ProcessTest(CoverageTest):
"""Tests of the per-process behavior of coverage.py."""
+ def number_of_data_files(self):
+ """Return the number of coverage data files in this directory."""
+ num = 0
+ for f in os.listdir('.'):
+ if f.startswith('.coverage.') or f == '.coverage':
+ num += 1
+ return num
+
def testSaveOnExit(self):
self.make_file("mycode.py", """\
h = "Hello"
@@ -1725,18 +1733,56 @@ class ProcessTest(CoverageTest):
self.assertFalse(os.path.exists(".coverage"))
# After two -p runs, there should be two .coverage.machine.123 files.
- self.assertEqual(
- len([f for f in os.listdir('.') if f.startswith('.coverage')]),
- 2)
+ self.assertEqual(self.number_of_data_files(), 2)
# Combine the parallel coverage data files into .coverage .
self.run_command("coverage -c")
self.assertTrue(os.path.exists(".coverage"))
# After combining, there should be only the .coverage file.
- self.assertEqual(
- len([f for f in os.listdir('.') if f.startswith('.coverage')]),
- 1)
+ self.assertEqual(self.number_of_data_files(), 1)
+
+ # Read the coverage file and see that b_or_c.py has all 7 lines
+ # executed.
+ data = coverage.CoverageData()
+ data.read_file(".coverage")
+ self.assertEqual(data.summary()['b_or_c.py'], 7)
+
+ def test_combine_with_rc(self):
+ self.make_file("b_or_c.py", """\
+ import sys
+ a = 1
+ if sys.argv[1] == 'b':
+ b = 1
+ else:
+ c = 1
+ d = 1
+ print ('done')
+ """)
+
+ self.make_file(".coveragerc", """\
+ [run]
+ parallel = true
+ """)
+
+ out = self.run_command("coverage run b_or_c.py b")
+ self.assertEqual(out, 'done\n')
+ self.assertFalse(os.path.exists(".coverage"))
+
+ out = self.run_command("coverage run b_or_c.py c")
+ self.assertEqual(out, 'done\n')
+ self.assertFalse(os.path.exists(".coverage"))
+
+ # After two runs, there should be two .coverage.machine.123 files.
+ self.assertEqual(self.number_of_data_files(), 2)
+
+ # Combine the parallel coverage data files into .coverage .
+ self.run_command("coverage combine")
+ self.assertTrue(os.path.exists(".coverage"))
+ self.assertTrue(os.path.exists(".coveragerc"))
+
+ # After combining, there should be only the .coverage file.
+ self.assertEqual(self.number_of_data_files(), 1)
# Read the coverage file and see that b_or_c.py has all 7 lines
# executed.