class documentation

class MonkeyPatcher: (source)

View In Hierarchy

Cover up attributes with new objects. Neat for monkey-patching things for unit-testing purposes.

Method __init__ Undocumented
Method addMixinPatch Add a patch so that the class name on obj will be a the same type, but bases will be appended to __bases__ when patch is called or during runWithPatches. You can restore the original values with a call to restore().
Method addPatch Add a patch so that the attribute name on obj will be assigned to value when patch is called or during runWithPatches. You can restore the original values with a call to restore().
Method patch Apply all of the patches that have been specified with addPatch. Reverse this operation using restore.
Method restore Restore all original values to any patched objects.
Method runWithPatches Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done.
Method _alreadyPatched Has the name attribute of obj already been patched by this patcher?
Instance Variable _originals Undocumented
Instance Variable _patchesToApply Undocumented
def __init__(self, *patches): (source)

Undocumented

Parameters
*patches:Tuple[Any, str, Any]Undocumented
def addMixinPatch(self, obj, name, bases): (source)

Add a patch so that the class name on obj will be a the same type, but bases will be appended to __bases__ when patch is called or during runWithPatches. You can restore the original values with a call to restore().

Warning, if some want to add multiple mixins, all of them should be listed in one call to addMixinPatch, successive call to addMixinPatch will result into the last pacth beeing applied only.

Parameters
obj:AnyUndocumented
name:strUndocumented
bases:Sequence[Type[Any]]Undocumented
Raises
Unknown exceptionAttributeError if the name is not found in obj.
Unknown exceptionTypeError if the object found is not a class.
def addPatch(self, obj, name, value): (source)

Add a patch so that the attribute name on obj will be assigned to value when patch is called or during runWithPatches. You can restore the original values with a call to restore().

Parameters
obj:AnyUndocumented
name:strUndocumented
value:AnyUndocumented
def patch(self): (source)

Apply all of the patches that have been specified with addPatch. Reverse this operation using restore.

def restore(self): (source)

Restore all original values to any patched objects.

def runWithPatches(self, f, *args, **kw): (source)

Apply each patch already specified. Then run the function f with the given args and kwargs. Restore everything when done.

def _alreadyPatched(self, obj, name): (source)

Has the name attribute of obj already been patched by this patcher?

_originals: List[PatchT] = (source)

Undocumented

_patchesToApply: List[PatchT] = (source)

Undocumented