Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9175114

Browse files
committed
Add test cases for the fnmatch module.
1 parent cd1b1dd commit 9175114

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lib/test/output/test_fnmatch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test_fnmatch

Lib/test/test_fnmatch.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Test cases for the fnmatch module."""
2+
3+
import re
4+
import test_support
5+
import unittest
6+
7+
from fnmatch import fnmatch, fnmatchcase
8+
9+
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))
20+
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)
34+
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)
40+
41+
42+
test_support.run_unittest(FnmatchTestCase)

0 commit comments

Comments
 (0)