add encoding tests

We also test the internal _encode/_decode functions.
These are not part of the API, but it might be good
to test these explicitely (Python 2/3 pitfall).
We have to make sure that this is in sync with the implementation
though.