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

Class ValueAssertionBuilder

source code

object --+
         |
        ValueAssertionBuilder

An assertion builder for testing properties of objects.

This object can be used to create a set of assertions about various properties of an object. Most methods return a builder with the same object so that more than one assertion to be made about it.

If any of the assertions fail, an AssertionError is raised.

Instance Methods [hide private]
 
__init__(self, value, invert=False)
Constructs a new builder.
source code
 
equal_to(self, other)
Asserts the value object is equal to some other object.
source code
 
same_as(self, other)
Asserts the value object is the same as another object.
source code
 
is_none(self)
Asserts the value object is None.
source code
 
is_not_none(self)
Asserts the value object is not None.
source code
 
is_a(self, clazz)
Asserts the value object is an instance of a particular type.
source code
 
length(self, length)
Asserts the value object has a specific length.
source code
 
contains(self, element)
Asserts the value object contains a specific element.
source code
 
index(self, index)
Asserts the value object has a specific index.
source code
 
_error(self, message, inverse_message, other)
Returns a new AssertionError with an appropriate message.
source code

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

Properties [hide private]
  is_not
Inverts the sense of the next assertion.

Inherited from object: __class__

Method Details [hide private]

__init__(self, value, invert=False)
(Constructor)

source code 

Constructs a new builder.

In general, you want to use the requiring function instead of this directly.
Parameters:
  • value - an object to be tested
  • invert - optionally inverts the sense of the next assertion if True
Overrides: object.__init__

equal_to(self, other)

source code 
Asserts the value object is equal to some other object.
Parameters:
  • other - another object to test against the builder's value object
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value is not equal to other

same_as(self, other)

source code 
Asserts the value object is the same as another object.
Parameters:
  • other - another object to test for same identity
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value is not the same object as other

is_none(self)

source code 
Asserts the value object is None.
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value is not None

is_not_none(self)

source code 
Asserts the value object is not None.
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value is None

is_a(self, clazz)

source code 
Asserts the value object is an instance of a particular type.
Parameters:
  • clazz - type the value must be an instance of
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value is not an instance of clazz

length(self, length)

source code 
Asserts the value object has a specific length.
Parameters:
  • length - the value that must be returned by passing the builder value to the len built-in
Returns:
this assertion builder
Raises:
  • AssertionError - if the length of the builder's value is not equal to length

contains(self, element)

source code 
Asserts the value object contains a specific element.
Parameters:
  • element - the element that must be contained by the value object, as tested using the keyword in
Returns:
this assertion builder
Raises:
  • AssertionError - if the builder's value does not contain element

index(self, index)

source code 

Asserts the value object has a specific index.

Note: this method returns a builder for the object at the given index, allowing assertions to be made about that object but not allowing any additional assertions to be made about the original object.

The is_not modifier has no effect on this method.

For example:
   test_map = {'foo': 'bar'}
   requiring(test_map).index('foo').equal_to('bar')
Parameters:
  • index - the index that must be contained by the value object, as tested using the keyword in
Returns:
an assertion builder for the object at the given index
Raises:
  • AssertionError - if the builder's value does not contain an element at index

Property Details [hide private]

is_not

Inverts the sense of the next assertion.

This property causes the boolean sense of the next assertion to be inverted. That is, if a call to equal_to is prefixed with is_not, it will raise an error if the value object is not equal to the given value. All other subsequent assertions retain the specified sense unless also prefixed with is_not.

For example:
   s = 'foo'
   requiring(s.length).is_not.equal_to(0)
Get Method:
unreachable.is_not(self) - Inverts the sense of the next assertion.