summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test/builtin/test_loader.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2009-01-18 00:24:28 (GMT)
committerBrett Cannon <bcannon@gmail.com>2009-01-18 00:24:28 (GMT)
commit23cbd8a6564df0ac3df339f91196c45f3e626d32 (patch)
treebef5602638a1567c28738aa359dae9865e04b6cd /Lib/importlib/test/builtin/test_loader.py
parent458ad47a2c8045080a86eaaf33bb6cd174021891 (diff)
downloadcpython-23cbd8a6564df0ac3df339f91196c45f3e626d32.zip
cpython-23cbd8a6564df0ac3df339f91196c45f3e626d32.tar.gz
cpython-23cbd8a6564df0ac3df339f91196c45f3e626d32.tar.bz2
Add initial implementation of importlib. See the NOTES files for what is
planned for the package. There are no docs yet, but they are coming once the API for the first new function, importlib.import_module() is finalized.
Diffstat (limited to 'Lib/importlib/test/builtin/test_loader.py')
-rw-r--r--Lib/importlib/test/builtin/test_loader.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/Lib/importlib/test/builtin/test_loader.py b/Lib/importlib/test/builtin/test_loader.py
new file mode 100644
index 0000000..5aa3d79
--- /dev/null
+++ b/Lib/importlib/test/builtin/test_loader.py
@@ -0,0 +1,52 @@
+import importlib
+from .. import support
+
+import sys
+import types
+import unittest
+
+
+class LoaderTests(unittest.TestCase):
+
+ """Test load_module() for built-in modules."""
+
+ assert 'errno' in sys.builtin_module_names
+ name = 'errno'
+
+ verification = {'__name__': 'errno', '__package__': None}
+
+ def verify(self, module):
+ """Verify that the module matches against what it should have."""
+ self.assert_(isinstance(module, types.ModuleType))
+ for attr, value in self.verification.items():
+ self.assertEqual(getattr(module, attr), value)
+ self.assert_(module.__name__ in sys.modules)
+
+ load_module = staticmethod(lambda name:
+ importlib.BuiltinImporter().load_module(name))
+
+ def test_load_module(self):
+ # Common case.
+ with support.uncache(self.name):
+ module = self.load_module(self.name)
+ self.verify(module)
+
+ def test_nonexistent(self):
+ name = 'dssdsdfff'
+ assert name not in sys.builtin_module_names
+ self.assertRaises(ImportError, self.load_module, name)
+
+ def test_already_imported(self):
+ # Using the name of a module already imported but not a built-in should
+ # still fail.
+ assert hasattr(importlib, '__file__') # Not a built-in.
+ self.assertRaises(ImportError, self.load_module, 'importlib')
+
+
+def test_main():
+ from test.support import run_unittest
+ run_unittest(LoaderTests)
+
+
+if __name__ == '__main__':
+ test_main()