Doctests to unittests

Copied most doctests to unit tests. `make test` and `tox` don't run the doctests any more.