test_tempdir.py 668 B

12345678910111213141516171819202122
  1. import os
  2. from ..tempdir import NamedFileInTemporaryDirectory
  3. from ..tempdir import TemporaryWorkingDirectory
  4. def test_named_file_in_temporary_directory():
  5. with NamedFileInTemporaryDirectory('filename') as file:
  6. name = file.name
  7. assert not file.closed
  8. assert os.path.exists(name)
  9. file.write(b'test')
  10. assert file.closed
  11. assert not os.path.exists(name)
  12. def test_temporary_working_directory():
  13. with TemporaryWorkingDirectory() as dir:
  14. assert os.path.exists(dir)
  15. assert os.path.realpath(os.curdir) == os.path.realpath(dir)
  16. assert not os.path.exists(dir)
  17. assert os.path.abspath(os.curdir) != dir