Using python-coverage for tests in Entertainer
I recently read a blog post about python-coverage. This is a module which works out how much of a python file has been used when a python file is run.
One very helpful use it can be put to is that of working out how much of a project’s source code has been covered by unit tests and I decided to try this for the Entertainer Media Center project.
What follows is how I installed and used python-coverage to work out how much of the Entertainer Source code is actually tested when all our unittests are run. I relied upon this webpage and the command line help available from python-coverage.
First of all I installed the python module from the Ubuntu repositories:
sudo apt-get install python-coverage
This installed version 2.6
I then changed directory to where all the unittests for Entertainer are stored on my computer:
cd src/tests
After testing it in a couple of ways, I then cleared any previous history with this command:
python /usr/share/python-support/python-coverage/coverage.py -e
The actual production of the statistics is done in two stages. First you run the program which will generate the stats (In this case all the unittests):
python /usr/share/python-support/python-coverage/coverage.py -x run_tests.py
This stores a history of what lines were executed. You can then compare this history to the actual source files with:
python /usr/share/python-support/python-coverage/coverage.py -r ../*.py ../*/*.py ../*/*/*.py ../*/*/*/*.py ../*/*/*/*/*.py
This gives statistics for each individual source code file and then a set of overall statistics for the whole project. I had to use the ../*’s to make sure all the source code was used.
The overall stats that were generated for the Entertainer Project is as follows:
...
../utils/log_viewer 114 0 0%
../utils/lyrics_downloader 80 19 23%
../utils/open_feed_source_dialog 77 0 0%
../utils/preferences_dialog 200 0 0%
../utils/resolve_dialog 64 0 0%
../utils/system_tray_icon 95 0 0%
../utils/theme 88 0 0%
../utils/thumbnailer 31 27 87%
../utils/video_thumbnailer 226 126 55%
../utils/weather 106 100 94%
----------------------------------------------------------------------------------
TOTAL 13195 2206 16%
This means that out of a total of 13,195 lines of python code only 16%, 2,206 lines, is being tested by the 145 unittests that have been written so far.
Obviously increasing the coverage of the unittests will make the Entertainer much better at pinpointing bugs and fixing breaks in code as the project is developed.
Recent Comments
Thanks, I thought I'd seen it somewhere before :)...
This one is really funny :) But Gentili should specify th...
Congratulations Joshua ! I'm very happy for you. Cheer...
Hey, many thanks, this is great... Johan, Belgium...
COOL! As we know, Entertainer has some way to go before it m...