Tools to attach spy functions to functions and replace object references with new references
Project description
pyjack is a small debug / test module that allows you to:
Connect a ‘spy’ function to almost any python function. This spy function is called instead of the original function. The original function is passed to the spy function along with all args, kwargs so you can call the original function; modify the args, kwargs first, print a debug message, then call it; not call the function, just log it or print a debug message; etc. etc.
Provides a convenience function pyjack.replace_all_refs which uses the gc module to replace all references to an object with references to another object.
A quick example:
>>> import pyjack >>> >>> def fakeimport(orgopen, *args, **kwargs): ... ... print 'Trying to import %s' % args[0] ... ... return 'MODULE_%s' % args[0] ... >>> >>> >>> pyjack.connect(__import__, spyfn=fakeimport) <..._PyjackFuncBuiltin object at 0x...> >>> >>> >>> import time Trying to import time >>> >>> >>> print time MODULE_time >>> >>> >>> __import__.restore() >>> >>> import time >>> print time <module 'time' (built-in)>
For full documentation and several examples please visit http://packages.python.org/pyjack/.
The git repo is here: https://github.com/cart0113/pyjack
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for pyjack-0.3.0.win-amd64-py2.7.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9b8ed69ae9a5f7440400b6948b4b78cecb5fd22021a473d08c7191186f0670a |
|
MD5 | 37569f44461fdaaa6b018a6ac3dcc62b |
|
BLAKE2b-256 | 789cde06859131ef44d27a2117bfa6b5e01f773f4844f54b75bc564a003ba189 |
Hashes for pyjack-0.3.0.win-amd64-py2.6.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b11aee92fefc6626762eeb7137bb814514432e64461ceb8c36c756723607885 |
|
MD5 | 9bdb2d79f8098d403362da00c4afb04b |
|
BLAKE2b-256 | 78f8bd8921a669cd361dbb470d1a0b430c95c55c2224540049a6b556994ab2b7 |