summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/test_util.py
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-05-28 22:35:54 (GMT)
committerBrett Cannon <brett@python.org>2013-05-28 22:35:54 (GMT)
commit3dc48d6f6937f110388efd0f257fa12c323763a6 (patch)
tree58de10b0ae6755796ce557ea2f11941a3de02073 /Lib/test/test_importlib/test_util.py
parenta22faca7144bdba5269e309965d926d155fc667b (diff)
downloadcpython-3dc48d6f6937f110388efd0f257fa12c323763a6.zip
cpython-3dc48d6f6937f110388efd0f257fa12c323763a6.tar.gz
cpython-3dc48d6f6937f110388efd0f257fa12c323763a6.tar.bz2
Issue #18070: importlib.util.module_for_loader() now sets __loader__
and __package__ unconditionally in order to do the right thing for reloading.
Diffstat (limited to 'Lib/test/test_importlib/test_util.py')
-rw-r--r--Lib/test/test_importlib/test_util.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/Lib/test/test_importlib/test_util.py b/Lib/test/test_importlib/test_util.py
index b986efd..b3896f8 100644
--- a/Lib/test/test_importlib/test_util.py
+++ b/Lib/test/test_importlib/test_util.py
@@ -85,12 +85,23 @@ class ModuleForLoaderTests(unittest.TestCase):
def test_reload(self):
# Test that a module is reused if already in sys.modules.
+ class FakeLoader:
+ def is_package(self, name):
+ return True
+ @util.module_for_loader
+ def load_module(self, module):
+ return module
name = 'a.b.c'
module = imp.new_module('a.b.c')
+ module.__loader__ = 42
+ module.__package__ = 42
with test_util.uncache(name):
sys.modules[name] = module
- returned_module = self.return_module(name)
+ loader = FakeLoader()
+ returned_module = loader.load_module(name)
self.assertIs(returned_module, sys.modules[name])
+ self.assertEqual(module.__loader__, loader)
+ self.assertEqual(module.__package__, name)
def test_new_module_failure(self):
# Test that a module is removed from sys.modules if added but an