test_tempdir.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. #-----------------------------------------------------------------------------
  2. # Copyright (C) 2012- The IPython Development Team
  3. #
  4. # Distributed under the terms of the BSD License. The full license is in
  5. # the file COPYING, distributed as part of this software.
  6. #-----------------------------------------------------------------------------
  7. import os
  8. from IPython.utils.tempdir import NamedFileInTemporaryDirectory
  9. from IPython.utils.tempdir import TemporaryWorkingDirectory
  10. def test_named_file_in_temporary_directory():
  11. with NamedFileInTemporaryDirectory('filename') as file:
  12. name = file.name
  13. assert not file.closed
  14. assert os.path.exists(name)
  15. file.write(b'test')
  16. assert file.closed
  17. assert not os.path.exists(name)
  18. def test_temporary_working_directory():
  19. with TemporaryWorkingDirectory() as dir:
  20. assert os.path.exists(dir)
  21. assert os.path.realpath(os.curdir) == os.path.realpath(dir)
  22. assert not os.path.exists(dir)
  23. assert os.path.abspath(os.curdir) != dir