diff --git a/Lib/fnmatch.py b/Lib/fnmatch.py index 26ae4ccb14d..be1fd1d16ce 100644 --- a/Lib/fnmatch.py +++ b/Lib/fnmatch.py @@ -12,12 +12,17 @@ import re -__all__ = ["filter", "fnmatch","fnmatchcase","translate"] +__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"] _cache = {} # Maps text patterns to compiled regexen. _cacheb = {} # Ditto for bytes patterns. _MAXCACHE = 100 # Maximum size of caches +def _purge(): + """Clear the pattern cache""" + _cache.clear() + _cacheb.clear() + def fnmatch(name, pat): """Test whether FILENAME matches PATTERN. diff --git a/Lib/test/test_fnmatch.py b/Lib/test/test_fnmatch.py index f2966ad7240..abf88114619 100644 --- a/Lib/test/test_fnmatch.py +++ b/Lib/test/test_fnmatch.py @@ -3,10 +3,14 @@ from test import support import unittest -from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb +from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _cacheb, _purge class FnmatchTestCase(unittest.TestCase): + + def tearDown(self): + _purge() + def check_match(self, filename, pattern, should_match=1): if should_match: self.assertTrue(fnmatch(filename, pattern),