0001 """Test cases for the fnmatch module.""" 0002 0003 from test import test_support 0004 import unittest 0005 0006 from fnmatch import fnmatch, fnmatchcase 0007 0008 0009 class FnmatchTestCase(unittest.TestCase): 0010 def check_match(self, filename, pattern, should_match=1): 0011 if should_match: 0012 self.assert_(fnmatch(filename, pattern), 0013 "expected %r to match pattern %r" 0014 % (filename, pattern)) 0015 else: 0016 self.assert_(not fnmatch(filename, pattern), 0017 "expected %r not to match pattern %r" 0018 % (filename, pattern)) 0019 0020 def test_fnmatch(self): 0021 check = self.check_match 0022 check('abc', 'abc') 0023 check('abc', '?*?') 0024 check('abc', '???*') 0025 check('abc', '*???') 0026 check('abc', '???') 0027 check('abc', '*') 0028 check('abc', 'ab[cd]') 0029 check('abc', 'ab[!de]') 0030 check('abc', 'ab[de]', 0) 0031 check('a', '??', 0) 0032 check('a', 'b', 0) 0033 0034 # these test that '\' is handled correctly in character sets; 0035 # see SF bug #??? 0036 check('\\', r'[\]') 0037 check('a', r'[!\]') 0038 check('\\', r'[!\]', 0) 0039 0040 0041 def test_main(): 0042 test_support.run_unittest(FnmatchTestCase) 0043 0044 0045 if __name__ == "__main__": 0046 test_main() 0047
Generated by PyXR 0.9.4