EPx professional blog and repository for braindumps

2007/02/09

Easy-to-use Python test coverage tool


http://nedbatchelder.com/code/modules/coverage.html


I had written a basic test routine for Luca, my
current pet project, while I felt the need of coverage statistics, to see how effective were the
tests written so far. Googling around I found the URL above and a very nice tool. It is a simple Python script (coverage.py) that you run like:


coverage.py -x your_script.py


and it starts collecting data in a .coverage hidden file. After you're done, you can run statistics with


coverage.py -r


It will include standard Python modules in the list, something you are probably not testing the coverage, so try


coverage.py -r -o /usr/lib/python2.4


and only "your" modules will be reported. Probaby the -o parameter should have been passed in first command along with -x, so it would not collect standard libraries' data at all, and making the execution faster. If you want detailed information of which code was or was not covered, do


coverage.py -a my_python_script.py


Which will create a my_python_script.py,covered file with information about what code was covered. Example of that report:


> try:
> db_row = self.table.get(id)
> row = self.db_to_row(db_row)
> intermediate = self.row_to_intermediate(row)
> except notfound, e:
> err = self.sqlnotfound(e)
! except modelerror, e:
! err = e.args[0]
! except sqlerror, e:
! err = self.sqlerr(e)


It means that the main code as well as the "notfound" exception were touched by the test, while the modelerror and sqlerror were never tested.

2007/02/01

BOSSA Conference


I have just confirmed my presence in the BOSSA Conference. Even though I am leaving Recife city, INdT was kind enough to invite me for this event.

Many big shots from the open source mobile community are coming too. I expect this event to be a unique opportunity to meet people, exchange ideas and sharpen our vision of future for mobile open source development.

Python in Series 60 cell phones, Python for Maemo, LLVM, UWB, WiMax, OLPC, Bluetooth, Maemo, Symbian, multimedia codecs... If any of those subjects are of your interest (I am sure that anyone keeps an eye on a couple of them), that's the place to be from March 12th to 14th.

My particular lecture (that may still be refactored into a BoF or maybe even a very productive after-hours beer-powered chat :) will be about Mamona, a SDK-related meta-project. Me and the team expect to exchange many ideas with people from other SDK-related projects (Scratchbox, OpenEmbedded etc.) and align our roadmaps in order to offer the best development experience for open-source application writing.

Be there!