mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Rewrite the code implementing __import__ for importlib. Now it is much simpler
and relies much more on meta path finders to abstract out various parts of import. As part of this the semantics for import_module tightened up and now follow __import__ much more closely (biggest thing is that the 'package' argument must now already be imported, else a SystemError is raised).
This commit is contained in:
parent
887b3f2625
commit
2c318a1390
9 changed files with 117 additions and 502 deletions
|
@ -1,6 +1,8 @@
|
|||
import unittest
|
||||
import importlib
|
||||
from . import util
|
||||
import imp
|
||||
import importlib
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
|
||||
class ImportModuleTests(unittest.TestCase):
|
||||
|
@ -33,6 +35,7 @@ class ImportModuleTests(unittest.TestCase):
|
|||
relative_name = '.{0}'.format(module_name)
|
||||
with util.mock_modules(pkg_long_name, absolute_name) as mock:
|
||||
with util.import_state(meta_path=[mock]):
|
||||
importlib.import_module(pkg_name)
|
||||
module = importlib.import_module(relative_name, pkg_name)
|
||||
self.assertEqual(module.__name__, absolute_name)
|
||||
|
||||
|
@ -44,6 +47,7 @@ class ImportModuleTests(unittest.TestCase):
|
|||
name = '{0}.mod'.format(pkg_name)
|
||||
with util.mock_modules(pkg_long_name, name) as mock:
|
||||
with util.import_state(meta_path=[mock]):
|
||||
importlib.import_module(pkg_name)
|
||||
module = importlib.import_module(name, pkg_name)
|
||||
self.assertEqual(module.__name__, name)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue