Commit 4b16e130 authored by Brett Cannon's avatar Brett Cannon

Add tests for fnmatch.filter and translate.

Partially closes issue 9356. Thanks to Brian Brazil for the patch.
parent cc143201
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
from test import support from test import support
import unittest 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): class FnmatchTestCase(unittest.TestCase):
...@@ -80,8 +81,29 @@ class FnmatchTestCase(unittest.TestCase): ...@@ -80,8 +81,29 @@ class FnmatchTestCase(unittest.TestCase):
self.assertLessEqual(len(_cacheb), _MAXCACHE) 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(): def test_main():
support.run_unittest(FnmatchTestCase) support.run_unittest(FnmatchTestCase,
TranslateTestCase,
FilterTestCase)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment