Fix all the current pyflakes warnings in the codebase.

This fixes all the warnings pyflakes have found so far. Nothing harmful.
It primarily consists of unused imports. However, it did prevent two
unit tests from running, due to duplicate function names.