Back to index

python3.2  3.2.2
Classes | Functions | Variables
importlib.test.util Namespace Reference

Classes

class  mock_modules

Functions

def case_insensitive_tests
def uncache
def import_state

Variables

 CASE_INSENSITIVE_FS = True
tuple changed_name = __file__.upper()

Function Documentation

Class decorator that nullifies tests requiring a case-insensitive
file system.

Definition at line 20 of file util.py.

00020 
00021 def case_insensitive_tests(test):
00022     """Class decorator that nullifies tests requiring a case-insensitive
00023     file system."""
00024     return unittest.skipIf(not CASE_INSENSITIVE_FS,
00025                             "requires a case-insensitive filesystem")(test)
00026 
00027 
@contextmanager
Context manager to manage the various importers and stored state in the
sys module.

The 'modules' attribute is not supported as the interpreter state stores a
pointer to the dict that the interpreter uses internally;
reassigning to sys.modules does not have the desired effect.

Definition at line 53 of file util.py.

00053 
00054 def import_state(**kwargs):
00055     """Context manager to manage the various importers and stored state in the
00056     sys module.
00057 
00058     The 'modules' attribute is not supported as the interpreter state stores a
00059     pointer to the dict that the interpreter uses internally;
00060     reassigning to sys.modules does not have the desired effect.
00061 
00062     """
00063     originals = {}
00064     try:
00065         for attr, default in (('meta_path', []), ('path', []),
00066                               ('path_hooks', []),
00067                               ('path_importer_cache', {})):
00068             originals[attr] = getattr(sys, attr)
00069             if attr in kwargs:
00070                 new_value = kwargs[attr]
00071                 del kwargs[attr]
00072             else:
00073                 new_value = default
00074             setattr(sys, attr, new_value)
00075         if len(kwargs):
00076             raise ValueError(
00077                     'unrecognized arguments: {0}'.format(kwargs.keys()))
00078         yield
00079     finally:
00080         for attr, value in originals.items():
00081             setattr(sys, attr, value)
00082 

Here is the call graph for this function:

def importlib.test.util.uncache (   names)
Uncache a module from sys.modules.

A basic sanity check is performed to prevent uncaching modules that either
cannot/shouldn't be uncached.

Definition at line 28 of file util.py.

00028 
00029 def uncache(*names):
00030     """Uncache a module from sys.modules.
00031 
00032     A basic sanity check is performed to prevent uncaching modules that either
00033     cannot/shouldn't be uncached.
00034 
00035     """
00036     for name in names:
00037         if name in ('sys', 'marshal', 'imp'):
00038             raise ValueError(
00039                 "cannot uncache {0} as it will break _importlib".format(name))
00040         try:
00041             del sys.modules[name]
00042         except KeyError:
00043             pass
00044     try:
00045         yield
00046     finally:
00047         for name in names:
00048             try:
00049                 del sys.modules[name]
00050             except KeyError:
00051                 pass
00052 
@contextmanager

Variable Documentation

Definition at line 9 of file util.py.

tuple importlib.test.util.changed_name = __file__.upper()

Definition at line 13 of file util.py.