summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/frozen/test_loader.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-02-01 01:34:13 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-02-01 01:34:13 (GMT)
commit223a19d8b19b02fb3200f92665dfc6b257ee14bb (patch)
treea9ebfd5a713349af7f4cd7a7e38702d3fbc86015 /Lib/importlib/test/frozen/test_loader.py
parente70485e7c1e9f769679328ee87f9e61bbd892ed8 (diff)
downloadcpython-223a19d8b19b02fb3200f92665dfc6b257ee14bb.zip
cpython-223a19d8b19b02fb3200f92665dfc6b257ee14bb.tar.gz
cpython-223a19d8b19b02fb3200f92665dfc6b257ee14bb.tar.bz2
Fix importlib.machinery.FrozenImporter.load_module() to set __package__
properly. Discovered by also moving the loader tests over to importlib.test.abc.LoaderTests.
Diffstat (limited to 'Lib/importlib/test/frozen/test_loader.py')
-rw-r--r--Lib/importlib/test/frozen/test_loader.py69
1 files changed, 51 insertions, 18 deletions
diff --git a/Lib/importlib/test/frozen/test_loader.py b/Lib/importlib/test/frozen/test_loader.py
index 95854f2..63a9742 100644
--- a/Lib/importlib/test/frozen/test_loader.py
+++ b/Lib/importlib/test/frozen/test_loader.py
@@ -1,26 +1,59 @@
from importlib import machinery
-from ..builtin import test_loader
-
-
-class LoaderTests(test_loader.LoaderTests):
-
- name = '__phello__'
- load_module = staticmethod(lambda name:
- machinery.FrozenImporter.load_module(name))
- verification = {'__name__': '__phello__', '__file__': '<frozen>',
- '__package__': None, '__path__': ['__phello__']}
-
-
-class SubmoduleLoaderTests(LoaderTests):
-
- name = '__phello__.spam'
- verification = {'__name__': '__phello__.spam', '__file__': '<frozen>',
- '__package__': None}
+from .. import abc
+from .. import support
+
+
+class LoaderTests(abc.LoaderTests):
+
+ def test_module(self):
+ with support.uncache('__hello__'):
+ module = machinery.FrozenImporter.load_module('__hello__')
+ check = {'__name__': '__hello__', '__file__': '<frozen>',
+ '__package__': None}
+ for attr, value in check.items():
+ self.assertEqual(getattr(module, attr), value)
+
+ def test_package(self):
+ with support.uncache('__phello__'):
+ module = machinery.FrozenImporter.load_module('__phello__')
+ check = {'__name__': '__phello__', '__file__': '<frozen>',
+ '__package__': '__phello__', '__path__': ['__phello__']}
+ for attr, value in check.items():
+ attr_value = getattr(module, attr)
+ self.assertEqual(attr_value, value,
+ "for __phello__.%s, %r != %r" %
+ (attr, attr_value, value))
+
+ def test_lacking_parent(self):
+ with support.uncache('__phello__', '__phello__.spam'):
+ module = machinery.FrozenImporter.load_module('__phello__.spam')
+ check = {'__name__': '__phello__.spam', '__file__': '<frozen>',
+ '__package__': '__phello__'}
+ for attr, value in check.items():
+ attr_value = getattr(module, attr)
+ self.assertEqual(attr_value, value,
+ "for __phello__.spam.%s, %r != %r" %
+ (attr, attr_value, value))
+
+ def test_module_reuse(self):
+ with support.uncache('__hello__'):
+ module1 = machinery.FrozenImporter.load_module('__hello__')
+ module2 = machinery.FrozenImporter.load_module('__hello__')
+ self.assert_(module1 is module2)
+
+ def test_state_after_failure(self):
+ # No way to trigger an error in a frozen module.
+ pass
+
+ def test_unloadable(self):
+ assert machinery.FrozenImporter.find_module('_not_real') is None
+ self.assertRaises(ImportError, machinery.FrozenImporter.load_module,
+ '_not_real')
def test_main():
from test.support import run_unittest
- run_unittest(LoaderTests, SubmoduleLoaderTests)
+ run_unittest(LoaderTests)
if __name__ == '__main__':