Format: text/x-python
⬇ Download File (1.1 KB)
   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  
   8  from pathlib import Path
   9  
  10  from IPython.utils.tempdir import NamedFileInTemporaryDirectory
  11  from IPython.utils.tempdir import TemporaryWorkingDirectory
  12  
  13  
  14  def test_named_file_in_temporary_directory():
  15      with NamedFileInTemporaryDirectory('filename') as file:
  16          name = file.name
  17          assert not file.closed
  18          assert Path(name).exists()
  19          file.write(b'test')
  20      assert file.closed
  21      assert not Path(name).exists()
  22  
  23  def test_temporary_working_directory():
  24      with TemporaryWorkingDirectory() as directory:
  25          directory_path = Path(directory).resolve()
  26          assert directory_path.exists()
  27          assert Path.cwd().resolve() == directory_path
  28      assert not directory_path.exists()
  29      assert Path.cwd().resolve() != directory_path
  30