add test cases for python3

and tweak some of the code to handle the tests cases as well.