Global substitution for Python unit tests
Provides substitution in all dictionaries throughout the interpreter, this includes references held by objects and modules. Restores those references which were replaced (only), i.e. you can re-use the objects you used as substitutions after restoring.
Replaces function in all namespaces with replacement
function – function to replace replacement – if provided, is used as the replacement object, otherwise a function returning None is constructed
Used to stub out functionality globally, this function uses global_replace to find all references to function and replace them with replacement. Use restore( replacement ) to restore function references.
Only references in namespaces will be replaced, references in anything other than dictionaries will not be replaced.
Restore previously subs’d function in all namespaces
function – the replacement function which was substituted
returns resolved function
For built-in types that do not allow arbitrary attributes, subclass and copy
Replace object ‘remove’ with object ‘install’ on all dictionaries.
Calculate which instances should not be replaced
Looks for the replacement (install) in namespaces, marking the key values in those namespaces as not-to-be-replaced.