Skip to main content

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

pyjack-0.3.0.zip (6.7 kB view hashes)

Uploaded Source

pyjack-0.3.0.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distributions

pyjack-0.3.0.win-amd64-py2.7.exe (230.1 kB view hashes)

Uploaded Source

pyjack-0.3.0.win-amd64-py2.6.exe (230.1 kB view hashes)

Uploaded Source

pyjack-0.3.0.win32-py2.7.exe (202.4 kB view hashes)

Uploaded Source

pyjack-0.3.0.win32-py2.6.exe (72.3 kB view hashes)

Uploaded Source

pyjack-0.3.0.win32-py2.5.exe (67.7 kB view hashes)

Uploaded Source

pyjack-0.3.0.win32-py2.4.exe (67.7 kB view hashes)

Uploaded Source

pyjack-0.3.0-py2.7.egg (7.1 kB view hashes)

Uploaded Source

pyjack-0.3.0-py2.6.egg (7.1 kB view hashes)

Uploaded Source

pyjack-0.3.0-py2.5.egg (7.1 kB view hashes)

Uploaded Source

pyjack-0.3.0-py2.4.egg (7.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page