summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/import_
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-03-13 17:41:36 (GMT)
committerBrett Cannon <brett@python.org>2013-03-13 17:41:36 (GMT)
commit4802becb160d76c2e0993ce7e8abbbe23667f91f (patch)
tree47c56787e702b1b15bc2d3fee5de3e9730aa9a57 /Lib/test/test_importlib/import_
parentaa73a1c9c9c149002f98dbf6fdd12eb3d41225ee (diff)
downloadcpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.zip
cpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.tar.gz
cpython-4802becb160d76c2e0993ce7e8abbbe23667f91f.tar.bz2
Issue #17117: Have both import itself and importlib.util.set_loader()
set __loader__ on a module when set to None. Thanks to Gökcen Eraslan for the fix.
Diffstat (limited to 'Lib/test/test_importlib/import_')
-rw-r--r--Lib/test/test_importlib/import_/test___loader__.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/import_/test___loader__.py b/Lib/test/test_importlib/import_/test___loader__.py
new file mode 100644
index 0000000..0edbcc5
--- /dev/null
+++ b/Lib/test/test_importlib/import_/test___loader__.py
@@ -0,0 +1,44 @@
+import imp
+import sys
+import unittest
+
+from .. import util
+from . import util as import_util
+
+
+class LoaderMock:
+
+ def find_module(self, fullname, path=None):
+ return self
+
+ def load_module(self, fullname):
+ sys.modules[fullname] = self.module
+ return self.module
+
+
+class LoaderAttributeTests(unittest.TestCase):
+
+ def test___loader___missing(self):
+ module = imp.new_module('blah')
+ try:
+ del module.__loader__
+ except AttributeError:
+ pass
+ loader = LoaderMock()
+ loader.module = module
+ with util.uncache('blah'), util.import_state(meta_path=[loader]):
+ module = import_util.import_('blah')
+ self.assertEqual(loader, module.__loader__)
+
+ def test___loader___is_None(self):
+ module = imp.new_module('blah')
+ module.__loader__ = None
+ loader = LoaderMock()
+ loader.module = module
+ with util.uncache('blah'), util.import_state(meta_path=[loader]):
+ returned_module = import_util.import_('blah')
+ self.assertEqual(loader, module.__loader__)
+
+
+if __name__ == '__main__':
+ unittest.main() \ No newline at end of file