Globalsub

globalsub Module

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.

globalsub.subs(function, replacement=None)[source]

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.

Note:

Only references in namespaces will be replaced, references in anything other than dictionaries will not be replaced.

returns replacement

globalsub.restore(function)[source]

Restore previously subs’d function in all namespaces

function – the replacement function which was substituted

returns resolved function

globalsub.subsable(x)[source]

For built-in types that do not allow arbitrary attributes, subclass and copy

globalsub.global_replace(remove, install, filter=None)[source]

Replace object ‘remove’ with object ‘install’ on all dictionaries.

globalsub.replace_filter(install)[source]

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.

Table Of Contents

Previous topic

Globalsub: Replace objects Globally

This Page