summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/coveragetest.py6
-rw-r--r--test/test_cmdline.py40
-rw-r--r--test/test_files.py39
-rw-r--r--test/test_testing.py4
-rw-r--r--test/test_testplugin.py2
5 files changed, 63 insertions, 28 deletions
diff --git a/test/coveragetest.py b/test/coveragetest.py
index 9b85b034..f09afc1f 100644
--- a/test/coveragetest.py
+++ b/test/coveragetest.py
@@ -121,12 +121,14 @@ class CoverageTest(TestCase):
"""Return the data written to stderr during the test."""
return self.captured_stderr.getvalue()
- def make_file(self, filename, text):
+ def make_file(self, filename, text=""):
"""Create a temp file.
`filename` is the path to the file, including directories if desired,
and `text` is the content.
+ Returns the path to the file.
+
"""
# Tests that call `make_file` should be run in a temp environment.
assert self.run_in_temp_dir
@@ -142,6 +144,8 @@ class CoverageTest(TestCase):
f.write(text)
f.close()
+ return filename
+
def import_module(self, modname):
"""Import the module named modname, and return the module object."""
modfile = modname + '.py'
diff --git a/test/test_cmdline.py b/test/test_cmdline.py
index cf20ba7f..9c0e1154 100644
--- a/test/test_cmdline.py
+++ b/test/test_cmdline.py
@@ -16,7 +16,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, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.load()\n"""
def model_object(self):
@@ -96,7 +96,7 @@ class ClassicCmdLineTest(CmdLineTest):
def testErase(self):
# coverage -e
self.cmd_executes("-e", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.erase()
""")
self.cmd_executes_same("-e", "--erase")
@@ -106,7 +106,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, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -115,7 +115,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, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -124,7 +124,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, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=True, branch=None, config_file=True, source=None, include=None, omit=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py', 'abc', '123'])
@@ -133,7 +133,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, include=None, omit=None)
+ .coverage(cover_pylib=True, data_suffix=True, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.load()
.start()
.run_python_file('foo.py', ['foo.py', '-a', '-b'])
@@ -150,7 +150,7 @@ class ClassicCmdLineTest(CmdLineTest):
def testCombine(self):
# coverage -c
self.cmd_executes("-c", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=None)
.load()
.combine()
.save()
@@ -172,13 +172,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, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
.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, 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"])
.load()
.report(ignore_errors=None, omit=["fooey", "booey"], include=None,
morfs=[], show_missing=None)
@@ -217,13 +217,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, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
.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, 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"])
.load()
.annotate(directory=None, ignore_errors=None,
omit=["fooey", "booey"], include=None, morfs=[])
@@ -262,13 +262,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, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
.load()
.html_report(directory=None, ignore_errors=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, 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"])
.load()
.html_report(directory=None, ignore_errors=None,
omit=["fooey", "booey"], include=None, morfs=[])
@@ -465,7 +465,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, include=None, omit=None)
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=True, config_file=True, source=None, include=None, omit=None)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -473,7 +473,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", 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)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -481,7 +481,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, 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)
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -489,7 +489,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, 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"])
.erase()
.start()
.run_python_file('foo.py', ['foo.py'])
@@ -499,7 +499,7 @@ class NewCmdLineTest(CmdLineTest):
self.cmd_executes("run --include=pre1,pre2 --omit=opre1,opre2 foo.py",
"""\
.coverage(cover_pylib=None, data_suffix=None, timid=None,
- branch=None, config_file=True,
+ branch=None, config_file=True, source=None,
include=["pre1", "pre2"],
omit=["opre1", "opre2"])
.erase()
@@ -528,13 +528,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, include=None, omit=["fooey"])
+ .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, source=None, include=None, omit=["fooey"])
.load()
.xml_report(ignore_errors=None, omit=["fooey"], include=None, morfs=[],
outfile="coverage.xml")
""")
self.cmd_executes("xml --omit fooey,booey", """\
- .coverage(cover_pylib=None, data_suffix=None, timid=None, branch=None, config_file=True, 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"])
.load()
.xml_report(ignore_errors=None, omit=["fooey", "booey"], include=None,
morfs=[], outfile="coverage.xml")
diff --git a/test/test_files.py b/test/test_files.py
index ca9b4e0d..db835e5e 100644
--- a/test/test_files.py
+++ b/test/test_files.py
@@ -2,7 +2,7 @@
import os, sys
-from coverage.files import FileLocator
+from coverage.files import FileLocator, TreeMatcher, FnmatchMatcher
sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
from coveragetest import CoverageTest
@@ -16,7 +16,7 @@ class FileLocatorTest(CoverageTest):
return os.path.join(os.getcwd(), os.path.normpath(p))
def test_simple(self):
- self.make_file("hello.py", "#hello")
+ self.make_file("hello.py")
fl = FileLocator()
self.assertEqual(fl.relative_filename("hello.py"), "hello.py")
a = self.abs_path("hello.py")
@@ -24,8 +24,8 @@ class FileLocatorTest(CoverageTest):
self.assertEqual(fl.relative_filename(a), "hello.py")
def test_peer_directories(self):
- self.make_file("sub/proj1/file1.py", "file1")
- self.make_file("sub/proj2/file2.py", "file2")
+ self.make_file("sub/proj1/file1.py")
+ self.make_file("sub/proj2/file2.py")
a1 = self.abs_path("sub/proj1/file1.py")
a2 = self.abs_path("sub/proj2/file2.py")
d = os.path.normpath("sub/proj1")
@@ -33,3 +33,34 @@ class FileLocatorTest(CoverageTest):
fl = FileLocator()
self.assertEqual(fl.relative_filename(a1), "file1.py")
self.assertEqual(fl.relative_filename(a2), a2)
+
+ def test_tree_matcher(self):
+ file1 = self.make_file("sub/file1.py")
+ file2 = self.make_file("sub/file2.c")
+ file3 = self.make_file("sub2/file3.h")
+ file4 = self.make_file("sub3/file4.py")
+ file5 = self.make_file("sub3/file5.c")
+ fl = FileLocator()
+ tm = TreeMatcher([
+ fl.canonical_filename("sub"),
+ fl.canonical_filename(file4),
+ ])
+ 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)))
+
+ def test_fnmatch_matcher(self):
+ file1 = self.make_file("sub/file1.py")
+ file2 = self.make_file("sub/file2.c")
+ file3 = self.make_file("sub2/file3.h")
+ file4 = self.make_file("sub3/file4.py")
+ file5 = self.make_file("sub3/file5.c")
+ fl = FileLocator()
+ fnm = FnmatchMatcher(["*.py", "*/sub2/*"])
+ self.assertTrue(fnm.match(fl.canonical_filename(file1)))
+ self.assertFalse(fnm.match(fl.canonical_filename(file2)))
+ self.assertTrue(fnm.match(fl.canonical_filename(file3)))
+ self.assertTrue(fnm.match(fl.canonical_filename(file4)))
+ self.assertFalse(fnm.match(fl.canonical_filename(file5)))
diff --git a/test/test_testing.py b/test/test_testing.py
index 9bbb7cca..1cae9310 100644
--- a/test/test_testing.py
+++ b/test/test_testing.py
@@ -107,5 +107,5 @@ class CoverageTestTest(CoverageTest):
self.make_file("sub/second.txt", "Second")
self.assertEqual(open("sub/second.txt").read(), "Second")
# A deeper directory
- self.make_file("sub/deeper/evenmore/third.txt", "Third")
- self.assertEqual(open("sub/deeper/evenmore/third.txt").read(), "Third")
+ self.make_file("sub/deeper/evenmore/third.txt")
+ self.assertEqual(open("sub/deeper/evenmore/third.txt").read(), "")
diff --git a/test/test_testplugin.py b/test/test_testplugin.py
index c5bcca01..b012ca6a 100644
--- a/test/test_testplugin.py
+++ b/test/test_testplugin.py
@@ -14,7 +14,7 @@ class TestCoverage(PluginTester, unittest.TestCase):
@py.test.mark.skipif(True) # "requires nose test runner"
def test_output(self):
- assert "Processing Coverage..." in self.output, (
+ assert "Processing coverage..." in self.output, (
"got: %s" % self.output)
def makeSuite(self):
class TC(unittest.TestCase):