Made four test files more robust.

Adjusted try ... finally blocks to make sure no temporary files linger after
tests.