Test a domain object by getting/setting attributes or invoking methods
Unlike ddt.MethodChecker , this class can be used without subclassing.
Just specify the targetClass in the constructor, and optionally set
itemPerRow to False if you want one target instance to be used for
all rows. You can also supply typeInfo to list the model.IType
types that should be used when invoking methods or checking their return
values. For example, you might use the following in an .ini file:
[peak.ddt.processors]
MyProcessor = ddt.ModelChecker(
targetClass = importString('my_model.MyElement'),
typeInfo = Items(
someMethodReturningInt = model.Integer,
someMethodTakingFloat = model.Float,
# etc.
)
)
If someMethodReturningInt or someMethodTakingFloat are invoked by a
test, the cell value will be converted to/from an integer or float as
appropriate.
By default, ModelChecker checks whether a column heading ends in ':
(indicating a "set" operation) or ?' (indicating a "get" operation).
If you would like to override this, you can supply a columnSuffixes
argument to the constructor, or override it in a subclass. See the
parseHeader() method for more details.
Methods
|
|
afterRow
beforeRow
getGetter
getHandler
getMapper
getSetter
parseHeader
|
|
afterRow
|
afterRow ( self )
Get rid of old instance, if needed, after finishing a row
|
|
beforeRow
|
beforeRow ( self )
Create a new instance, if needed, before starting a row
|
|
getGetter
|
getGetter ( self, name )
Get a "getting" handler for name
This is implemented by getting a ddt.ICellMapper for the named
feature from self.getMapper(name) , and returning a handler that
performs a mapper.get() operation on self.targetInstance each
time it's invoked.
|
|
getHandler
|
getHandler ( self, text )
Figure out whether handler should get or set, and how to do that
The default implementation uses self.parseHeader() to determine the
kind of handler required, and then returns self.getGetter() or
self.getSetter() accordingly.
Exceptions
|
|
ValueError( "Invalid return value from parseHeader():", getOrSet )
|
|
|
getMapper
|
getMapper ( self, name )
Get an ICellMapper for the named feature in the target class
This is done by retrieving the named attribute from the class (after
applying titleAsMethodName() to the name) and and adapting it to
the ddt.ICellMapper interface. If there is an entry in
self.typeInfo that indicates the datatype that should be used for
the column, the mapper is informed of this via its suggestType()
method.
|
|
getSetter
|
getSetter ( self, name )
Get a "setting" handler for name
This is implemented by getting a ddt.ICellMapper for the named
feature from self.getMapper(name) , and returning a handler that
performs a mapper.set() operation on self.targetInstance each
time it's invoked.
|
|
parseHeader
|
parseHeader ( self, text )
Return a (getOrSet,name) tuple for header text
getOrSet should be the string "get" or "set" , indicating how the
column is to be interpreted. name should be the name to be used for
calling self.getSetter() or self.getGetter() , respectively.
The default implementation uses self.columnSuffixes to determine the
appropriate type. The columnSuffixes attribute must be an iterable
of (suffix,getOrSet) pairs, where suffix is a string to be checked
for at the end of text , and getOrSet is a string indicating whether
the column should be get or set. The suffices in columnSuffixes are
checked in the order they are provided, so longer suffixes should be
listed before shorter ones to avoid ambiguity. An empty string may
be used as a suffix, to indicate the default behavior for a column, but
should be placed last in the suffixes, if used. If no default is
given, and no suffixes match, an error is raised, causing the header
to be marked in error and the table as a whole to be skipped.
Exceptions
|
|
ValueError( "Unable to determine column type:", text )
|
|
|