Fixes 899174 r=@gabithume, @peterbe, @brandonsavage

* PEP8 fixes
* Cleanup of debugging
* Refactor tests to use a dict and a loop