diff options
author | Brett Cannon <bcannon@gmail.com> | 2010-07-23 16:23:13 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2010-07-23 16:23:13 (GMT) |
commit | 4b16e130cc0262699a186b1917b2a9896abe9f25 (patch) | |
tree | 6a392401d3baec7da67342625d7a3d5c123e41cb | |
parent | cc14320159d1c9cb1f2a0644eeb6b5c7a71c200d (diff) | |
download | cpython-4b16e130cc0262699a186b1917b2a9896abe9f25.zip cpython-4b16e130cc0262699a186b1917b2a9896abe9f25.tar.gz cpython-4b16e130cc0262699a186b1917b2a9896abe9f25.tar.bz2 |
Add tests for fnmatch.filter and translate.
Partially closes issue 9356. Thanks to Brian Brazil for the patch.
-rw-r--r-- | Lib/test/test_fnmatch.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py index 496f145..a93558c 100644 --- a/Lib/test/test_fnmatch.py +++ b/Lib/test/test_fnmatch.py @@ -3,7 +3,8 @@ from test import support import unittest -from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, purge +from fnmatch import (fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, purge, + translate, filter) class FnmatchTestCase(unittest.TestCase): @@ -80,8 +81,29 @@ class FnmatchTestCase(unittest.TestCase): self.assertLessEqual(len(_cacheb), _MAXCACHE) +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): + + def test_filter(self): + self.assertEqual(filter(['a', 'b'], 'a'), ['a']) + + def test_main(): - support.run_unittest(FnmatchTestCase) + support.run_unittest(FnmatchTestCase, + TranslateTestCase, + FilterTestCase) if __name__ == "__main__": |