mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Rename importlib.util.ModuleManager to module_to_load so that the name
explains better what the context manager is providing.
This commit is contained in:
parent
335ab5b66f
commit
357c9fb055
6 changed files with 3568 additions and 3547 deletions
|
@ -7,7 +7,7 @@ import types
|
|||
import unittest
|
||||
|
||||
|
||||
class ModuleManagerTests(unittest.TestCase):
|
||||
class ModuleToLoadTests(unittest.TestCase):
|
||||
|
||||
module_name = 'ModuleManagerTest_module'
|
||||
|
||||
|
@ -19,7 +19,7 @@ class ModuleManagerTests(unittest.TestCase):
|
|||
# Test a new module is created, inserted into sys.modules, has
|
||||
# __initializing__ set to True after entering the context manager,
|
||||
# and __initializing__ set to False after exiting.
|
||||
with util.ModuleManager(self.module_name) as module:
|
||||
with util.module_to_load(self.module_name) as module:
|
||||
self.assertIn(self.module_name, sys.modules)
|
||||
self.assertIs(sys.modules[self.module_name], module)
|
||||
self.assertTrue(module.__initializing__)
|
||||
|
@ -28,19 +28,19 @@ class ModuleManagerTests(unittest.TestCase):
|
|||
def test_new_module_failed(self):
|
||||
# Test the module is removed from sys.modules.
|
||||
try:
|
||||
with util.ModuleManager(self.module_name) as module:
|
||||
with util.module_to_load(self.module_name) as module:
|
||||
self.assertIn(self.module_name, sys.modules)
|
||||
raise exception
|
||||
except Exception:
|
||||
self.assertNotIn(self.module_name, sys.modules)
|
||||
else:
|
||||
self.fail('importlib.util.ModuleManager swallowed an exception')
|
||||
self.fail('importlib.util.module_to_load swallowed an exception')
|
||||
|
||||
def test_reload(self):
|
||||
# Test that the same module is in sys.modules.
|
||||
created_module = imp.new_module(self.module_name)
|
||||
sys.modules[self.module_name] = created_module
|
||||
with util.ModuleManager(self.module_name) as module:
|
||||
with util.module_to_load(self.module_name) as module:
|
||||
self.assertIs(module, created_module)
|
||||
|
||||
def test_reload_failed(self):
|
||||
|
@ -48,12 +48,12 @@ class ModuleManagerTests(unittest.TestCase):
|
|||
created_module = imp.new_module(self.module_name)
|
||||
sys.modules[self.module_name] = created_module
|
||||
try:
|
||||
with util.ModuleManager(self.module_name) as module:
|
||||
with util.module_to_load(self.module_name) as module:
|
||||
raise Exception
|
||||
except Exception:
|
||||
self.assertIn(self.module_name, sys.modules)
|
||||
else:
|
||||
self.fail('importlib.util.ModuleManager swallowed an exception')
|
||||
self.fail('importlib.util.module_to_load swallowed an exception')
|
||||
|
||||
|
||||
class ModuleForLoaderTests(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue