Use context managers to ensure files are closed
There were several places where context managers were not being used and
files were potentially not being closed.
I started investigating this since the unit tests are not passing if the
code directory is mounted with SSHFS. The test setUp failed to remove
directories with ``shutil.rmtree`` with "directory not empty". Looking
at the directories, there were .fuse_hidden* files so I assumed the
file handles were being leaked. The tests are still failing so I've
either missed something in my search or that was not the problem, but I
thought this would be a good change in any case.
Signed-off-by: Jeremy Cline <jeremy@jcline.org></jeremy@jcline.org>