summaryrefslogtreecommitdiff
path: root/Lib/importlib/test/test_api.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-03-17 16:58:12 +0100
committerGeorg Brandl <georg@python.org>2012-03-17 16:58:12 +0100
commitffd4830f6ab0942a463772a01a91f051bfa2d376 (patch)
tree14d5f982ed3d51197f0dd69370d3f6002aec8e1e /Lib/importlib/test/test_api.py
parent206a0cc1b0f2545eef212be6210b4bf7008815ba (diff)
parent5d6d9423be73e8c6f3f18fa3e006573fc5836236 (diff)
downloadcpython-ffd4830f6ab0942a463772a01a91f051bfa2d376.tar.gz
merge with 3.2
Diffstat (limited to 'Lib/importlib/test/test_api.py')
-rw-r--r--Lib/importlib/test/test_api.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py
index a151626de7..cc147c200b 100644
--- a/Lib/importlib/test/test_api.py
+++ b/Lib/importlib/test/test_api.py
@@ -84,6 +84,34 @@ class ImportModuleTests(unittest.TestCase):
importlib.import_module('a.b')
self.assertEqual(b_load_count, 1)
+
+class InvalidateCacheTests(unittest.TestCase):
+
+ def test_method_called(self):
+ # If defined the method should be called.
+ class InvalidatingNullFinder:
+ def __init__(self, *ignored):
+ self.called = False
+ def find_module(self, *args):
+ return None
+ def invalidate_caches(self):
+ self.called = True
+
+ key = 'gobledeegook'
+ ins = InvalidatingNullFinder()
+ sys.path_importer_cache[key] = ins
+ self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key))
+ importlib.invalidate_caches()
+ self.assertTrue(ins.called)
+
+ def test_method_lacking(self):
+ # There should be no issues if the method is not defined.
+ key = 'gobbledeegook'
+ sys.path_importer_cache[key] = imp.NullImporter('abc')
+ self.addCleanup(lambda: sys.path_importer_cache.__delitem__(key))
+ importlib.invalidate_caches() # Shouldn't trigger an exception.
+
+
def test_main():
from test.support import run_unittest
run_unittest(ImportModuleTests)