summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_fnmatch.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_fnmatch.py')
-rw-r--r--Lib/test/test_fnmatch.py47
1 files changed, 32 insertions, 15 deletions
diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py
index 37ec50d..482835d 100644
--- a/Lib/test/test_fnmatch.py
+++ b/Lib/test/test_fnmatch.py
@@ -1,17 +1,12 @@
"""Test cases for the fnmatch module."""
-from test import test_support
+from test import support
import unittest
-from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache
-from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _purge
-
+from fnmatch import fnmatch, fnmatchcase, translate, filter
class FnmatchTestCase(unittest.TestCase):
- def tearDown(self):
- _purge()
-
def check_match(self, filename, pattern, should_match=1, fn=fnmatch):
if should_match:
self.assertTrue(fn(filename, pattern),
@@ -49,23 +44,45 @@ class FnmatchTestCase(unittest.TestCase):
check('\nfoo', 'foo*', False)
check('\n', '*')
+ def test_mix_bytes_str(self):
+ self.assertRaises(TypeError, fnmatch, 'test', b'*')
+ self.assertRaises(TypeError, fnmatch, b'test', '*')
+ self.assertRaises(TypeError, fnmatchcase, 'test', b'*')
+ self.assertRaises(TypeError, fnmatchcase, b'test', '*')
+
def test_fnmatchcase(self):
check = self.check_match
check('AbC', 'abc', 0, fnmatchcase)
check('abc', 'AbC', 0, fnmatchcase)
- def test_cache_clearing(self):
- # check that caches do not grow too large
- # http://bugs.python.org/issue7846
+ def test_bytes(self):
+ self.check_match(b'test', b'te*')
+ self.check_match(b'test\xff', b'te*\xff')
+ self.check_match(b'foo\nbar', b'foo*')
+
+class TranslateTestCase(unittest.TestCase):
+
+ def test_translate(self):
+ self.assertEqual(translate('*'), '.*\Z(?ms)')
+ self.assertEqual(translate('?'), '.\Z(?ms)')
+ self.assertEqual(translate('a?b*'), 'a.b.*\Z(?ms)')
+ self.assertEqual(translate('[abc]'), '[abc]\Z(?ms)')
+ self.assertEqual(translate('[]]'), '[]]\Z(?ms)')
+ self.assertEqual(translate('[!x]'), '[^x]\Z(?ms)')
+ self.assertEqual(translate('[^x]'), '[\\^x]\Z(?ms)')
+ self.assertEqual(translate('[x'), '\\[x\Z(?ms)')
+
+
+class FilterTestCase(unittest.TestCase):
- # string pattern cache
- for i in range(_MAXCACHE + 1):
- fnmatch('foo', '?' * i)
+ def test_filter(self):
+ self.assertEqual(filter(['a', 'b'], 'a'), ['a'])
- self.assertLessEqual(len(_cache), _MAXCACHE)
def test_main():
- test_support.run_unittest(FnmatchTestCase)
+ support.run_unittest(FnmatchTestCase,
+ TranslateTestCase,
+ FilterTestCase)
if __name__ == "__main__":