premailer now with 100% test coverage

22 August 2014   0 comments   Python

Powered by Fusion×

One of my most popular GitHub Open Source projects is premailer. It's a python library for combining HTML and CSS into HTML with all its CSS inlined into tags. This is a useful and necessary technique when sending HTML emails because you can't send those with an external CSS file (or even a CSS style tag in many cases).

The project has had 23 contributors so far and as always people come in get some itch they have scratched and then leave. I really try to get good test coverage and when people come with code I almost always require that it should come with tests too.

But sometimes you miss things. Also, this project was born as a weekend hack that slowly morphed into an actual package and its own repository and I bet there was code from that day that was never fully test covered.

So today I combed through the code and plugged all the holes where there wasn't test coverage.
Also, I set up Coveralls (project page) which is an awesome service that hooks itself up with Travis CI so that on every build and every Pull Request, the tests are run with --with-cover on nosetests and that output is reported to Coveralls.

The relevant changes you need to do are:

1) You need to go to (sign in with your GitHub account) and add the repo.
2) Edit your .travis.yml file to contain the following:

    - pip install coverage
    - pip install coveralls
    - coveralls

And you need to execute your tests so that coverage is calculated (the coverage module stores everything in a .coverage file which coveralls analyzes and sends). So in my case I change to this:

    - nosetests premailer --with-cover --cover-erase --cover-package=premailer

3) You must also give coveralls some clues. So it reports on only the relevant files. Here's what mine looked like:

source = premailer

omit = premailer/test*

Now, I get to have a cute "coverage: 100%" badge in the README and when people post pull requests Coveralls will post a comment to reflect how the pull request changes the test coverage.

I am so grateful for all these wonderful tools. And it's all free too!


Thank you for posting a comment

Your email will never ever be published

Related posts

Aggressively prefetching everything you might click 20 August 2014
How I back up all my photos on S3 via Dropbox 28 August 2014
ElasticSearch 5 in Travis-CI 06 January 2017
Premailer 3.0.0 - classes kept by default 07 June 2016 08 July 2015
premailer 2.9.0 and new rules for `base_url` 11 May 2015
Premailer on Python 3 08 October 2014
COPYFILE_DISABLE and python distutils in python 2.6 12 April 2014
premailer now excludes pseudo selectors by default 27 May 2013
premailer now honours specificity 21 March 2013
Gamification for me as a software developer 21 December 2012
How to use premailer as a command line script 13 July 2012