diff options
author | Brett Cannon <brett@python.org> | 2012-02-27 23:15:42 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-02-27 23:15:42 (GMT) |
commit | b46a1793a787747d59e735e12471b3a309aa51da (patch) | |
tree | 61eacabf46212791ef3fa96f44c95c9593c8607d /Lib/importlib/test/test_api.py | |
parent | 9a4d7ddb6c09af03953840ff8a2c1215fc6742a7 (diff) | |
download | cpython-b46a1793a787747d59e735e12471b3a309aa51da.zip cpython-b46a1793a787747d59e735e12471b3a309aa51da.tar.gz cpython-b46a1793a787747d59e735e12471b3a309aa51da.tar.bz2 |
Update importlib.invalidate_caches() to be more general.
Diffstat (limited to 'Lib/importlib/test/test_api.py')
-rw-r--r-- | Lib/importlib/test/test_api.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/importlib/test/test_api.py b/Lib/importlib/test/test_api.py index a151626..cc147c2 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) |