Module achoo
source code
Achoo is a fluent interface for testing Python objects.
It is designed to be used in conjunction with a unit testing framework
like PyUnit's unittest
module, shipped with all modern
Python distributions.
To use Achoo, import the assertion builder functions then use them to
wire up assertions about objects and callables.
The two assertion builder functions are requiring
- used
to test properties of objects and calling
, used to test
properties of a calling a callable object (that is, a function, method or
similar). These functions returns assertion builders that can be used to
chain assertions calls together. See the documentation for the functions
for more information.
If any of the assertions are not met, an AssertionError
is raised.
For example:
import unittest
from achoo import requiring
from achoo import calling
class StringTest(unittest.TestCase):
def testLength(self):
s = 'foo'
requiring(s.length).equal_to(3)
def testStrip(self):
s = ' foo '
calling(s.strip).returns('foo')
def testSplit(self):
s = 'foo,bar'
calling(s.split).passing(',').returns()\
.length(2)\
.index(0).equal_to('foo')\
.index(1).equal_to('bar')
def testBadIndex(self):
s = 'foo'
calling(s.index).passing('quux').raises(ValueError)
Assertion builder factory for object properties.
To test an object, call requiring and pass the object as
the sole argument. A ValueAssertionBuilder is returned and
can be used to chain together assertions about it.
For example:
test_map = {'foo': 'bar'}
requiring(test_map) .length(1) .contains('foo') .index('foo').equal_to('bar')
- Parameters:
value - an object to be tested
- Returns:
- an instance of
ValueAssertionBuilder wrapping the
value passed in
|
Assertion builder factory for callable objects.
To test a callable, call requiring and pass the object as
the sole argument. A ValueAssertionBuilder is returned and
can be used to chain together assertions about it.
For example:
incr = lambda x: x + 1
calling(incr).passing(1).returns(2)
calling(incr).raises(TypeError)
- Parameters:
callabl - a callable object (function, method or similar) to be
tested
- Returns:
- an instance of
CallableAssertionBuilder wrapping
the callable passed in
|