test_env_site.py (poetry-1.1.15) | : | test_env_site.py (poetry-1.2.0) | ||
---|---|---|---|---|
from __future__ import annotations | ||||
import uuid | import uuid | |||
from poetry.utils._compat import Path | from pathlib import Path | |||
from typing import TYPE_CHECKING | ||||
from poetry.utils._compat import decode | from poetry.utils._compat import decode | |||
from poetry.utils.env import SitePackages | from poetry.utils.env import SitePackages | |||
def test_env_site_simple(tmp_dir, mocker): | if TYPE_CHECKING: | |||
from pytest_mock import MockerFixture | ||||
def test_env_site_simple(tmp_dir: str, mocker: MockerFixture): | ||||
# emulate permission error when creating directory | # emulate permission error when creating directory | |||
mocker.patch("poetry.utils._compat.Path.mkdir", side_effect=OSError()) | mocker.patch("pathlib.Path.mkdir", side_effect=OSError()) | |||
site_packages = SitePackages(Path("/non-existent"), fallbacks=[Path(tmp_dir) ]) | site_packages = SitePackages(Path("/non-existent"), fallbacks=[Path(tmp_dir) ]) | |||
candidates = site_packages.make_candidates(Path("hello.txt"), writable_only= True) | candidates = site_packages.make_candidates(Path("hello.txt"), writable_only= True) | |||
hello = Path(tmp_dir) / "hello.txt" | hello = Path(tmp_dir) / "hello.txt" | |||
assert len(candidates) == 1 | assert len(candidates) == 1 | |||
assert candidates[0].as_posix() == hello.as_posix() | assert candidates[0].as_posix() == hello.as_posix() | |||
content = decode(str(uuid.uuid4())) | content = decode(str(uuid.uuid4())) | |||
site_packages.write_text(Path("hello.txt"), content, encoding="utf-8") | site_packages.write_text(Path("hello.txt"), content, encoding="utf-8") | |||
assert hello.read_text(encoding="utf-8") == content | assert hello.read_text(encoding="utf-8") == content | |||
assert not (site_packages.path / "hello.txt").exists() | assert not (site_packages.path / "hello.txt").exists() | |||
def test_env_site_select_first(tmp_dir): | def test_env_site_select_first(tmp_dir: str): | |||
path = Path(tmp_dir) | path = Path(tmp_dir) | |||
fallback = path / "fallback" | fallback = path / "fallback" | |||
fallback.mkdir(parents=True) | fallback.mkdir(parents=True) | |||
site_packages = SitePackages(path, fallbacks=[fallback]) | site_packages = SitePackages(path, fallbacks=[fallback]) | |||
candidates = site_packages.make_candidates(Path("hello.txt"), writable_only= True) | candidates = site_packages.make_candidates(Path("hello.txt"), writable_only= True) | |||
assert len(candidates) == 2 | assert len(candidates) == 2 | |||
assert len(site_packages.find(Path("hello.txt"))) == 0 | assert len(site_packages.find(Path("hello.txt"))) == 0 | |||
End of changes. 5 change blocks. | ||||
4 lines changed or deleted | 11 lines changed or added |