fix some python3 issues

* close the test files in the dynamic tests
* use str() instead of unicode() when using python 3.x