PageRenderTime 101ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/Lib/test/test_fnmatch.py

http://unladen-swallow.googlecode.com/
Python | 46 lines | 33 code | 10 blank | 3 comment | 2 complexity | 0ef68988f81a89858fbe90aef06693b7 MD5 | raw file
 1"""Test cases for the fnmatch module."""
 2
 3from test import test_support
 4import unittest
 5
 6from fnmatch import fnmatch, fnmatchcase
 7
 8
 9class FnmatchTestCase(unittest.TestCase):
10    def check_match(self, filename, pattern, should_match=1):
11        if should_match:
12            self.assert_(fnmatch(filename, pattern),
13                         "expected %r to match pattern %r"
14                         % (filename, pattern))
15        else:
16            self.assert_(not fnmatch(filename, pattern),
17                         "expected %r not to match pattern %r"
18                         % (filename, pattern))
19
20    def test_fnmatch(self):
21        check = self.check_match
22        check('abc', 'abc')
23        check('abc', '?*?')
24        check('abc', '???*')
25        check('abc', '*???')
26        check('abc', '???')
27        check('abc', '*')
28        check('abc', 'ab[cd]')
29        check('abc', 'ab[!de]')
30        check('abc', 'ab[de]', 0)
31        check('a', '??', 0)
32        check('a', 'b', 0)
33
34        # these test that '\' is handled correctly in character sets;
35        # see SF bug #???
36        check('\\', r'[\]')
37        check('a', r'[!\]')
38        check('\\', r'[!\]', 0)
39
40
41def test_main():
42    test_support.run_unittest(FnmatchTestCase)
43
44
45if __name__ == "__main__":
46    test_main()