mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Merged revisions 74584 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r74584 | brett.cannon | 2009-08-29 20:47:36 -0700 (Sat, 29 Aug 2009) | 3 lines Have importlib raise ImportError if None is found in sys.modules. This matches current import semantics. ........
This commit is contained in:
parent
af0312af7a
commit
8a1a59f0ec
3 changed files with 23 additions and 5 deletions
|
@ -17,15 +17,25 @@ class UseCache(unittest.TestCase):
|
|||
loader returns) [from cache on return]. This also applies to imports of
|
||||
things contained within a package and thus get assigned as an attribute
|
||||
[from cache to attribute] or pulled in thanks to a fromlist import
|
||||
[from cache for fromlist].
|
||||
[from cache for fromlist]. But if sys.modules contains None then
|
||||
ImportError is raised [None in cache].
|
||||
|
||||
"""
|
||||
def test_using_cache(self):
|
||||
# [use cache]
|
||||
module_to_use = "some module found!"
|
||||
sys.modules['some_module'] = module_to_use
|
||||
module = import_util.import_('some_module')
|
||||
self.assertEqual(id(module_to_use), id(module))
|
||||
with util.uncache(module_to_use):
|
||||
sys.modules['some_module'] = module_to_use
|
||||
module = import_util.import_('some_module')
|
||||
self.assertEqual(id(module_to_use), id(module))
|
||||
|
||||
def test_None_in_cache(self):
|
||||
#[None in cache]
|
||||
name = 'using_None'
|
||||
with util.uncache(name):
|
||||
sys.modules[name] = None
|
||||
with self.assertRaises(ImportError):
|
||||
import_util.import_(name)
|
||||
|
||||
def create_mock(self, *names, return_=None):
|
||||
mock = util.mock_modules(*names)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue