Package lib :: Module mock :: Class Mock
[hide private]
[frames] | no frames]

Class Mock

source code


The Mock class emulates any other class for testing purposes. All method calls are stored for later examination.
Instance Methods [hide private]
 
__getattr__(self, name) source code
 
__init__(self, returnValues=None, realClass=None)
The Mock class constructor takes a dictionary of method names and the values they return.
source code
 
_checkInterfaceCall(self, name, callParams, callKwParams)
Check that a call to a method of the given name to the original class with the given parameters would not fail.
source code
 
_setupSubclassMethodInterceptors(self) source code
 
getAllCalls(self)
Return a list of MockCall objects, representing all the methods in the order they were called.
source code
 
getNamedCalls(self, methodName)
Return a list of MockCall objects, representing all the calls to the named method in the order they were called.
source code
 
mockAddReturnValues(self, **methodReturnValues) source code
 
mockCheckCall(self, index, name, *args, **kwargs)
test that the index-th call had the specified name and parameters
source code
 
mockGetAllCalls(self)
Return a list of MockCall objects, representing all the methods in the order they were called.
source code
 
mockGetNamedCalls(self, methodName)
Return a list of MockCall objects, representing all the calls to the named method in the order they were called.
source code
 
mockSetExpectation(self, name, testFn, after=0, until=0) 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]

__getattr__(self, name)
(Qualification operator)

source code 

__init__(self, returnValues=None, realClass=None)
(Constructor)

source code 
The Mock class constructor takes a dictionary of method names and the values they return. Methods that are not in the returnValues dictionary will return None. You may also supply a class whose interface is being mocked. All calls will be checked to see if they appear in the original interface. Any calls to methods not appearing in the real class will raise a MockInterfaceError. Any calls that would fail due to non-matching parameter lists will also raise a MockInterfaceError. Both of these help to prevent the Mock class getting out of sync with the class it is Mocking.
Overrides: object.__init__

_checkInterfaceCall(self, name, callParams, callKwParams)

source code 
Check that a call to a method of the given name to the original class with the given parameters would not fail. If it would fail, raise a MockInterfaceError. Based on the Python 2.3.3 Reference Manual section 5.3.4: Calls.

_setupSubclassMethodInterceptors(self)

source code 

getAllCalls(self)

source code 
Return a list of MockCall objects, representing all the methods in the order they were called.

getNamedCalls(self, methodName)

source code 
Return a list of MockCall objects, representing all the calls to the named method in the order they were called.

mockAddReturnValues(self, **methodReturnValues)

source code 

mockCheckCall(self, index, name, *args, **kwargs)

source code 
test that the index-th call had the specified name and parameters

mockGetAllCalls(self)

source code 
Return a list of MockCall objects, representing all the methods in the order they were called.

mockGetNamedCalls(self, methodName)

source code 
Return a list of MockCall objects, representing all the calls to the named method in the order they were called.

mockSetExpectation(self, name, testFn, after=0, until=0)

source code