Moved unit-testing framework to pytest.

Previously, unit testing was done using doctests, but this quickly got
out of hand. All 'serious' unit tests have been moved to a proper unit
testing framework, but a few doctests remain for actual documentation
purposes.

By doing this, the public API docstrings were able to better mirror
the API presented in the README.

Test coverage is now 99%, so most exception paths are tested.  The
remaining 1% is an exception path that may not be possible to reach.