Minor fixes to reduce the amount of warnings

* Close the file after reading so no more ResourceWarnings in py3.
* When testing mime types, the __file__ could be a .pyc in py2.