Welcome to ludibrio
- Author:
Gustavo Rezende <nsigustavo@gmail.com>
- Contributors:
Diego Pinheiro <me@dmpinheiro.net>
Hugo Lopes <hltbra@gmail.com>
Rodrigo Manhães <rmanhaes@gmail.com>
Rebeca Motta <becacmotta@gmail.com>
Install
Ludibrio is registered with PyPi. If you have pip, setuptools or Distribute you can install mock with:
$ sudo easy_install ludibrio
Download
The latest official version is 3.0.2. Here’s how to get it:
http://pypi.python.org/pypi/ludibrio/3.0.2
Documentation
See the http://ludibriar.appspot.com/ for the current documentation.
Getting involved !
Ludibrio’s development may be viewed and followed on github:
http://github.com/nsigustavo/ludibrio
Retrieve the source code using ‘git’:
$ git clone git://github.com/nsigustavo/ludibrio.git
Install package in ‘development mode’ and run tests with doctestcommand:
$ sudo easy_install doctestcommand $ git clone git://github.com/nsigustavo/ludibrio.git $ cd ludibrio $ sudo python setup.py develop $ cd ludibrio $ doctest
In a nutshell
Test doubles are fake objects that simulate the behavior of a real object for testing purposes.
Mock
Mocks are objects pre-programmed with expectations which form a specification of the calls they are expected to receive:
>>> from ludibrio import Mock
>>> with Mock() as MySQLdb:
... con = MySQLdb.connect('server', 'user', 'XXXX')
... con.select_db('DB') >> None
... cursor = con.cursor()
... cursor.execute('select * from numbers') >> None
... cursor.fetchall() >> [1,2,3,4,5]
>>> con = MySQLdb.connect('server', 'user', 'XXXX')
>>> con.select_db('DB')
>>> cursor = con.cursor()
>>> cursor.execute('select * from numbers')
>>> cursor.fetchall()
[1, 2, 3, 4, 5]
>>> MySQLdb.validate() #passed
Stub
Stubs provide pre-defined answers to method calls made during a test:
>>> from ludibrio import Stub >>> with Stub() as x: ... x.anything() >> 'response'
>>> x.anything() 'response'
Trivial mocking or stubing for any external module
Ludibrio also offers a replace mode, which basically means if a “from … import …” statement is defined into a ‘with’ scope, the replay mechanism will return a mock object to replace the original object in namespace of the whole Python interpreter (including any modules, etc). There’s a simple example below to illustrate how use it:
>>> from ludibrio import Stub >>> with Stub() as time: ... from time import time ... time() >> 171
>>> from time import time >>> time() 171
Proxy
Two Ludibrio’s powerful features that aren’t found in other mocking systems is the ability of proxying existing objects, or patching a real instance or class.
When an object is proxied, Ludibrio create a Test Double object holding a reference to the real object, allowing expressions passthrough to it(mocked or not, and by default or on request):
>>> from os.path import splitext
>>> with Stub(proxy=splitext) as splitext:
... splitext('ludibrio/stubed.py') >> ('/temp/temp','.temp')
>>> splitext('mock.py')
('mock', '.py')
>>> splitext('ludibrio/stubed.py')
('/temp/temp', '.temp')
Metadata
Release files for ludibrio 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ludibrio-3.1.0.tar.gz | 6.0 kB | Without provenance | Details for ludibrio-3.1.0.tar.gz |
Release files / ludibrio-3.1.0.tar.gz
| Download URL | ludibrio-3.1.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
271a2a866b00a059d9330dc1213d182731121c83088a42f6b3e7f24777b522db
|
|
BLAKE2b-256 checksum How to use checksums |
5cb7960bf226748b919729c084c2fd49f603523bfd070c9d997af5ac7d9327d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ludibrio 3.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.