diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2014-03-11 07:27:59 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2014-03-11 07:27:59 -0400 |
commit | 5898eeefc6c9885782ede16b65fc04086aed2fcd (patch) | |
tree | 0a0675b7321fc9fca0a793b8bb49211004cb43a2 /tests/test_files.py | |
parent | 8cc4ffa19dd13d8433878aab3458f6c7572e74b5 (diff) | |
download | python-coveragepy-git-5898eeefc6c9885782ede16b65fc04086aed2fcd.tar.gz |
Cleaner tests of the file matchers
Diffstat (limited to 'tests/test_files.py')
-rw-r--r-- | tests/test_files.py | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/tests/test_files.py b/tests/test_files.py index 85c0ac7b..42457a5c 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -50,41 +50,49 @@ class FileLocatorTest(CoverageTest): class MatcherTest(CoverageTest): """Tests of file matchers.""" + def setUp(self): + super(MatcherTest, self).setUp() + self.fl = FileLocator() + + def assertMatches(self, matcher, filepath, matches): + """The `matcher` should agree with `matches` about `filepath`.""" + canonical = self.fl.canonical_filename(filepath) + self.assertEqual( + matcher.match(canonical), matches, + "File %s should have matched as %s" % (filepath, matches) + ) + 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") + matches_to_try = [ + (self.make_file("sub/file1.py"), True), + (self.make_file("sub/file2.c"), True), + (self.make_file("sub2/file3.h"), False), + (self.make_file("sub3/file4.py"), True), + (self.make_file("sub3/file5.c"), False), + ] fl = FileLocator() trees = [ fl.canonical_filename("sub"), - fl.canonical_filename(file4), + fl.canonical_filename("sub3/file4.py"), ] 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) + for filepath, matches in matches_to_try: + self.assertMatches(tm, filepath, matches) 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") + matches_to_try = [ + (self.make_file("sub/file1.py"), True), + (self.make_file("sub/file2.c"), False), + (self.make_file("sub2/file3.h"), True), + (self.make_file("sub3/file4.py"), True), + (self.make_file("sub3/file5.c"), False), + ] 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))) - self.assertEqual(fnm.info(), ["*.py", "*/sub2/*"]) + for filepath, matches in matches_to_try: + self.assertMatches(fnm, filepath, matches) class PathAliasesTest(CoverageTest): |