Update tests, and put in appropriate with-open wrappers for cleaning up resources after tests