Fix Python 2 tests

This PR addresses a few unittest API compatibility bugs in Python 2 tests that were previously disabled due to #12. It also backports several changes from typing for Python 3 into typing for Python 2.

The PR is based on PR #30.