Refactor test to ensure file is closed

Python requires parentheses to call a method. Without parentheses it
will return the method object which doesn't do anything useful without
an lvalue.

Since we're in here, switch it to be a context manager to be shorter
while making sure the file gets closed.

Change-Id: Ib8b15e286c8bbca1f59c530c9200cb7a781c3d6b
Merge "Refactor test to ensure file is closed"