File: test_tmpdirs.py

package info (click to toggle)
python-auditwheel 6.6.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 980 kB
  • sloc: python: 6,165; ansic: 304; cpp: 66; sh: 28; makefile: 25; f90: 12
file content (51 lines) | stat: -rw-r--r-- 1,393 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
46
47
48
49
50
51
from __future__ import annotations

from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import pytest

from auditwheel.tmpdirs import InGivenDirectory, InTemporaryDirectory


def test_intemporarydirectory() -> None:
    cwd = Path.cwd()
    with InTemporaryDirectory() as path:
        assert path.is_dir()
        assert path.samefile(Path.cwd())
        assert not path.samefile(cwd)
    assert not path.exists()
    assert cwd.samefile(Path.cwd())


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


def test_ingivendirectory(tmp_path: Path) -> None:
    cwd = Path.cwd()
    expected_path = tmp_path / "foo"
    with InGivenDirectory(expected_path) as path:
        assert path.is_dir()
        assert path.samefile(Path.cwd())
        assert path.samefile(expected_path)
    assert path.exists()
    assert cwd.samefile(Path.cwd())


def test_ingivendirectory_cwd(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
    monkeypatch.chdir(tmp_path)
    with InGivenDirectory() as path:
        assert path.is_dir()
        assert path.samefile(Path.cwd())
        assert path.samefile(tmp_path)
    assert path.exists()


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