Fix a load of test and import issues causing tests to fail on Python 3