refactor tests, use NamedTemporaryFile