Restore removed tests and make Python 3 compatible

This restores tests removed in 23beb7d43e
pep8: Fix remaining issues