eyam is a Python module that provides isolation of objects, functions and methods by mocking most of the contents in a module with Mock objects (from Michael Foord’s Mock library). It removes the need to individually mock all objects which the method under test depends on. After performing an action, you can inspect calls made by the code under test in the usual way with tools provided by the mock.py library.
mock is tested on Python version 2.6.
eyam is very easy to use and is designed for use with Michael Foord’s Mock library.
You can mock classes, instances, functions and methods. The syntax is straightforward:
>>> from eyam import isolate >>> import tests.isolationfixture as mod>>> def dump(expr): ... print '%s == %r' % (expr, eval('mod.%s' % expr))
Whole classes can be isolated:
>>> with isolate(mod, 'UnmockedClass'): #doctest:+ELLIPSIS
... dump('MyClass')
... dump('UnmockedClass')
MyClass == <mock.ClassMock object at 0x...>
UnmockedClass == <class 'tests.isolationfixture.UnmockedClass'>
Instances of an isolated class work as normally. Instances of mocked classes are Mock objects, so their methods return Mock objects:
>>> with isolate(mod, 'UnmockedClass'): #doctest:+ELLIPSIS
... dump('MyClass().bogus()')
... dump('UnmockedClass().instance_method()')
MyClass().bogus() == <mock.Mock object at 0x...>
UnmockedClass().instance_method() == 'return value of UnmockedClass.instance_method()'
Instances can be isolated as well:
>>> with isolate(mod, 'unmocked_instance'): #doctest:+ELLIPSIS
... dump('my_instance')
... dump('unmocked_instance')
my_instance == <mock.Mock object at 0x...>
unmocked_instance == <tests.isolationfixture.MyClass object at 0x...>
Individual methods of an instance can be isolated. The instance becomes a Mock object, but the original method is re-bound to it:
>>> with isolate(mod, 'my_instance.unmocked_method'): #doctest:+ELLIPSIS
... dump('my_instance')
... dump('my_instance.unmocked_method')
... dump('my_instance.unmocked_method()')
my_instance == <mock.Mock object at 0x...>
my_instance.unmocked_method == <bound method ?.unmocked_method of <mock.Mock object at 0x...>>
my_instance.unmocked_method() == 'return value of MyClass.unmocked_method'
All other methods and attributes of the instance are mocked.
>>> with isolate(mod, 'my_instance.unmocked_method'): #doctest:+ELLIPSIS
... dump('my_instance.instance_method')
... dump('my_instance.instance_method()')
my_instance.instance_method == <Mock name='mock.instance_method' id='...'>
my_instance.instance_method() == <mock.Mock object at 0x...>
Non-isolated instances become Mock objects, and their methods return Mock objects:
>>> with isolate(mod, 'my_instance.unmocked_method'): #doctest:+ELLIPSIS
... dump('unmocked_instance.instance_method')
... dump('unmocked_instance.instance_method()')
unmocked_instance.instance_method == <Mock name='mock.instance_method' id='...>
unmocked_instance.instance_method() == <mock.Mock object at 0x...>
Finally, module-level functions can be isolated:
>>> with isolate(mod, 'unmocked_function'): #doctest:+ELLIPSIS
... dump('unmocked_function')
... dump('unmocked_function()')
unmocked_function == <function unmocked_function at 0x...>
unmocked_function() == 'return value of unmocked_function'
Other functions are replaced with mock objects:
>>> with isolate(mod, 'unmocked_function'): #doctest:+ELLIPSIS
... dump('my_function')
... dump('my_function()')
my_function == <mock.Mock object at 0x...>
my_function() == <mock.Mock object at 0x...>
The distribution contains tests and documentation. The tests require unittest2 to run.
Metadata
Release files for eyam 0.1
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 |
|---|---|---|---|---|
| eyam-0.1.tar.gz | 4.4 kB | Without provenance | Details for eyam-0.1.tar.gz |
Release files / eyam-0.1.tar.gz
| Download URL | eyam-0.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2c9d3bd21549aab89a9d4b7d1b30ff6f8691d78c1ea58d1ebbb1ca676a0102b
|
|
BLAKE2b-256 checksum How to use checksums |
63c6f2b188be47797b0f80848cef65f37d17bb439ba96ec5b8b486a8350e0fee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for eyam 0.1
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.