| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from pathlib import Path |
| 4 |
from typing import TYPE_CHECKING |
| 5 |
|
| 6 |
if TYPE_CHECKING: |
| 7 |
import pytest |
| 8 |
|
| 9 |
from auditwheel.tmpdirs import InGivenDirectory, InTemporaryDirectory |
| 10 |
|
| 11 |
|
| 12 |
def test_intemporarydirectory() -> None: |
| 13 |
cwd = Path.cwd() |
| 14 |
with InTemporaryDirectory() as path: |
| 15 |
assert path.is_dir() |
| 16 |
assert path.samefile(Path.cwd()) |
| 17 |
assert not path.samefile(cwd) |
| 18 |
assert not path.exists() |
| 19 |
assert cwd.samefile(Path.cwd()) |
| 20 |
|
| 21 |
|
| 22 |
def test_intemporarydirectory_name() -> None: |
| 23 |
tmp_dir = InTemporaryDirectory() |
| 24 |
with tmp_dir as path: |
| 25 |
assert tmp_dir.name == path |
| 26 |
|
| 27 |
|
| 28 |
def test_ingivendirectory(tmp_path: Path) -> None: |
| 29 |
cwd = Path.cwd() |
| 30 |
expected_path = tmp_path / "foo" |
| 31 |
with InGivenDirectory(expected_path) as path: |
| 32 |
assert path.is_dir() |
| 33 |
assert path.samefile(Path.cwd()) |
| 34 |
assert path.samefile(expected_path) |
| 35 |
assert path.exists() |
| 36 |
assert cwd.samefile(Path.cwd()) |
| 37 |
|
| 38 |
|
| 39 |
def test_ingivendirectory_cwd(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: |
| 40 |
monkeypatch.chdir(tmp_path) |
| 41 |
with InGivenDirectory() as path: |
| 42 |
assert path.is_dir() |
| 43 |
assert path.samefile(Path.cwd()) |
| 44 |
assert path.samefile(tmp_path) |
| 45 |
assert path.exists() |
| 46 |
|
| 47 |
|
| 48 |
def test_ingivendirectory_name(): |
| 49 |
given_dir = InGivenDirectory() |
| 50 |
with given_dir as path: |
| 51 |
assert given_dir.name == path |