Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_fnmatch.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | aa0d2d51fbde |
| children | 93c7f650937f 6768b2350c57 9c930a32cebb |
| rev | line source |
|---|---|
|
17110
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
1 """Test cases for the fnmatch module.""" |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
2 |
|
24364
aa0d2d51fbde
Get rid of relative imports in all unittests. Now anything that
Barry Warsaw <barry@python.org>
parents:
20013
diff
changeset
|
3 from test import test_support |
|
17110
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
4 import unittest |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
5 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
6 from fnmatch import fnmatch, fnmatchcase |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
7 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
8 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
9 class FnmatchTestCase(unittest.TestCase): |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
10 def check_match(self, filename, pattern, should_match=1): |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
11 if should_match: |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
12 self.assert_(fnmatch(filename, pattern), |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
13 "expected %r to match pattern %r" |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
14 % (filename, pattern)) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
15 else: |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
16 self.assert_(not fnmatch(filename, pattern), |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
17 "expected %r not to match pattern %r" |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
18 % (filename, pattern)) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
19 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
20 def test_fnmatch(self): |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
21 check = self.check_match |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
22 check('abc', 'abc') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
23 check('abc', '?*?') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
24 check('abc', '???*') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
25 check('abc', '*???') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
26 check('abc', '???') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
27 check('abc', '*') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
28 check('abc', 'ab[cd]') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
29 check('abc', 'ab[!de]') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
30 check('abc', 'ab[de]', 0) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
31 check('a', '??', 0) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
32 check('a', 'b', 0) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
33 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
34 # these test that '\' is handled correctly in character sets; |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
35 # see SF bug #??? |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
36 check('\\', r'[\]') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
37 check('a', r'[!\]') |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
38 check('\\', r'[!\]', 0) |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
39 |
|
7ed3e7a08a31
Add test cases for the fnmatch module.
Fred Drake <fdrake@acm.org>
parents:
diff
changeset
|
40 |
|
20013
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
41 def test_main(): |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
42 test_support.run_unittest(FnmatchTestCase) |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
43 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
44 |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
45 if __name__ == "__main__": |
|
e3184e46303b
Change the PyUnit-based tests to use the test_main() approach. This
Fred Drake <fdrake@acm.org>
parents:
17918
diff
changeset
|
46 test_main() |
