Wednesday, August 13, 2008

Cassopi testing

Today I wrote a tiny script that helps me to handle testing easier. Originally each file to be tested had to contain following block at the end (Does someone know if blogspot has code block btw?):

# enable contract checking
import contract
contract.checkmod(__name__)

def _test():
import doctest
return doctest.testmod()

if __name__ == '__main__':
_test()

Of course it's not much code but nevertheless on longer term it would just get annoying to add that to the end of almost each file. Also extending it would be somewhat nasty as you would have to edit all files containing it.

Therefore I ended up writing a simple script that can be executed at the root of Cassopi source (/cassopi/). You just type "./tester.py modulename" and it runs contract tests (if contract module is available) and doctests. I might add coverage testing there later but at the moment I am happy with those two. You can find the script at http://code.google.com/p/cassopi/source/browse/trunk/cassopi/tester.py .

I also found a great page containing more documentation for the contract module. Check out http://people.cs.uchicago.edu/~knorby/pycontract-doc/ .

No comments: