Updated for 2.1b2 distribution.
[python/dscho.git] / Lib / test / test_fnmatch.py
blob40c4dfd1160ca22f66dde7e39e9b4c2f8ba52817
1 """Test cases for the fnmatch module."""
3 import re
4 import test_support
5 import unittest
7 from fnmatch import fnmatch, fnmatchcase
10 class FnmatchTestCase(unittest.TestCase):
11 def check_match(self, filename, pattern, should_match=1):
12 if should_match:
13 self.assert_(fnmatch(filename, pattern),
14 "expected %r to match pattern %r"
15 % (filename, pattern))
16 else:
17 self.assert_(not fnmatch(filename, pattern),
18 "expected %r not to match pattern %r"
19 % (filename, pattern))
21 def test_fnmatch(self):
22 check = self.check_match
23 check('abc', 'abc')
24 check('abc', '?*?')
25 check('abc', '???*')
26 check('abc', '*???')
27 check('abc', '???')
28 check('abc', '*')
29 check('abc', 'ab[cd]')
30 check('abc', 'ab[!de]')
31 check('abc', 'ab[de]', 0)
32 check('a', '??', 0)
33 check('a', 'b', 0)
35 # these test that '\' is handled correctly in character sets;
36 # see SF bug #???
37 check('\\', r'[\]')
38 check('a', r'[!\]')
39 check('\\', r'[!\]', 0)
42 test_support.run_unittest(FnmatchTestCase)