remove unittest2 and fix various warnings in py3

This PR removes ``unittest2`` dependency, which entails a few changes to ``assert``s (``assertItemsEqual``is removed in Py3).

This also fixed a lot of issues that produced warnings in Py3.
  - use ``assertEqual`` instead of ``assertEquals``
  - don't leave files open (use ``with``)
  - ``html.escape`` instead of ``cgi.escape``