Fix Python 3 support, add functional test

Python 3 issue was hidden in code not covered by unit tests so I added a
functional test that covers most of the common code.

Change-Id: I1f41209b5992588a8430dd1456d28f88d61a7e86