File: test_tmpdirs.py

package info (click to toggle)
python-auditwheel 5.3.0%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 816 kB
  • sloc: python: 4,270; ansic: 205; cpp: 58; makefile: 20; f90: 12
file content (45 lines) | stat: -rw-r--r-- 1,349 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os

from auditwheel.tmpdirs import InGivenDirectory, InTemporaryDirectory


def test_intemporarydirectory():
    cwd = os.getcwd()
    with InTemporaryDirectory() as path:
        assert os.path.isdir(path)
        assert os.path.samefile(path, os.getcwd())
        assert not os.path.samefile(cwd, path)
    assert not os.path.exists(path)
    assert os.path.samefile(cwd, os.getcwd())


def test_intemporarydirectory_name():
    tmp_dir = InTemporaryDirectory()
    with tmp_dir as path:
        assert tmp_dir.name == path


def test_ingivendirectory(tmp_path):
    cwd = os.getcwd()
    expected_path = os.path.join(str(tmp_path), "foo")
    with InGivenDirectory(expected_path) as path:
        assert os.path.isdir(path)
        assert os.path.samefile(path, os.getcwd())
        assert os.path.samefile(path, expected_path)
    assert os.path.exists(path)
    assert os.path.samefile(cwd, os.getcwd())


def test_ingivendirectory_cwd(monkeypatch, tmp_path):
    monkeypatch.chdir(tmp_path)
    with InGivenDirectory() as path:
        assert os.path.isdir(path)
        assert os.path.samefile(path, os.getcwd())
        assert os.path.samefile(path, str(tmp_path))
    assert os.path.exists(path)


def test_ingivendirectory_name():
    given_dir = InGivenDirectory()
    with given_dir as path:
        assert given_dir.name == path