Back to index

python3.2  3.2.2
Public Member Functions
importlib.test.test_api.ImportModuleTests Class Reference

List of all members.

Public Member Functions

def test_module_import
def test_absolute_package_import
def test_shallow_relative_package_import
def test_deep_relative_package_import
def test_absolute_import_with_package
def test_relative_import_wo_package

Detailed Description

Test importlib.import_module.

Definition at line 8 of file test_api.py.


Member Function Documentation

Definition at line 51 of file test_api.py.

00051 
00052     def test_absolute_import_with_package(self):
00053         # Test importing a module from a package with an absolute name with
00054         # the 'package' argument given.
00055         pkg_name = 'pkg'
00056         pkg_long_name = '{0}.__init__'.format(pkg_name)
00057         name = '{0}.mod'.format(pkg_name)
00058         with util.mock_modules(pkg_long_name, name) as mock:
00059             with util.import_state(meta_path=[mock]):
00060                 importlib.import_module(pkg_name)
00061                 module = importlib.import_module(name, pkg_name)
00062                 self.assertEqual(module.__name__, name)

Here is the call graph for this function:

Definition at line 19 of file test_api.py.

00019 
00020     def test_absolute_package_import(self):
00021         # Test importing a module from a package with an absolute name.
00022         pkg_name = 'pkg'
00023         pkg_long_name = '{0}.__init__'.format(pkg_name)
00024         name = '{0}.mod'.format(pkg_name)
00025         with util.mock_modules(pkg_long_name, name) as mock:
00026             with util.import_state(meta_path=[mock]):
00027                 module = importlib.import_module(name)
00028                 self.assertEqual(module.__name__, name)

Here is the call graph for this function:

Definition at line 42 of file test_api.py.

00042 
00043     def test_deep_relative_package_import(self):
00044         modules = ['a.__init__', 'a.b.__init__', 'a.c']
00045         with util.mock_modules(*modules) as mock:
00046             with util.import_state(meta_path=[mock]):
00047                 importlib.import_module('a')
00048                 importlib.import_module('a.b')
00049                 module = importlib.import_module('..c', 'a.b')
00050                 self.assertEqual(module.__name__, 'a.c')

Here is the call graph for this function:

Definition at line 12 of file test_api.py.

00012 
00013     def test_module_import(self):
00014         # Test importing a top-level module.
00015         with util.mock_modules('top_level') as mock:
00016             with util.import_state(meta_path=[mock]):
00017                 module = importlib.import_module('top_level')
00018                 self.assertEqual(module.__name__, 'top_level')

Here is the call graph for this function:

Definition at line 63 of file test_api.py.

00063 
00064     def test_relative_import_wo_package(self):
00065         # Relative imports cannot happen without the 'package' argument being
00066         # set.
00067         with self.assertRaises(TypeError):
00068             importlib.import_module('.support')
00069 

Here is the call graph for this function:

Definition at line 29 of file test_api.py.

00029 
00030     def test_shallow_relative_package_import(self):
00031         # Test importing a module from a package through a relative import.
00032         pkg_name = 'pkg'
00033         pkg_long_name = '{0}.__init__'.format(pkg_name)
00034         module_name = 'mod'
00035         absolute_name = '{0}.{1}'.format(pkg_name, module_name)
00036         relative_name = '.{0}'.format(module_name)
00037         with util.mock_modules(pkg_long_name, absolute_name) as mock:
00038             with util.import_state(meta_path=[mock]):
00039                 importlib.import_module(pkg_name)
00040                 module = importlib.import_module(relative_name, pkg_name)
00041                 self.assertEqual(module.__name__, absolute_name)

Here is the call graph for this function:


The documentation for this class was generated from the following file: