1 """Test cases for the fnmatch module."""
3 from test
import test_support
6 from fnmatch
import fnmatch
, fnmatchcase
9 class FnmatchTestCase(unittest
.TestCase
):
10 def check_match(self
, filename
, pattern
, should_match
=1, fn
=fnmatch
):
12 self
.assertTrue(fn(filename
, pattern
),
13 "expected %r to match pattern %r"
14 % (filename
, pattern
))
16 self
.assertTrue(not fn(filename
, pattern
),
17 "expected %r not to match pattern %r"
18 % (filename
, pattern
))
20 def test_fnmatch(self
):
21 check
= self
.check_match
28 check('abc', 'ab[cd]')
29 check('abc', 'ab[!de]')
30 check('abc', 'ab[de]', 0)
34 # these test that '\' is handled correctly in character sets;
38 check('\\', r
'[!\]', 0)
40 # test that filenames with newlines in them are handled correctly.
41 # http://bugs.python.org/issue6665
42 check('foo\nbar', 'foo*')
43 check('foo\nbar\n', 'foo*')
44 check('\nfoo', 'foo*', False)
47 def test_fnmatchcase(self
):
48 check
= self
.check_match
49 check('AbC', 'abc', 0, fnmatchcase
)
50 check('abc', 'AbC', 0, fnmatchcase
)
54 test_support
.run_unittest(FnmatchTestCase
)
57 if __name__
== "__main__":