Perform tests by mapping columns to methods of the checker
If a table has columns named x , y , and z , this checker will call
self.x(cell) for the first cell in each row, self.y(cell) for the
second, and so on across each row. It's up to you to define those methods
in a subclass to do whatever is appropriate for the given cell, such
as using it for input, using it to validate output, mark the cell "right"
or "wrong", etc.
You can also override various methods of this class to use different ways
of finding the methods to be called, parse column headings differently,
etc. See each method's documentation for details.
Methods
|
|
afterRow
beforeRow
getHandler
methodNameFor
processRow
processRows
setupHandlers
|
|
afterRow
|
afterRow ( self )
Perform any post-row tear down
This method is akin to tearDown() in a PyUnit test case. It gives
you an opportunity to get rid of objects, reset values, close files,
etc. after finishing a row in the test table. The default
implementation does nothing.
|
|
beforeRow
|
beforeRow ( self )
Perform any pre-row setup
This method is akin to setUp() in a PyUnit test case. It gives you
an opportunity to create objects, reset values, open files, etc. before
starting a row in the test table. The default implementation does
nothing.
|
|
getHandler
|
getHandler ( self, text )
Get a handler using text from a cell
The default implementation computes a method name using
self.methodNameFor(text) , and then attempts to return
getattr(self,methodName) .
You can override this routine to return any callable object that
accepts a ddt.Cell as its sole parameter.
|
|
methodNameFor
|
methodNameFor ( self, text )
Convert text to a method name
The default implemenation uses titleAsMethodName to normalize the
cell text to a "camel case" (e.g. camelCase ) format.
|
|
processRow
|
processRow (
self,
row,
rows,
)
Match each cell with a handler, and invoke it
This method matches each cell in the row with the corresponding handler
from self.handlers , and then calls handler(cell) . If a handler
raises an exception, attempt to annotate the cell with the appropriate
error information.
|
|
processRows
|
processRows ( self, rows )
Set up methods from the heading row, then process other rows
This method invokes self.setupHandlers(row,rows) on the "heading"
row (the row after the title row naming the processor for this table).
It then invokes self.processRow(row,rows) on the remaining rows.
|
|
setupHandlers
|
setupHandlers (
self,
row,
rows,
)
Obtain a handler (method) corresponding to each column heading
Obtain a handler using self.getHandler(cell.text) for each cell in
the heading row, and put them in self.handlers in the same order as
they appear in the table. If an error occurs when looking up a handler,
the corresponding cell is annotated with error information, and the
table's contents are skipped, by consuming the rows iterator.
|
|