[Python-checkins] r83101 - python/branches/py3k/Lib/test/test_fnmatch.py

brett.cannon python-checkins at python.org
Fri Jul 23 18:23:13 CEST 2010


Author: brett.cannon
Date: Fri Jul 23 18:23:13 2010
New Revision: 83101

Log:
Add tests for fnmatch.filter and translate.

Partially closes issue 9356. Thanks to Brian Brazil for the patch.


Modified:
   python/branches/py3k/Lib/test/test_fnmatch.py

Modified: python/branches/py3k/Lib/test/test_fnmatch.py
==============================================================================
--- python/branches/py3k/Lib/test/test_fnmatch.py	(original)
+++ python/branches/py3k/Lib/test/test_fnmatch.py	Fri Jul 23 18:23:13 2010
@@ -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 @@
         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__":


More information about the Python-checkins mailing list