Regression fix

c8af625aa4 introduced a regression, no failing tests were found.
Tests weren't catching the problem, so I also fixed the tests.

Tested on Python 2.6, 2.7.3 and 3.1