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!

Simple, extensible test assertions.

Project Description
Grain
=====

Overview
--------

Simple, extensible test assertions.

Usage
-----

Use `expect` to build test assertions.

```python
from grain import expect
from yourmodule import your_func

n = your_func(10)

# Raises an `AssertionError` if `n` is not equal to `100`.
expect(n).equal(100)

# Raises an `AssertionError` if `your_func(None)` does not raise a `TypeError`.
with expect.raises(TypeError):
your_func(None)
```

Available assertion methods:

- expect(a).equal(b)
- expect(a).not_equal(b)
- expect(a).is_(b)
- expect(a).is_not(b)
- expect(a).true()
- expect(a).false()
- expect(a).in_(b)
- expect(a).not_in(b)
- expect(a).less(b)
- expect(a).less_equal(b)
- expect(a).greater(b)
- expect(a).greater_equal(b)
- expect(a).almost_equal(b)
- expect(a).not_almost_equal(b)
- expect.raises(exception_class)
- expect.fail()

Custom Assertions
-----------------

`expect` is actually just a class. You can use `expect.extend()` to conveniently
create a copy that mixes in additional methods. This lets you add custom
assertion methods that work exactly like the built-in methods.

The following code will replace `expect` with a new copy that includes two
additional `even` and `odd` assertion methods.

```python
from grain import expect

class CustomAssertions(object):
def even(self):
if self.actual % 2 == 0:
return
self.fail('Expected {} to be even'.format(repr(self.actual)))

def odd(self):
if self.actual % 2 != 0:
return
self.fail('Expected {} to be odd'.format(repr(self.actual)))

expect = expect.extend(CustomAssertions)

expect(2).even()
expect(3).odd()
```
Release History

Release History

This version
History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
grain-0.1.4.macosx-10.8-x86_64.exe (65.3 kB) Copy SHA256 Checksum SHA256 any Windows Installer Jun 17, 2013
grain-0.1.4.tar.gz (1.9 kB) Copy SHA256 Checksum SHA256 Source Jun 17, 2013

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