[Python-checkins] r52959 - sandbox/trunk/import_in_py/test_importer.py
brett.cannon
python-checkins at python.org
Thu Dec 7 21:08:27 CET 2006
Author: brett.cannon
Date: Thu Dec 7 21:08:26 2006
New Revision: 52959
Modified:
sandbox/trunk/import_in_py/test_importer.py
Log:
Tweak test for an empty string to make sure it fails for levels of 0 and -1.
Also flesh out comments for integration tests to specify the import statement
it is meant to be testing and under what circumstances.
Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py (original)
+++ sandbox/trunk/import_in_py/test_importer.py Thu Dec 7 21:08:26 2006
@@ -1024,8 +1024,9 @@
self.failUnless(resolved_name not in sys.modules)
def test_empty_string(self):
- # An empty string should raise ValueError.
- self.failUnlessRaises(ValueError, self.importer, '')
+ # An empty string should raise ValueError if level is not > 0.
+ for level in (-1, 0):
+ self.failUnlessRaises(ValueError, self.importer, '', {}, {}, level)
class ImportMetaPathTests(ImportHelper):
@@ -1211,6 +1212,7 @@
def test_builtin(self):
# Test importing a built-in module.
+ # ``import sys``
self.clear_sys_modules('sys')
module = self.import_('sys')
self.failUnlessEqual(module.__name__, 'sys')
@@ -1221,6 +1223,7 @@
def test_frozen(self):
# Importing a frozen module should work.
+ # ``import __hello__``
self.clear_sys_modules('__hello__')
faked_stdout = StringIO.StringIO()
sys.stdout = faked_stdout
@@ -1233,17 +1236,20 @@
def test_extension(self):
# Should be able to import extension modules.
+ # ``import time``
module = self.import_('time')
self.failUnlessEqual(module.__name__, 'time')
self.failUnless(hasattr(module, 'time'))
def test_pyc_w_py(self):
# Should be able to import a .pyc file when a .py is also present.
+ # ``import pyc`` with a corresponding .py .
module = self.import_(self.module_name)
self.verify_module(module, self.pyc_path)
def test_pyc_wo_py(self):
# Importing just a .pyc file (w/ no .py) should be okay.
+ # ``import pyc`` from a .pyc .
os.remove(self.py_path)
module = self.import_(self.module_name)
self.verify_module(module, self.pyc_path)
@@ -1251,6 +1257,7 @@
def test_sys_modules(self):
# Should be able to pull from sys.modules even if a file does not exist
# for the module.
+ # ``import module`` from sys.modules.
test_module_name = '<' + self.module_name + '>'
test_module = mock_importer.MockModule(test_module_name)
sys.modules[test_module_name] = test_module
@@ -1262,6 +1269,7 @@
def test_py_creating_pyc(self):
# Importing a .py file should work and generate a .pyc file.
+ # ``import py`` creating a .pyc .
os.remove(self.pyc_path)
module = self.import_(self.module_name)
self.verify_module(module)
@@ -1280,35 +1288,42 @@
def test_top_level_package(self):
# Should be able to import a top-level package.
+ # ``import package``
module = self.import_(self.pkg_name)
self.verify_package(module)
def test_package_module(self):
# A module within a top-level package should work with the package not
# already imported.
+ # ``import package.module``
assert '.' in self.pkg_module_name
module = self.import_(self.pkg_module_name)
self.verify_package(module, self.pkg_module_name)
def test_sub_package(self):
# A package within a package should work.
+ # ``import package.subpackage``
module = self.import_(self.sub_pkg_name)
self.verify_package(module, self.sub_pkg_name)
def test_sub_package_module(self):
# A module contained within a sub-package should work.
+ # ``import package.subpackage.module``
module = self.import_(self.sub_pkg_module_name)
self.verify_package(module, self.sub_pkg_module_name)
def test_classic_relative_import_in_package_init(self):
# Importing within a package's __init__ file using a relative name
# should work properly.
+ # ``import module`` for 'package' where 'module' is 'package.module'.
package_globals = {'__name__':self.pkg_name, '__path__':['some_path']}
module = self.import_(self.module_name, package_globals, level=-1)
self.verify_package(module, self.pkg_module_name)
def test_classic_relative_import_in_module(self):
# Importing using a relative name in a module in a package should work.
+ # ``import module`` for 'package.some_module' where 'module' is
+ # 'package.module'.
module_globals = {'__name__':self.pkg_name + '.' + 'another_module'}
module = self.import_(self.module_name, module_globals, level=-1)
self.verify_package(module, self.pkg_module_name)
@@ -1318,6 +1333,7 @@
# relative or absolute, but only exists in an absolute name context,
# should work. It should also lead to a value for None in sys.modules
# for the resolved relative name.
+ # ``import module`` for 'package' where 'module' is 'module'.
package_module_globals = {'__name__':self.pkg_module_name}
module = self.import_(self.top_level_module_name,
package_module_globals, level=-1)
@@ -1329,6 +1345,7 @@
def test_relative_import_in_package_init(self):
# Importing a module with a relative name in a package's __init__ file
# should work.
+ # XXX
package_globals = {'__name__':self.pkg_name, '__path__':self.pkg_path}
module = self.import_(self.module_name, package_globals, level=1)
self.verify_package(module, self.pkg_module_name)
@@ -1336,6 +1353,7 @@
def test_relative_import_in_package(self):
# Importing a module with a relative name in another module should
# work.
+ # XXX
module_globals = {'__name__':self.pkg_name + '.another_module'}
module = self.import_(self.module_name, module_globals, level=1)
self.verify_package(module, self.pkg_module_name)
@@ -1343,6 +1361,7 @@
def test_relative_import_return(self):
# When importing from a relative name, the module up to the first dot
# of that relative name (made absolute) should be returned.
+ # ``import subpackage.module`` for 'package.module'.
module_globals = {'__name__':self.pkg_module_name}
relative_name = self.sub_pkg_tail_name + '.' + self.module_name
module = self.import_(relative_name, module_globals)
More information about the Python-checkins
mailing list