I need this for some tests, and it makes code clearer. This commit also changes some assertEqual calls to use (actual, expected) order and fix some pyflakes warnings.