Fix tests for Python 2.x

This branch reworks some of the tests and makes some code changes to make the tests run on both Python 2.6 and 2.7.