File: test_tempdir.py

package info (click to toggle)
ipython-genutils 0.2.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: python: 885; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 668 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

import os

from ..tempdir import NamedFileInTemporaryDirectory
from ..tempdir import TemporaryWorkingDirectory


def test_named_file_in_temporary_directory():
    with NamedFileInTemporaryDirectory('filename') as file:
        name = file.name
        assert not file.closed
        assert os.path.exists(name)
        file.write(b'test')
    assert file.closed
    assert not os.path.exists(name)

def test_temporary_working_directory():
    with TemporaryWorkingDirectory() as dir:
        assert os.path.exists(dir)
        assert os.path.realpath(os.curdir) == os.path.realpath(dir)
    assert not os.path.exists(dir)
    assert os.path.abspath(os.curdir) != dir