Back to index

python3.2  3.2.2
Public Member Functions
importlib.test.test_util.ModuleForLoaderTests Class Reference

List of all members.

Public Member Functions

def return_module
def raise_exception
def test_new_module
def test_reload
def test_new_module_failure
def test_reload_failure

Detailed Description

Tests for importlib.util.module_for_loader.

Definition at line 9 of file test_util.py.


Member Function Documentation

Definition at line 17 of file test_util.py.

00017 
00018     def raise_exception(self, name):
00019         def to_wrap(self, module):
00020             raise ImportError
00021         fxn = util.module_for_loader(to_wrap)
00022         try:
00023             fxn(self, name)
00024         except ImportError:
00025             pass

Here is the caller graph for this function:

Definition at line 13 of file test_util.py.

00013 
00014     def return_module(self, name):
00015         fxn = util.module_for_loader(lambda self, module: module)
00016         return fxn(self, name)

Here is the caller graph for this function:

Definition at line 26 of file test_util.py.

00026 
00027     def test_new_module(self):
00028         # Test that when no module exists in sys.modules a new module is
00029         # created.
00030         module_name = 'a.b.c'
00031         with test_util.uncache(module_name):
00032             module = self.return_module(module_name)
00033             self.assertTrue(module_name in sys.modules)
00034         self.assertTrue(isinstance(module, types.ModuleType))
00035         self.assertEqual(module.__name__, module_name)

Here is the call graph for this function:

Definition at line 45 of file test_util.py.

00045 
00046     def test_new_module_failure(self):
00047         # Test that a module is removed from sys.modules if added but an
00048         # exception is raised.
00049         name = 'a.b.c'
00050         with test_util.uncache(name):
00051             self.raise_exception(name)
00052             self.assertTrue(name not in sys.modules)

Here is the call graph for this function:

Definition at line 36 of file test_util.py.

00036 
00037     def test_reload(self):
00038         # Test that a module is reused if already in sys.modules.
00039         name = 'a.b.c'
00040         module = imp.new_module('a.b.c')
00041         with test_util.uncache(name):
00042             sys.modules[name] = module
00043             returned_module = self.return_module(name)
00044             self.assertIs(returned_module, sys.modules[name])

Here is the call graph for this function:

Definition at line 53 of file test_util.py.

00053 
00054     def test_reload_failure(self):
00055         # Test that a failure on reload leaves the module in-place.
00056         name = 'a.b.c'
00057         module = imp.new_module(name)
00058         with test_util.uncache(name):
00059             sys.modules[name] = module
00060             self.raise_exception(name)
00061             self.assertIs(module, sys.modules[name])
00062 

Here is the call graph for this function:


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