Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Terse mock expectations for Python and Mock

Project Description
# expect

Inspired by [RSpec's test doubles][2] and [Expecter Gadget][3].

Uses [Mock][1] but provides a terser syntax for expectations.

Example:

```python
>>> def assert_equal(lhs, rhs):
... assert lhs == rhs
>>> from expect import new_expect
>>> expect = new_expect(__eq__=assert_equal)
>>> expect(2) == 2
>>> expect(2) == 3
Traceback (most recent call last):
...
AssertionError

>>> class MyClass(object):
... @classmethod
... def my_method(cls, arg):
... pass

>>> # Stubs don't have to be called.
>>> expect(MyClass).stub('my_method').with_(1).and_return(2)
>>> MyClass.my_method(1)
2
>>> expect.reset()

>>> # Mocks
>>> expect(MyClass).should_receive('my_method').with_(1).and_return(2)
>>> expect.verify()
Traceback (most recent call last):
...
AssertionError: Expected to be called once. Called 0 times.

```

[1]: http://www.voidspace.org.uk/python/mock/
[2]: https://github.com/rspec/rspec-mocks
[3]: https://github.com/garybernhardt/expecter
Release History

Release History

This version
History Node

0.0.1

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting