Fix pyflakes errors
Fix up tests