[WIP] Improve python test coverage

It's cleaner and safer with a context manager:
```python
with open(TEST_TXT_FILE, 'w') as f:
    f.write(TEST_CONTENTS)
```