Reorganise tests.

Split tests.py into several different files. Fix flake8 errors.
Flake8 fixes.
Update HISTORY.
Switch to test.py for unit tests.