Copyright © 2012 JoshuaScotton.com. Silver theme by c.bavota & Juan Gordillo. Powered by WordPress.
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.



September 4, 2011 at 7:36 pm
Hey, you used to write excellent, but the last few posts have been kinda boring¡K I miss your great writings. Past several posts are just a bit out of track! come on!
September 18, 2011 at 10:34 am
Love your blog. Boy, am I pleased I found you friend! We’ve attempted to enroll for the Rss feed but it couldn’t let me through.
October 4, 2011 at 7:44 pm
I have been exploring for a bit for any high-quality articles or weblog posts in this sort of house . Exploring in Yahoo I at last stumbled upon this web site. Reading this information So i am glad to convey that I have an incredibly excellent uncanny feeling I found out just what I needed. I most unquestionably will make sure to do not fail to remember this website and provides it a look regularly.
October 14, 2011 at 12:10 am
Hello this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding expertise so I wanted to get advice from someone with experience. Any help would be enormously appreciated!
October 14, 2011 at 3:28 am
Please let me know if you’re looking for a author for your weblog. You have some really great articles and I believe I would be a good asset. If you ever want to take some of the load off, I’d love to write some articles for your blog in exchange for a link back to mine. Please blast me an email if interested. Thanks!
October 28, 2011 at 5:25 am
Hello! I know this is kinda off topic but I was wondering which blog platform are you using for this website? I’m getting tired of WordPress because I’ve had issues with hackers and I’m looking at options for another platform. I would be great if you could point me in the direction of a good platform.
October 28, 2011 at 7:21 am
Hi there just wanted to give you a quick heads up. The words in your content seem to be running off the screen in Opera. I’m not sure if this is a format issue or something to do with browser compatibility but I thought I’d post to let you know. The style and design look great though! Hope you get the problem resolved soon. Thanks
October 28, 2011 at 8:51 am
Thanks on your marvelous posting! I truly enjoyed reading it, you happen to be a great author.I will make certain to bookmark your blog and definitely will come back sometime soon. I want to encourage you to definitely continue your great job, have a nice day!
November 15, 2011 at 4:59 pm
As soon as I discovered this site I went on reddit to share some of the love with them. “Love the little trade which thou hast learned, and be content therewith.” by Marcus Aurelius Antoninus.
December 12, 2011 at 9:56 am
It is actually a nice and helpful piece of info. I’m satisfied that you just shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.
December 16, 2011 at 7:27 pm
Very nice article, exactly what I needed.