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

Module mock

source code

Mock object library for Python. Mock objects can be used when unit testing to remove a dependency on another production class. They are typically used when the dependency would either pull in lots of other classes, or significantly slow down the execution of the test. They are also used to create exceptional conditions that cannot otherwise be easily triggered in the class under test.

Version: 0.1.0

Classes [hide private]
  MockInterfaceError
  Mock
The Mock class emulates any other class for testing purposes.
  MockCall
MockCall records the name and parameters of a call to an instance of a Mock class.
  MockCallable
Intercepts the call and records it, then delegates to either the mock's dictionary of mock return values that was passed in to the constructor, or a handcrafted method of a Mock subclass.
  ReturnValuesBase
  ReturnValues
  ReturnIterator
Functions [hide private]
 
_getNumPosSeenAndCheck(numPosCallParams, callKwParams, args, varkw)
Positional arguments can appear as call parameters either named as a named (keyword) parameter, or just as a value to be matched by position.
source code
 
_findFunc(cl, name)
Depth first search for a method with a given name.
source code
 
expectParams(*params, **keywords)
check that the callObj is called with specified params and keywords
source code
 
expectAfter(*methods)
check that the function is only called after all the functions in 'methods'
source code
 
expectException(exception, *args, **kwargs)
raise an exception when the method is called
source code
 
expectParam(paramIdx, cond)
check that the callObj is called with parameter specified by paramIdx (a position index or keyword) fulfills the condition specified by cond.
source code
 
EQ(value) source code
 
NE(value) source code
 
GT(value) source code
 
LT(value) source code
 
GE(value) source code
 
LE(value) source code
 
AND(*condlist) source code
 
OR(*condlist) source code
 
NOT(cond) source code
 
MATCHES(regex, *args, **kwargs) source code
 
SEQ(*sequence) source code
 
IS(instance) source code
 
ISINSTANCE(class_) source code
 
ISSUBCLASS(class_) source code
 
CONTAINS(val) source code
 
IN(container) source code
 
HASATTR(attr) source code
 
HASMETHOD(method) source code

Imports: inspect, re, CALLABLE


Function Details [hide private]

_getNumPosSeenAndCheck(numPosCallParams, callKwParams, args, varkw)

source code 
Positional arguments can appear as call parameters either named as a named (keyword) parameter, or just as a value to be matched by position. Count the positional arguments that are given by either keyword or position, and check for duplicate specifications. Also check for arguments specified by keyword that do not appear in the method's parameter list.

_findFunc(cl, name)

source code 
Depth first search for a method with a given name.

expectParams(*params, **keywords)

source code 
check that the callObj is called with specified params and keywords

expectAfter(*methods)

source code 
check that the function is only called after all the functions in 'methods'

expectException(exception, *args, **kwargs)

source code 
raise an exception when the method is called

expectParam(paramIdx, cond)

source code 
check that the callObj is called with parameter specified by paramIdx (a position index or keyword) fulfills the condition specified by cond. cond is a function that takes a single argument, the value to test.

EQ(value)

source code 

NE(value)

source code 

GT(value)

source code 

LT(value)

source code 

GE(value)

source code 

LE(value)

source code 

AND(*condlist)

source code 

OR(*condlist)

source code 

NOT(cond)

source code 

MATCHES(regex, *args, **kwargs)

source code 

SEQ(*sequence)

source code 

IS(instance)

source code 

ISINSTANCE(class_)

source code 

ISSUBCLASS(class_)

source code 

CONTAINS(val)

source code 

IN(container)

source code 

HASATTR(attr)

source code 

HASMETHOD(method)

source code