Test improvements and fixes geared toward eventual Python 3 compat.