summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <nedbat@gmail.com>2013-09-16 09:13:21 -0400
committerNed Batchelder <nedbat@gmail.com>2013-09-16 09:13:21 -0400
commitd39438e5121ebddaf8aa0f6b2abdf7ce07f7ea31 (patch)
tree1ee0cefdf520871cc54583410d8525e4dbf2eed8 /tests
parentdfe83e5fcdb5cc48880fda91d3d78353cb6ce4f7 (diff)
parentf5675121528fe9d4729f0ba8052282de99ec9b79 (diff)
downloadpython-coveragepy-d39438e5121ebddaf8aa0f6b2abdf7ce07f7ea31.tar.gz
Merged in rogerjhu/coverage.py (pull request #19)
Make UTF-8 detection more robust.
Diffstat (limited to 'tests')
-rw-r--r--tests/coveragetest.py11
-rw-r--r--tests/test_arcs.py63
-rw-r--r--tests/test_cmdline.py80
-rw-r--r--tests/test_collector.py57
-rw-r--r--tests/test_debug.py113
-rw-r--r--tests/test_farm.py6
-rw-r--r--tests/test_files.py9
-rw-r--r--tests/test_html.py3
-rw-r--r--tests/test_misc.py1
-rw-r--r--tests/test_process.py4
10 files changed, 293 insertions, 54 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 5613fa6..5060b53 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -36,8 +36,12 @@ OK, ERR = 0, 1
class CoverageTest(TestCase):
"""A base class for Coverage test cases."""
+ # Our own setting: most CoverageTests run in their own temp directory.
run_in_temp_dir = True
+ # Standard unittest setting: show me diffs even if they are very long.
+ maxDiff = None
+
def setUp(self):
super(CoverageTest, self).setUp()
@@ -61,8 +65,11 @@ class CoverageTest(TestCase):
self.old_dir = os.getcwd()
os.chdir(self.temp_dir)
- # Modules should be importable from this temp directory.
- sys.path.insert(0, '')
+ # Modules should be importable from this temp directory. We don't
+ # use '' because we make lots of different temp directories and
+ # nose's caching importer can get confused. The full path prevents
+ # problems.
+ sys.path.insert(0, os.getcwd())
# Keep a counter to make every call to check_coverage unique.
self.n = 0
diff --git a/tests/test_arcs.py b/tests/test_arcs.py
index f3c5fc3..6268e28 100644
--- a/tests/test_arcs.py
+++ b/tests/test_arcs.py
@@ -141,7 +141,7 @@ class SimpleArcTest(CoverageTest):
)
if 0: # expected failure
- def test_lambdas_are_confusing_bug_90(self):
+ def test_unused_lambdas_are_confusing_bug_90(self):
self.check_coverage("""\
a = 1
fn = lambda x: x
@@ -172,9 +172,9 @@ if sys.version_info >= (2, 6):
self.check_coverage("""\
for i in range(2):
with open("test", "w") as f:
- print 3
- print 4
- print 5
+ print(3)
+ print(4)
+ print(5)
""",
arcz=".1 12 23 34 41 15 5."
)
@@ -456,8 +456,8 @@ class ExceptionArcTest(CoverageTest):
d = 12 # C
assert a == 5 and c == 10 and d == 12 # D
""",
- arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.",
- arcz_missing="3D AD", arcz_unpredicted="7A")
+ arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB BC CD D.",
+ arcz_missing="3D", arcz_unpredicted="7A")
self.check_coverage("""\
a, c, d, i = 1, 1, 1, 99
try:
@@ -473,8 +473,8 @@ class ExceptionArcTest(CoverageTest):
d = 12 # C
assert a == 8 and c == 10 and d == 1 # D
""",
- arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB AD BC CD D.",
- arcz_missing="67 AB AD BC CD", arcz_unpredicted="")
+ arcz=".1 12 23 34 3D 45 56 67 68 8A A3 AB BC CD D.",
+ arcz_missing="67 AB BC CD", arcz_unpredicted="")
def test_break_in_finally(self):
@@ -493,22 +493,45 @@ class ExceptionArcTest(CoverageTest):
d = 12 # C
assert a == 5 and c == 10 and d == 1 # D
""",
- arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB AD BC CD D.",
- arcz_missing="3D AB BC CD", arcz_unpredicted="")
+ arcz=".1 12 23 34 3D 45 56 67 68 7A 8A A3 AB BC CD D.",
+ arcz_missing="3D AB BC CD", arcz_unpredicted="AD")
- if 0: # expected failure
- def test_finally_in_loop_bug_92(self):
+ def test_finally_in_loop_bug_92(self):
+ self.check_coverage("""\
+ for i in range(5):
+ try:
+ j = 3
+ finally:
+ f = 5
+ g = 6
+ h = 7
+ """,
+ arcz=".1 12 23 35 56 61 17 7.",
+ arcz_missing="", arcz_unpredicted="")
+
+ # Run this test only on 2.6 and 2.7 for now. I hope to fix it on Py3
+ # eventually...
+ if (2, 6) <= sys.version_info < (3,):
+ # "except Exception as e" is crucial here.
+ def test_bug_212(self):
self.check_coverage("""\
- for i in range(5):
+ def b(exc):
try:
- j = 3
- finally:
- f = 5
- g = 6
- h = 7
+ while 1:
+ raise Exception(exc) # 4
+ except Exception as e:
+ if exc != 'expected':
+ raise
+ q = 8
+
+ b('expected')
+ try:
+ b('unexpected') # C
+ except:
+ pass
""",
- arcz=".1 12 23 35 56 61 17 7.",
- arcz_missing="", arcz_unpredicted="")
+ arcz=".1 .2 1A 23 34 56 67 68 8. AB BC C. DE E.",
+ arcz_missing="C.", arcz_unpredicted="45 7. CD")
if sys.version_info >= (2, 5):
# Try-except-finally was new in 2.5
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index 6b11b3e..493ce18 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -15,7 +15,7 @@ class CmdLineTest(CoverageTest):
run_in_temp_dir = False
INIT_LOAD = """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.load()\n"""
def model_object(self):
@@ -104,7 +104,7 @@ class ClassicCmdLineTest(CmdLineTest):
def test_erase(self):
# coverage -e
self.cmd_executes("-e", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
""")
self.cmd_executes_same("-e", "--erase")
@@ -114,7 +114,7 @@ class ClassicCmdLineTest(CmdLineTest):
# -x calls coverage.load first.
self.cmd_executes("-x foo.py", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -123,7 +123,7 @@ class ClassicCmdLineTest(CmdLineTest):
""")
# -e -x calls coverage.erase first.
self.cmd_executes("-e -x foo.py", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -132,7 +132,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=None, timid=True, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=True, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py', 'abc', '123'])
@@ -141,7 +141,7 @@ class ClassicCmdLineTest(CmdLineTest):
""")
# -L sets a flag, and flags for the program don't confuse us.
self.cmd_executes("-x -p -L foo.py -a -b", """\
- .coverage(cover_pylib=True, data_suffix=True, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=True, data_suffix=True, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py', '-a', '-b'])
@@ -158,7 +158,7 @@ class ClassicCmdLineTest(CmdLineTest):
def test_combine(self):
# coverage -c
self.cmd_executes("-c", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.load()
.combine()
.save()
@@ -180,13 +180,13 @@ class ClassicCmdLineTest(CmdLineTest):
show_missing=True)
""")
self.cmd_executes("-r -o fooey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"], debug=None)
.load()
.report(ignore_errors=None, omit=["fooey"], include=None,
morfs=[], show_missing=None)
""")
self.cmd_executes("-r -o fooey,booey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"], debug=None)
.load()
.report(ignore_errors=None, omit=["fooey", "booey"], include=None,
morfs=[], show_missing=None)
@@ -225,13 +225,13 @@ class ClassicCmdLineTest(CmdLineTest):
omit=None, include=None, morfs=[])
""")
self.cmd_executes("-a -o fooey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"], debug=None)
.load()
.annotate(directory=None, ignore_errors=None,
omit=["fooey"], include=None, morfs=[])
""")
self.cmd_executes("-a -o fooey,booey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"], debug=None)
.load()
.annotate(directory=None, ignore_errors=None,
omit=["fooey", "booey"], include=None, morfs=[])
@@ -270,13 +270,13 @@ class ClassicCmdLineTest(CmdLineTest):
omit=None, include=None, morfs=[])
""")
self.cmd_executes("-b -o fooey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"], debug=None)
.load()
.html_report(directory=None, ignore_errors=None, title=None,
omit=["fooey"], include=None, morfs=[])
""")
self.cmd_executes("-b -o fooey,booey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"], debug=None)
.load()
.html_report(directory=None, ignore_errors=None, title=None,
omit=["fooey", "booey"], include=None, morfs=[])
@@ -481,7 +481,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=None, timid=None, branch=True, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=True, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -489,7 +489,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run --rcfile=myrc.rc foo.py", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file="myrc.rc", source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file="myrc.rc", source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -497,7 +497,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run --include=pre1,pre2 foo.py", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=["pre1", "pre2"], omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=["pre1", "pre2"], omit=None, debug=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -505,7 +505,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run --omit=opre1,opre2 foo.py", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["opre1", "opre2"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["opre1", "opre2"], debug=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -517,7 +517,9 @@ class NewCmdLineTest(CmdLineTest):
.coverage(cover_pylib=None, data_suffix=None, timid=None,
branch=None, config_file=True, source=None,
include=["pre1", "pre2"],
- omit=["opre1", "opre2"])
+ omit=["opre1", "opre2"],
+ debug=None,
+ )
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -529,7 +531,37 @@ class NewCmdLineTest(CmdLineTest):
.coverage(cover_pylib=None, data_suffix=None, timid=None,
branch=None, config_file=True,
source=["quux", "hi.there", "/home/bar"], include=None,
- omit=None)
+ omit=None,
+ debug=None,
+ )
+ .erase()
+ .start()
+ .run_python_file('foo.py', ['foo.py'])
+ .stop()
+ .save()
+ """)
+
+ def test_run_debug(self):
+ self.cmd_executes("run --debug=opt1 foo.py", """\
+ .coverage(cover_pylib=None, data_suffix=None, timid=None,
+ branch=None, config_file=True,
+ source=None, include=None,
+ omit=None,
+ debug=["opt1"],
+ )
+ .erase()
+ .start()
+ .run_python_file('foo.py', ['foo.py'])
+ .stop()
+ .save()
+ """)
+ self.cmd_executes("run --debug=opt1,opt2 foo.py", """\
+ .coverage(cover_pylib=None, data_suffix=None, timid=None,
+ branch=None, config_file=True,
+ source=None, include=None,
+ omit=None,
+ debug=["opt1","opt2"],
+ )
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -539,7 +571,7 @@ class NewCmdLineTest(CmdLineTest):
def test_run_module(self):
self.cmd_executes("run -m mymodule", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_module('mymodule', ['mymodule'])
@@ -547,7 +579,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run -m mymodule -qq arg1 arg2", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_module('mymodule', ['mymodule', '-qq', 'arg1', 'arg2'])
@@ -555,7 +587,7 @@ class NewCmdLineTest(CmdLineTest):
.save()
""")
self.cmd_executes("run --branch -m mymodule", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=True, config_file=True, source=None, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=True, config_file=True, source=None, include=None, omit=None, debug=None)
.erase()
.start()
.run_python_module('mymodule', ['mymodule'])
@@ -583,13 +615,13 @@ class NewCmdLineTest(CmdLineTest):
outfile="-")
""")
self.cmd_executes("xml --omit fooey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"], debug=None)
.load()
.xml_report(ignore_errors=None, omit=["fooey"], include=None, morfs=[],
outfile=None)
""")
self.cmd_executes("xml --omit fooey,booey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey", "booey"], debug=None)
.load()
.xml_report(ignore_errors=None, omit=["fooey", "booey"], include=None,
morfs=[], outfile=None)
diff --git a/tests/test_collector.py b/tests/test_collector.py
new file mode 100644
index 0000000..af3814f
--- /dev/null
+++ b/tests/test_collector.py
@@ -0,0 +1,57 @@
+"""Tests of coverage/collector.py and other collectors."""
+
+import re
+
+import coverage
+from coverage.backward import StringIO
+
+from tests.coveragetest import CoverageTest
+
+
+class CollectorTest(CoverageTest):
+ """Test specific aspects of the collection process."""
+
+ def test_should_trace_cache(self):
+ # The tracers should only invoke should_trace once for each file name.
+ # TODO: Might be better to do this with a mocked _should_trace,
+ # rather than by examining debug output.
+
+ # Make some files that invoke each other.
+ self.make_file("f1.py", """\
+ def f1(x, f):
+ return f(x)
+ """)
+
+ self.make_file("f2.py", """\
+ import f1
+
+ def func(x):
+ return f1.f1(x, otherfunc)
+
+ def otherfunc(x):
+ return x*x
+
+ for i in range(10):
+ func(i)
+ """)
+
+ # Trace one file, but not the other, and get the debug output.
+ debug_out = StringIO()
+ cov = coverage.coverage(
+ include=["f1.py"], debug=['trace'], debug_file=debug_out
+ )
+
+ # Import the python file, executing it.
+ self.start_import_stop(cov, "f2")
+
+ # Grab all the filenames mentioned in debug output, there should be no
+ # duplicates.
+ trace_lines = [
+ l for l in debug_out.getvalue().splitlines()
+ if l.startswith("Tracing ") or l.startswith("Not tracing ")
+ ]
+ filenames = [re.search(r"'[^']+'", l).group() for l in trace_lines]
+ self.assertEqual(len(filenames), len(set(filenames)))
+
+ # Double-check that the tracing messages are in there somewhere.
+ self.assertGreater(len(filenames), 5)
diff --git a/tests/test_debug.py b/tests/test_debug.py
new file mode 100644
index 0000000..0132c1c
--- /dev/null
+++ b/tests/test_debug.py
@@ -0,0 +1,113 @@
+"""Tests of coverage/debug.py"""
+
+import os
+import re
+
+import coverage
+from coverage.backward import StringIO
+from coverage.debug import info_formatter
+from tests.coveragetest import CoverageTest
+
+
+class InfoFormatterTest(CoverageTest):
+ """Tests of misc.info_formatter."""
+
+ def test_info_formatter(self):
+ lines = list(info_formatter([
+ ('x', 'hello there'),
+ ('very long label', ['one element']),
+ ('regular', ['abc', 'def', 'ghi', 'jkl']),
+ ('nothing', []),
+ ]))
+ self.assertEqual(lines, [
+ ' x: hello there',
+ 'very long label: one element',
+ ' regular: abc',
+ ' def',
+ ' ghi',
+ ' jkl',
+ ' nothing: -none-',
+ ])
+
+
+class DebugTraceTest(CoverageTest):
+ """Tests of debug output."""
+
+ def f1_debug_output(self, debug):
+ """Runs some code with `debug` option, returns the debug output."""
+ # Make code to run.
+ self.make_file("f1.py", """\
+ def f1(x):
+ return x+1
+
+ for i in range(5):
+ f1(i)
+ """)
+
+ debug_out = StringIO()
+ cov = coverage.coverage(debug=debug, debug_file=debug_out)
+ self.start_import_stop(cov, "f1")
+
+ out_lines = debug_out.getvalue().splitlines()
+ return out_lines
+
+ def test_debug_no_trace(self):
+ out_lines = self.f1_debug_output([])
+
+ # We should have no output at all.
+ self.assertFalse(out_lines)
+
+ def test_debug_trace(self):
+ out_lines = self.f1_debug_output(["trace"])
+
+ # We should have a line like "Tracing 'f1.py'"
+ self.assertIn("Tracing 'f1.py'", out_lines)
+
+ # We should lines like "Not tracing 'collector.py'..."
+ coverage_lines = lines_matching(
+ out_lines,
+ r"^Not tracing .*: is part of coverage.py$"
+ )
+ self.assertTrue(coverage_lines)
+
+ def test_debug_trace_pid(self):
+ out_lines = self.f1_debug_output(["trace", "pid"])
+
+ # Now our lines are always prefixed with the process id.
+ pid_prefix = "^pid %5d: " % os.getpid()
+ pid_lines = lines_matching(out_lines, pid_prefix)
+ self.assertEqual(pid_lines, out_lines)
+
+ # We still have some tracing, and some not tracing.
+ self.assertTrue(lines_matching(out_lines, pid_prefix + "Tracing "))
+ self.assertTrue(lines_matching(out_lines, pid_prefix + "Not tracing "))
+
+ def test_debug_config(self):
+ out_lines = self.f1_debug_output(["config"])
+
+ labels = """
+ attempted_config_files branch config_files cover_pylib data_file
+ debug exclude_list extra_css html_dir html_title ignore_errors
+ include omit parallel partial_always_list partial_list paths
+ precision show_missing source timid xml_output
+ """.split()
+ for label in labels:
+ label_pat = r"^\s*%s: " % label
+ self.assertEqual(len(lines_matching(out_lines, label_pat)), 1)
+
+ def test_debug_sys(self):
+ out_lines = self.f1_debug_output(["sys"])
+
+ labels = """
+ version coverage cover_dir pylib_dirs tracer config_files
+ configs_read data_path python platform implementation executable
+ cwd path environment command_line cover_match pylib_match
+ """.split()
+ for label in labels:
+ label_pat = r"^\s*%s: " % label
+ self.assertEqual(len(lines_matching(out_lines, label_pat)), 1)
+
+
+def lines_matching(lines, pat):
+ """Gives the list of lines from `lines` that match `pat`."""
+ return [l for l in lines if re.search(pat, l)]
diff --git a/tests/test_farm.py b/tests/test_farm.py
index e514e66..fee2806 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -195,9 +195,9 @@ class FarmTestCase(object):
"""Compare files matching `file_pattern` in `dir1` and `dir2`.
`dir2` is interpreted as a prefix, with Python version numbers appended
- to find the actual directory to compare with. "foo" will compare against
- "foo_v241", "foo_v24", "foo_v2", or "foo", depending on which directory
- is found first.
+ to find the actual directory to compare with. "foo" will compare
+ against "foo_v241", "foo_v24", "foo_v2", or "foo", depending on which
+ directory is found first.
`size_within` is a percentage delta for the file sizes. If non-zero,
then the file contents are not compared (since they are expected to
diff --git a/tests/test_files.py b/tests/test_files.py
index 509c23b..eeb2264 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -58,16 +58,19 @@ class MatcherTest(CoverageTest):
file4 = self.make_file("sub3/file4.py")
file5 = self.make_file("sub3/file5.c")
fl = FileLocator()
- tm = TreeMatcher([
+ trees = [
fl.canonical_filename("sub"),
fl.canonical_filename(file4),
- ])
+ ]
+ tm = TreeMatcher(trees)
self.assertTrue(tm.match(fl.canonical_filename(file1)))
self.assertTrue(tm.match(fl.canonical_filename(file2)))
self.assertFalse(tm.match(fl.canonical_filename(file3)))
self.assertTrue(tm.match(fl.canonical_filename(file4)))
self.assertFalse(tm.match(fl.canonical_filename(file5)))
+ self.assertEqual(tm.info(), trees)
+
def test_fnmatch_matcher(self):
file1 = self.make_file("sub/file1.py")
file2 = self.make_file("sub/file2.c")
@@ -82,6 +85,8 @@ class MatcherTest(CoverageTest):
self.assertTrue(fnm.match(fl.canonical_filename(file4)))
self.assertFalse(fnm.match(fl.canonical_filename(file5)))
+ self.assertEqual(fnm.info(), ["*.py", "*/sub2/*"])
+
class PathAliasesTest(CoverageTest):
"""Tests for coverage/files.py:PathAliases"""
diff --git a/tests/test_html.py b/tests/test_html.py
index 40852ac..c004303 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -52,8 +52,6 @@ class HtmlDeltaTest(HtmlTestHelpers, CoverageTest):
# so grab it here to restore it later.
self.real_coverage_version = coverage.__version__
- self.maxDiff = None
-
def tearDown(self):
coverage.__version__ = self.real_coverage_version
super(HtmlDeltaTest, self).tearDown()
@@ -291,6 +289,7 @@ class HtmlTest(CoverageTest):
os.remove("sub/another.py")
missing_file = os.path.join(self.temp_dir, "sub", "another.py")
+ missing_file = os.path.realpath(missing_file)
self.assertRaisesRegexp(NoSource,
"(?i)No source for code: '%s'" % re.escape(missing_file),
cov.html_report
diff --git a/tests/test_misc.py b/tests/test_misc.py
index e7fa436..50ddb17 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -1,4 +1,5 @@
"""Tests of miscellaneous stuff."""
+
import sys
from coverage.misc import Hasher, file_be_gone
diff --git a/tests/test_process.py b/tests/test_process.py
index 8554eb5..97e2f82 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -583,7 +583,7 @@ class ProcessStartupTest(CoverageTest):
pass
finally:
pth.close()
- else: # pragma: not covered
+ else: # pragma: not covered
raise Exception("Couldn't find a place for the .pth file")
def tearDown(self):
@@ -615,7 +615,9 @@ class ProcessStartupTest(CoverageTest):
import main # pylint: disable=F0401,W0612
self.assertEqual(open("out.txt").read(), "Hello, world!\n")
+
# Read the data from .coverage
+ self.assert_exists(".mycovdata")
data = coverage.CoverageData()
data.read_file(".mycovdata")
self.assertEqual(data.summary()['sub.py'], 3)