diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-06 22:09:26 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-09-06 22:09:26 -0400 |
commit | d918e93a2a87aa730932d901b3bc19291b1a2dc9 (patch) | |
tree | 92c5911cd355434c059bdfdbba02591dfb9f1347 | |
parent | 7cf52d30fc8238ab183790ec52b0be86c9df1818 (diff) | |
download | python-coveragepy-d918e93a2a87aa730932d901b3bc19291b1a2dc9.tar.gz |
Give the matchers a way to get info out of them.
-rw-r--r-- | coverage/files.py | 8 | ||||
-rw-r--r-- | tests/test_files.py | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/coverage/files.py b/coverage/files.py index 4c55151..8d154c6 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -144,6 +144,10 @@ class TreeMatcher(object): def __repr__(self): return "<TreeMatcher %r>" % self.dirs + def info(self): + """A list of strings for displaying when dumping state.""" + return self.dirs + def add(self, directory): """Add another directory to the list we match for.""" self.dirs.append(directory) @@ -169,6 +173,10 @@ class FnmatchMatcher(object): def __repr__(self): return "<FnmatchMatcher %r>" % self.pats + def info(self): + """A list of strings for displaying when dumping state.""" + return self.pats + def match(self, fpath): """Does `fpath` match one of our filename patterns?""" for pat in self.pats: 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""" |