[Dev] About Item.checkItem() and tests
vajda at osafoundation.org
Wed Feb 1 19:52:02 PST 2006
For a long time there has been a method defined on Item called check() that
will perform a number of repository consistency checks and report failures in
That functionality is even available from the Chandler UI's Test menu with the
'Check Repository' menu item. It will recursively walk the UI repository view,
loading *all* items and calling check() on them.
This method has been invaluable to me for ensuring that a real Chandler
repository is still consistent after some use. No amount of unit test writing
can replace such a real life test.
I just added another method, called Item.checkItem(), that is meant to be
overriden by developers to write additional checks to verify that the
semantics of a given item are still valid within their domain of use. When
Item.check() succeeds, it calls checkItem() before returning.
For a hypothetical example, I'd expect a calendar event item to have an
'endDate' that is after its 'startDate'. It'd be pretty simple to override
checkItem() on that class and verify this constraint.
When overriding Item.checkItem(), please don't forget to call super() and
combine its return value with yours, ie, if super() returned False, return
False even if all your checks succeeded. When you find a failure, log it, but
try to continue running all checks in the method unless they depend on each
other, then return False. If all checks passed, return True.
Unless there is a bug triggered by the checkItem() code itself, checkItem()
returns False in case of error and True otherwise. This should make it
convenient to use in unit tests as well...
More information about the Dev