Logo Search packages:      
Sourcecode: ubuntu-sso-client version File versions  Download package

mocker::MockerBase Class Reference

Inherited by mocker::Mocker.

List of all members.

Detailed Description

Controller of mock objects.

A mocker instance is used to command recording and replay of
expectations on any number of mock objects.

Expectations should be expressed for the mock object while in
record mode (the initial one) by using the mock object itself,
and using the mocker (and/or C{expect()} as a helper) to define
additional behavior for each event.  For instance::

    mock = mocker.mock()
    assert mock.hello() == "Hi!"

In this short excerpt a mock object is being created, then an
expectation of a call to the C{hello()} method was recorded, and
when called the method should return the value C{10}.  Then, the
mocker is put in replay mode, and the expectation is satisfied by
calling the C{hello()} method, which indeed returns 10.  Finally,
a call to the L{restore()} method is performed to undo any needed
changes made in the environment, and the L{verify()} method is
called to ensure that all defined expectations were met.

The same logic can be expressed more elegantly using the
C{with mocker:} statement, as follows::

    mock = mocker.mock()
    with mocker:
        assert mock.hello() == "Hi!"

Also, the MockerTestCase class, which integrates the mocker on
a unittest.TestCase subclass, may be used to reduce the overhead
of controlling the mocker.  A test could be written as follows::

    class SampleTest(MockerTestCase):

        def test_hello(self):
            mock = self.mocker.mock()
            self.assertEquals(mock.hello(), "Hi!")

Definition at line 334 of file mocker.py.

Public Member Functions

def __init__

Static Public Attributes

 on = expect

Private Attributes


Static Private Attributes

list _recorders = []


class  __metaclass__

The documentation for this class was generated from the following file:

Generated by  Doxygen 1.6.0   Back to index