Convenient approach to monkey patching
Project description
Gorilla is a library providing a convenient approach to monkey patching.
Monkey patching is the process of modifying modules and classes attributes at runtime with the purpose of replacing of extending third-party code. See Wikipedia’s Monkey patch page for a more complete definition.
Features
creation of patches using decorators.
creation of batches of patches using the members of either classes or modules.
warns when patching an existing attribute and/or store the overriden attribute to make it accessible.
customizable behaviour.
allows the dynamic creation of patches at runtime.
compatible with both Python 2 and Python 3.
Usage
Marking a function my_function() as being a patch for a module destination is as easy as:
>>> import gorilla
>>> import destination
>>> @gorilla.patch(destination)
... def my_function():
... print("Hello world!")
Marking a class destination.Class to be patched with the members of another class is no sweat either:
>>> import gorilla
>>> import destination
>>> @gorilla.patches(destination.Class)
... class MyClass(object):
... def method(self):
... print("Hello")
... @classmethod
... def class_method(cls):
... print("world!")
See the overview and tutorial sections of the documentation for more details.
Documentation
Read the documentation online at <http://gorilla.readthedocs.org> or check their source from the doc folder.
The documentation can be built in different formats using Sphinx.
Running the Tests
A suite of unit tests is available from the tests directory. You can run it by firing:
$ python tests/run.py
To run specific tests, it is possible to pass names to match in the command line.
$ python tests/run.py TestCase test_my_code
This command will run all the tests within the TestCase class as well as the individual tests which contains test_my_code in their name.
Get the Source
The source code is available from the GitHub project page.
Contributing
Found a bug or got a feature request? Don’t keep it for yourself, log a new issue on GitHub.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for gorilla-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 66a4301f6db3924965f85246e1de64a4e7ec8b98b7b40e97dc01e2d0284cd46b |
|
MD5 | 459399cf344ff986fa9aa4abc5081631 |
|
BLAKE2b-256 | fce949efd155c21e95df6ee4c05c3b7399cde10d30c86d5b9f164acb36c77253 |