From 4b16e130cc0262699a186b1917b2a9896abe9f25 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 23 Jul 2010 16:23:13 +0000 Subject: Add tests for fnmatch.filter and translate. Partially closes issue 9356. Thanks to Brian Brazil for the patch. --- Lib/test/test_fnmatch.py | 26 ++++++++++++++++++++++++-- 1 file 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__": -- cgit v0.12