Module achoo :: Class CallableAssertionBuilder
[hide private]
[frames] | no frames]

Class CallableAssertionBuilder

source code

object --+
         |
        CallableAssertionBuilder

An assertion builder for testing callable objects.

This object can be used to create a set of assertions about conditions when calling a callable object, such as a function or method.

To provide parameters to the callable, use the passing method. The callable is not actually executed until one of the return or raises methods is called.

Instance Methods [hide private]
 
__init__(self, callabl)
Constructs a new builder.
source code
 
passing(self, *args, **kwargs)
Applies a set of arguments to be passed to the callable.
source code
 
returns(self, value=None)
Invokes the callable, optionally checking the returned value.
source code
 
returns_none(self)
Invokes the callable and ensures the return value is None.
source code
 
raises(self, error)
Invokes the callable, ensuring it raises an exception.
source code
 
_invoke(self)
Invokes the callable with any parameters that have been specified.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, callabl)
(Constructor)

source code 

Constructs a new builder.

In general, you want to use the calling function instead of this directly.
Parameters:
  • callabl - an object to be tested
Overrides: object.__init__

passing(self, *args, **kwargs)

source code 

Applies a set of arguments to be passed to the callable.

Use this method to specify what positional and keyword arguments should be passed to the callable.
Parameters:
  • args - positional arguments to be passed to the callable
  • kwargs - keyword arguments to be passed to the callable
Returns:
this assertion builder

returns(self, value=None)

source code 

Invokes the callable, optionally checking the returned value.

Calling this method will cause the callable to be invoked, with any arguments specified using passing and returning a ValueAssertionBuilder for the object returned by the callable.

An object can be optionally passed to this method for conveniently checking the value of the object returned by the callable.
Parameters:
  • value - optional value that must be equal to the object returned by invoking the callable
Returns:
a ValueAssertionBuilder for the object returned by the invocation of the callable
Raises:
  • AssertionError - if the returned value is not equal to value

returns_none(self)

source code 

Invokes the callable and ensures the return value is None.

Calling this method will cause the callable to be invoked, with any arguments specified using passing.
Raises:
  • AssertionError - if the value returned by invoking the callable is not equal to None

raises(self, error)

source code 

Invokes the callable, ensuring it raises an exception.

Calling this method will cause the callable to be invoked, with any arguments specified using passing.

A ValueAssertionBuilder for the exception is returned, allowing its properties to be examined.
Parameters:
  • error - type of the exception to be raised
Returns:
a ValueAssertionBuilder for the exception raised by the invocation of the callable
Raises:
  • AssertionError - if the callable invocation did not raise an exception or if it raised an exception that was not of type BaseException

_invoke(self)

source code 
Invokes the callable with any parameters that have been specified.
Returns:
the return value from the callable invocation