| OLD | NEW |
| 1 """Test cases for the fnmatch module.""" | 1 """Test cases for the fnmatch module.""" |
| 2 | 2 |
| 3 from test import support | 3 from test import support |
| 4 import unittest | 4 import unittest |
| 5 import sys |
| 5 | 6 |
| 6 from fnmatch import fnmatch, fnmatchcase | 7 from fnmatch import fnmatch, fnmatchcase, filter |
| 7 | 8 |
| 8 | 9 |
| 9 class FnmatchTestCase(unittest.TestCase): | 10 class FnmatchTestCase(unittest.TestCase): |
| 10 def check_match(self, filename, pattern, should_match=1): | 11 def check_match(self, filename, pattern, should_match=1): |
| 11 if should_match: | 12 if should_match: |
| 12 self.assert_(fnmatch(filename, pattern), | 13 self.assert_(fnmatch(filename, pattern), |
| 13 "expected %r to match pattern %r" | 14 "expected %r to match pattern %r" |
| 14 % (filename, pattern)) | 15 % (filename, pattern)) |
| 15 else: | 16 else: |
| 16 self.assert_(not fnmatch(filename, pattern), | 17 self.assert_(not fnmatch(filename, pattern), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 30 check('abc', 'ab[de]', 0) | 31 check('abc', 'ab[de]', 0) |
| 31 check('a', '??', 0) | 32 check('a', '??', 0) |
| 32 check('a', 'b', 0) | 33 check('a', 'b', 0) |
| 33 | 34 |
| 34 # these test that '\' is handled correctly in character sets; | 35 # these test that '\' is handled correctly in character sets; |
| 35 # see SF bug #??? | 36 # see SF bug #??? |
| 36 check('\\', r'[\]') | 37 check('\\', r'[\]') |
| 37 check('a', r'[!\]') | 38 check('a', r'[!\]') |
| 38 check('\\', r'[!\]', 0) | 39 check('\\', r'[!\]', 0) |
| 39 | 40 |
| 41 def test_filter_bytes(self): |
| 42 charset = sys.getfilesystemencoding() |
| 43 abc = "abc".encode(charset) |
| 44 names = ["abc", abc] |
| 45 self.assertEqual(filter(names, "*"), names) |
| 40 | 46 |
| 41 def test_main(): | 47 def test_main(): |
| 42 support.run_unittest(FnmatchTestCase) | 48 support.run_unittest(FnmatchTestCase) |
| 43 | 49 |
| 44 | 50 |
| 45 if __name__ == "__main__": | 51 if __name__ == "__main__": |
| 46 test_main() | 52 test_main() |
| OLD | NEW |