Commit 3855bc58 by Randy Döring

tests: consistently use fixture_dir

parent 4c377351
...@@ -282,6 +282,11 @@ def http() -> Iterator[type[httpretty.httpretty]]: ...@@ -282,6 +282,11 @@ def http() -> Iterator[type[httpretty.httpretty]]:
yield httpretty yield httpretty
@pytest.fixture
def project_root() -> Path:
return Path(__file__).parent.parent
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def fixture_base() -> Path: def fixture_base() -> Path:
return Path(__file__).parent / "fixtures" return Path(__file__).parent / "fixtures"
...@@ -417,11 +422,6 @@ def project_factory( ...@@ -417,11 +422,6 @@ def project_factory(
return _factory return _factory
@pytest.fixture
def project_root() -> Path:
return Path(__file__).parent.parent
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def set_simple_log_formatter() -> None: def set_simple_log_formatter() -> None:
""" """
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
...@@ -20,12 +19,11 @@ if TYPE_CHECKING: ...@@ -20,12 +19,11 @@ if TYPE_CHECKING:
from tests.helpers import TestRepository from tests.helpers import TestRepository
from tests.types import CommandTesterFactory from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
FIXTURES = Path(__file__).parent.joinpath("fixtures")
@pytest.fixture
@pytest.fixture() def setup(mocker: MockerFixture, fixture_dir: FixtureDirGetter) -> None:
def setup(mocker: MockerFixture, fixture_dir: Path):
mocker.patch.object( mocker.patch.object(
Executor, Executor,
"_download", "_download",
...@@ -46,7 +44,7 @@ def test_self_update_can_update_from_recommended_installation( ...@@ -46,7 +44,7 @@ def test_self_update_can_update_from_recommended_installation(
tester: CommandTester, tester: CommandTester,
repo: TestRepository, repo: TestRepository,
installed: TestRepository, installed: TestRepository,
): ) -> None:
new_version = Version.parse(__version__).next_minor().text new_version = Version.parse(__version__).next_minor().text
old_poetry = Package("poetry", __version__) old_poetry = Package("poetry", __version__)
......
...@@ -3,23 +3,26 @@ from __future__ import annotations ...@@ -3,23 +3,26 @@ from __future__ import annotations
import shutil import shutil
import tarfile import tarfile
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from poetry.factory import Factory from poetry.factory import Factory
if TYPE_CHECKING: if TYPE_CHECKING:
from pathlib import Path
from poetry.utils.env import VirtualEnv from poetry.utils.env import VirtualEnv
from tests.types import CommandTesterFactory from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
def test_build_with_multiple_readme_files( def test_build_with_multiple_readme_files(
tmp_path: Path, tmp_venv: VirtualEnv, command_tester_factory: CommandTesterFactory fixture_dir: FixtureDirGetter,
): tmp_path: Path,
source_dir = ( tmp_venv: VirtualEnv,
Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files" command_tester_factory: CommandTesterFactory,
) ) -> None:
source_dir = fixture_dir("with_multiple_readme_files")
target_dir = tmp_path / "project" target_dir = tmp_path / "project"
shutil.copytree(str(source_dir), str(target_dir)) shutil.copytree(str(source_dir), str(target_dir))
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
...@@ -11,6 +10,7 @@ if TYPE_CHECKING: ...@@ -11,6 +10,7 @@ if TYPE_CHECKING:
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
from tests.types import CommandTesterFactory from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
@pytest.fixture() @pytest.fixture()
...@@ -18,7 +18,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: ...@@ -18,7 +18,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
return command_tester_factory("check") return command_tester_factory("check")
def test_check_valid(tester: CommandTester): def test_check_valid(tester: CommandTester) -> None:
tester.execute() tester.execute()
expected = """\ expected = """\
...@@ -28,17 +28,14 @@ All set! ...@@ -28,17 +28,14 @@ All set!
assert tester.io.fetch_output() == expected assert tester.io.fetch_output() == expected
def test_check_invalid(mocker: MockerFixture, tester: CommandTester): def test_check_invalid(
mocker: MockerFixture, tester: CommandTester, fixture_dir: FixtureDirGetter
) -> None:
from poetry.toml import TOMLFile from poetry.toml import TOMLFile
mocker.patch( mocker.patch(
"poetry.poetry.Poetry.file", "poetry.poetry.Poetry.file",
return_value=TOMLFile( return_value=TOMLFile(fixture_dir("invalid_pyproject") / "pyproject.toml"),
Path(__file__).parent.parent.parent
/ "fixtures"
/ "invalid_pyproject"
/ "pyproject.toml"
),
new_callable=mocker.PropertyMock, new_callable=mocker.PropertyMock,
) )
...@@ -61,13 +58,12 @@ Warning: Deprecated classifier\ ...@@ -61,13 +58,12 @@ Warning: Deprecated classifier\
assert tester.io.fetch_error() == expected assert tester.io.fetch_error() == expected
def test_check_private(mocker: MockerFixture, tester: CommandTester): def test_check_private(
mocker: MockerFixture, tester: CommandTester, fixture_dir: FixtureDirGetter
) -> None:
mocker.patch( mocker.patch(
"poetry.factory.Factory.locate", "poetry.factory.Factory.locate",
return_value=Path(__file__).parent.parent.parent return_value=fixture_dir("private_pyproject") / "pyproject.toml",
/ "fixtures"
/ "private_pyproject"
/ "pyproject.toml",
) )
tester.execute() tester.execute()
......
...@@ -2,7 +2,6 @@ from __future__ import annotations ...@@ -2,7 +2,6 @@ from __future__ import annotations
import os import os
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
...@@ -22,6 +21,7 @@ from tests.helpers import mock_clone ...@@ -22,6 +21,7 @@ from tests.helpers import mock_clone
if TYPE_CHECKING: if TYPE_CHECKING:
from collections.abc import Iterator from collections.abc import Iterator
from pathlib import Path
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
...@@ -31,6 +31,7 @@ if TYPE_CHECKING: ...@@ -31,6 +31,7 @@ if TYPE_CHECKING:
from poetry.utils.env import Env from poetry.utils.env import Env
from tests.conftest import Config from tests.conftest import Config
from tests.types import CommandTesterFactory from tests.types import CommandTesterFactory
from tests.types import FixtureDirGetter
from tests.types import ProjectFactory from tests.types import ProjectFactory
...@@ -96,11 +97,12 @@ def project_directory() -> str: ...@@ -96,11 +97,12 @@ def project_directory() -> str:
@pytest.fixture @pytest.fixture
def poetry(project_directory: str, project_factory: ProjectFactory) -> Poetry: def poetry(
return project_factory( project_directory: str,
name="simple", project_factory: ProjectFactory,
source=Path(__file__).parent.parent / "fixtures" / project_directory, fixture_dir: FixtureDirGetter,
) ) -> Poetry:
return project_factory(name="simple", source=fixture_dir(project_directory))
@pytest.fixture @pytest.fixture
......
...@@ -68,13 +68,6 @@ def get_dependency( ...@@ -68,13 +68,6 @@ def get_dependency(
return Factory.create_dependency(name, constraint or "*", groups=groups) return Factory.create_dependency(name, constraint or "*", groups=groups)
def fixture(path: str | None = None) -> Path:
if path:
return FIXTURE_PATH / path
else:
return FIXTURE_PATH
def copy_or_symlink(source: Path, dest: Path) -> None: def copy_or_symlink(source: Path, dest: Path) -> None:
if dest.is_symlink() or dest.is_file(): if dest.is_symlink() or dest.is_file():
dest.unlink() # missing_ok is only available in Python >= 3.8 dest.unlink() # missing_ok is only available in Python >= 3.8
...@@ -113,7 +106,7 @@ def mock_clone( ...@@ -113,7 +106,7 @@ def mock_clone(
parsed = ParsedUrl.parse(url) parsed = ParsedUrl.parse(url)
path = re.sub(r"(.git)?$", "", parsed.pathname.lstrip("/")) path = re.sub(r"(.git)?$", "", parsed.pathname.lstrip("/"))
folder = Path(__file__).parent / "fixtures" / "git" / parsed.resource / path folder = FIXTURE_PATH / "git" / parsed.resource / path
if not source_root: if not source_root:
source_root = Path(Config.create().get("cache-dir")) / "src" source_root = Path(Config.create().get("cache-dir")) / "src"
...@@ -128,8 +121,7 @@ def mock_clone( ...@@ -128,8 +121,7 @@ def mock_clone(
def mock_download(url: str, dest: Path) -> None: def mock_download(url: str, dest: Path) -> None:
parts = urllib.parse.urlparse(url) parts = urllib.parse.urlparse(url)
fixtures = Path(__file__).parent / "fixtures" fixture = FIXTURE_PATH / parts.path.lstrip("/")
fixture = fixtures / parts.path.lstrip("/")
copy_or_symlink(fixture, dest) copy_or_symlink(fixture, dest)
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from subprocess import CalledProcessError from subprocess import CalledProcessError
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
...@@ -13,10 +12,11 @@ from poetry.utils.env import VirtualEnv ...@@ -13,10 +12,11 @@ from poetry.utils.env import VirtualEnv
if TYPE_CHECKING: if TYPE_CHECKING:
from pathlib import Path
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
FIXTURE_DIR_BASE = Path(__file__).parent.parent / "fixtures" from tests.types import FixtureDirGetter
FIXTURE_DIR_INSPECTIONS = FIXTURE_DIR_BASE / "inspection"
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
...@@ -25,13 +25,13 @@ def pep517_metadata_mock() -> None: ...@@ -25,13 +25,13 @@ def pep517_metadata_mock() -> None:
@pytest.fixture @pytest.fixture
def demo_sdist() -> Path: def demo_sdist(fixture_dir: FixtureDirGetter) -> Path:
return FIXTURE_DIR_BASE / "distributions" / "demo-0.1.0.tar.gz" return fixture_dir("distributions") / "demo-0.1.0.tar.gz"
@pytest.fixture @pytest.fixture
def demo_wheel() -> Path: def demo_wheel(fixture_dir: FixtureDirGetter) -> Path:
return FIXTURE_DIR_BASE / "distributions" / "demo-0.1.0-py2.py3-none-any.whl" return fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl"
@pytest.fixture @pytest.fixture
...@@ -128,15 +128,15 @@ def test_info_from_bdist(demo_wheel: Path) -> None: ...@@ -128,15 +128,15 @@ def test_info_from_bdist(demo_wheel: Path) -> None:
demo_check_info(info) demo_check_info(info)
def test_info_from_poetry_directory() -> None: def test_info_from_poetry_directory(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_directory( info = PackageInfo.from_directory(
FIXTURE_DIR_INSPECTIONS / "demo", disable_build=True fixture_dir("inspection") / "demo", disable_build=True
) )
demo_check_info(info) demo_check_info(info)
def test_info_from_poetry_directory_fallback_on_poetry_create_error( def test_info_from_poetry_directory_fallback_on_poetry_create_error(
mocker: MockerFixture, mocker: MockerFixture, fixture_dir: FixtureDirGetter
) -> None: ) -> None:
mock_create_poetry = mocker.patch( mock_create_poetry = mocker.patch(
"poetry.inspection.info.Factory.create_poetry", side_effect=RuntimeError "poetry.inspection.info.Factory.create_poetry", side_effect=RuntimeError
...@@ -146,16 +146,16 @@ def test_info_from_poetry_directory_fallback_on_poetry_create_error( ...@@ -146,16 +146,16 @@ def test_info_from_poetry_directory_fallback_on_poetry_create_error(
"poetry.inspection.info.get_pep517_metadata" "poetry.inspection.info.get_pep517_metadata"
) )
PackageInfo.from_directory(FIXTURE_DIR_INSPECTIONS / "demo_poetry_package") PackageInfo.from_directory(fixture_dir("inspection") / "demo_poetry_package")
assert mock_create_poetry.call_count == 1 assert mock_create_poetry.call_count == 1
assert mock_get_poetry_package.call_count == 1 assert mock_get_poetry_package.call_count == 1
assert mock_get_pep517_metadata.call_count == 1 assert mock_get_pep517_metadata.call_count == 1
def test_info_from_requires_txt() -> None: def test_info_from_requires_txt(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_metadata( info = PackageInfo.from_metadata(
FIXTURE_DIR_INSPECTIONS / "demo_only_requires_txt.egg-info" fixture_dir("inspection") / "demo_only_requires_txt.egg-info"
) )
assert info is not None assert info is not None
demo_check_info(info) demo_check_info(info)
...@@ -171,9 +171,9 @@ def test_info_from_setup_cfg(demo_setup_cfg: Path) -> None: ...@@ -171,9 +171,9 @@ def test_info_from_setup_cfg(demo_setup_cfg: Path) -> None:
demo_check_info(info, requires_dist={"package"}) demo_check_info(info, requires_dist={"package"})
def test_info_no_setup_pkg_info_no_deps() -> None: def test_info_no_setup_pkg_info_no_deps(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_directory( info = PackageInfo.from_directory(
FIXTURE_DIR_INSPECTIONS / "demo_no_setup_pkg_info_no_deps", fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps",
disable_build=True, disable_build=True,
) )
assert info.name == "demo" assert info.name == "demo"
...@@ -250,8 +250,8 @@ def test_info_setup_missing_mandatory_should_trigger_pep517( ...@@ -250,8 +250,8 @@ def test_info_setup_missing_mandatory_should_trigger_pep517(
assert spy.call_count == 1 assert spy.call_count == 1
def test_info_prefer_poetry_config_over_egg_info() -> None: def test_info_prefer_poetry_config_over_egg_info(fixture_dir: FixtureDirGetter) -> None:
info = PackageInfo.from_directory( info = PackageInfo.from_directory(
FIXTURE_DIR_INSPECTIONS / "demo_with_obsolete_egg_info" fixture_dir("inspection") / "demo_with_obsolete_egg_info"
) )
demo_check_info(info) demo_check_info(info)
...@@ -24,6 +24,7 @@ if TYPE_CHECKING: ...@@ -24,6 +24,7 @@ if TYPE_CHECKING:
from poetry.utils.env import VirtualEnv from poetry.utils.env import VirtualEnv
from tests.conftest import Config from tests.conftest import Config
from tests.types import FixtureDirGetter
@pytest.fixture @pytest.fixture
...@@ -278,7 +279,10 @@ def test_install_with_trusted_host(config: Config, env: NullEnv) -> None: ...@@ -278,7 +279,10 @@ def test_install_with_trusted_host(config: Config, env: NullEnv) -> None:
def test_install_directory_fallback_on_poetry_create_error( def test_install_directory_fallback_on_poetry_create_error(
mocker: MockerFixture, tmp_venv: VirtualEnv, pool: RepositoryPool mocker: MockerFixture,
tmp_venv: VirtualEnv,
pool: RepositoryPool,
fixture_dir: FixtureDirGetter,
) -> None: ) -> None:
mock_create_poetry = mocker.patch( mock_create_poetry = mocker.patch(
"poetry.factory.Factory.create_poetry", side_effect=RuntimeError "poetry.factory.Factory.create_poetry", side_effect=RuntimeError
...@@ -293,9 +297,7 @@ def test_install_directory_fallback_on_poetry_create_error( ...@@ -293,9 +297,7 @@ def test_install_directory_fallback_on_poetry_create_error(
"demo", "demo",
"1.0.0", "1.0.0",
source_type="directory", source_type="directory",
source_url=str( source_url=str(fixture_dir("inspection") / "demo_poetry_package"),
Path(__file__).parent.parent / "fixtures/inspection/demo_poetry_package"
),
) )
installer = PipInstaller(tmp_venv, NullIO(), pool) installer = PipInstaller(tmp_venv, NullIO(), pool)
......
...@@ -28,51 +28,40 @@ if TYPE_CHECKING: ...@@ -28,51 +28,40 @@ if TYPE_CHECKING:
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
from poetry.poetry import Poetry from poetry.poetry import Poetry
from tests.types import FixtureDirGetter
@pytest.fixture() @pytest.fixture()
def simple_poetry() -> Poetry: def simple_poetry(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("simple_project"))
Path(__file__).parent.parent.parent / "fixtures" / "simple_project"
)
return poetry return poetry
@pytest.fixture() @pytest.fixture()
def project_with_include() -> Poetry: def project_with_include(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("with-include"))
Path(__file__).parent.parent.parent / "fixtures" / "with-include"
)
return poetry return poetry
@pytest.fixture() @pytest.fixture()
def extended_poetry() -> Poetry: def extended_poetry(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("extended_project"))
Path(__file__).parent.parent.parent / "fixtures" / "extended_project"
)
return poetry return poetry
@pytest.fixture() @pytest.fixture()
def extended_without_setup_poetry() -> Poetry: def extended_without_setup_poetry(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("extended_project_without_setup"))
Path(__file__).parent.parent.parent
/ "fixtures"
/ "extended_project_without_setup"
)
return poetry return poetry
@pytest.fixture @pytest.fixture
def with_multiple_readme_files() -> Poetry: def with_multiple_readme_files(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("with_multiple_readme_files"))
Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files"
)
return poetry return poetry
...@@ -235,9 +224,11 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts( ...@@ -235,9 +224,11 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
assert [] == env.executed assert [] == env.executed
def test_builder_setup_generation_runs_with_pip_editable(tmp_path: Path) -> None: def test_builder_setup_generation_runs_with_pip_editable(
fixture_dir: FixtureDirGetter, tmp_path: Path
) -> None:
# create an isolated copy of the project # create an isolated copy of the project
fixture = Path(__file__).parent.parent.parent / "fixtures" / "extended_project" fixture = fixture_dir("extended_project")
extended_project = tmp_path / "extended_project" extended_project = tmp_path / "extended_project"
shutil.copytree(fixture, extended_project) shutil.copytree(fixture, extended_project)
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from poetry.factory import Factory from poetry.factory import Factory
...@@ -13,6 +12,7 @@ if TYPE_CHECKING: ...@@ -13,6 +12,7 @@ if TYPE_CHECKING:
from poetry.repositories import Repository from poetry.repositories import Repository
from tests.mixology.version_solver.conftest import Provider from tests.mixology.version_solver.conftest import Provider
from tests.types import FixtureDirGetter
def test_no_version_matching_constraint( def test_no_version_matching_constraint(
...@@ -94,11 +94,13 @@ Because myapp depends on both foo (1.0.0) and foo (2.0.0), version solving faile ...@@ -94,11 +94,13 @@ Because myapp depends on both foo (1.0.0) and foo (2.0.0), version solving faile
def test_disjoint_root_constraints_path_dependencies( def test_disjoint_root_constraints_path_dependencies(
root: ProjectPackage, provider: Provider, repo: Repository root: ProjectPackage,
provider: Provider,
repo: Repository,
fixture_dir: FixtureDirGetter,
) -> None: ) -> None:
provider.set_package_python_versions("^3.7") provider.set_package_python_versions("^3.7")
fixtures = Path(__file__).parent.parent.parent / "fixtures" project_dir = fixture_dir("with_conditional_path_deps")
project_dir = fixtures.joinpath("with_conditional_path_deps")
dependency1 = Factory.create_dependency("demo", {"path": project_dir / "demo_one"}) dependency1 = Factory.create_dependency("demo", {"path": project_dir / "demo_one"})
root.add_dependency(dependency1) root.add_dependency(dependency1)
dependency2 = Factory.create_dependency("demo", {"path": project_dir / "demo_two"}) dependency2 = Factory.create_dependency("demo", {"path": project_dir / "demo_two"})
......
...@@ -737,14 +737,13 @@ content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77 ...@@ -737,14 +737,13 @@ content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77
def test_root_extras_dependencies_are_ordered( def test_root_extras_dependencies_are_ordered(
locker: Locker, root: ProjectPackage locker: Locker, root: ProjectPackage, fixture_base: Path
) -> None: ) -> None:
root_dir = Path(__file__).parent.parent.joinpath("fixtures") Factory.create_dependency("B", "1.0.0", root_dir=fixture_base)
Factory.create_dependency("B", "1.0.0", root_dir=root_dir) Factory.create_dependency("C", "1.0.0", root_dir=fixture_base)
Factory.create_dependency("C", "1.0.0", root_dir=root_dir) package_first = Factory.create_dependency("first", "1.0.0", root_dir=fixture_base)
package_first = Factory.create_dependency("first", "1.0.0", root_dir=root_dir) package_second = Factory.create_dependency("second", "1.0.0", root_dir=fixture_base)
package_second = Factory.create_dependency("second", "1.0.0", root_dir=root_dir) package_third = Factory.create_dependency("third", "1.0.0", root_dir=fixture_base)
package_third = Factory.create_dependency("third", "1.0.0", root_dir=root_dir)
root.extras = { root.extras = {
"C": [package_third, package_second, package_first], "C": [package_third, package_second, package_first],
...@@ -834,25 +833,24 @@ content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77 ...@@ -834,25 +833,24 @@ content-hash = "c3d07fca33fba542ef2b2a4d75bf5b48d892d21a830e2ad9c952ba5123a52f77
def test_locker_dumps_dependency_information_correctly( def test_locker_dumps_dependency_information_correctly(
locker: Locker, root: ProjectPackage locker: Locker, root: ProjectPackage, fixture_base: Path
) -> None: ) -> None:
root_dir = Path(__file__).parent.parent.joinpath("fixtures")
package_a = get_package("A", "1.0.0") package_a = get_package("A", "1.0.0")
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"B", {"path": "project_with_extras", "develop": True}, root_dir=root_dir "B", {"path": "project_with_extras", "develop": True}, root_dir=fixture_base
) )
) )
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"C", "C",
{"path": "directory/project_with_transitive_directory_dependencies"}, {"path": "directory/project_with_transitive_directory_dependencies"},
root_dir=root_dir, root_dir=fixture_base,
) )
) )
package_a.add_dependency( package_a.add_dependency(
Factory.create_dependency( Factory.create_dependency(
"D", {"path": "distributions/demo-0.1.0.tar.gz"}, root_dir=root_dir "D", {"path": "distributions/demo-0.1.0.tar.gz"}, root_dir=fixture_base
) )
) )
package_a.add_dependency( package_a.add_dependency(
...@@ -969,15 +967,14 @@ content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8 ...@@ -969,15 +967,14 @@ content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8
def test_locker_dumps_dependency_extras_in_correct_order( def test_locker_dumps_dependency_extras_in_correct_order(
locker: Locker, root: ProjectPackage locker: Locker, root: ProjectPackage, fixture_base: Path
) -> None: ) -> None:
root_dir = Path(__file__).parent.parent.joinpath("fixtures")
package_a = get_package("A", "1.0.0") package_a = get_package("A", "1.0.0")
Factory.create_dependency("B", "1.0.0", root_dir=root_dir) Factory.create_dependency("B", "1.0.0", root_dir=fixture_base)
Factory.create_dependency("C", "1.0.0", root_dir=root_dir) Factory.create_dependency("C", "1.0.0", root_dir=fixture_base)
package_first = Factory.create_dependency("first", "1.0.0", root_dir=root_dir) package_first = Factory.create_dependency("first", "1.0.0", root_dir=fixture_base)
package_second = Factory.create_dependency("second", "1.0.0", root_dir=root_dir) package_second = Factory.create_dependency("second", "1.0.0", root_dir=fixture_base)
package_third = Factory.create_dependency("third", "1.0.0", root_dir=root_dir) package_third = Factory.create_dependency("third", "1.0.0", root_dir=fixture_base)
package_a.extras = { package_a.extras = {
"C": [package_third, package_second, package_first], "C": [package_third, package_second, package_first],
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
...@@ -21,8 +20,7 @@ if TYPE_CHECKING: ...@@ -21,8 +20,7 @@ if TYPE_CHECKING:
from pytest_mock import MockerFixture from pytest_mock import MockerFixture
from tests.conftest import Config from tests.conftest import Config
from tests.types import FixtureDirGetter
CWD = Path(__file__).parent.parent / "fixtures" / "simple_project"
class ManagerFactory(Protocol): class ManagerFactory(Protocol):
...@@ -46,13 +44,14 @@ class InvalidPlugin: ...@@ -46,13 +44,14 @@ class InvalidPlugin:
poetry.package.version = "9.9.9" poetry.package.version = "9.9.9"
@pytest.fixture() @pytest.fixture
def poetry(tmp_path: Path, config: Config) -> Poetry: def poetry(fixture_dir: FixtureDirGetter, config: Config) -> Poetry:
project_path = fixture_dir("simple_project")
poetry = Poetry( poetry = Poetry(
CWD / "pyproject.toml", project_path / "pyproject.toml",
{}, {},
ProjectPackage("simple-project", "1.2.3"), ProjectPackage("simple-project", "1.2.3"),
Locker(CWD / "poetry.lock", {}), Locker(project_path / "poetry.lock", {}),
config, config,
) )
...@@ -82,7 +81,7 @@ def test_load_plugins_and_activate( ...@@ -82,7 +81,7 @@ def test_load_plugins_and_activate(
poetry: Poetry, poetry: Poetry,
io: BufferedIO, io: BufferedIO,
with_my_plugin: None, with_my_plugin: None,
): ) -> None:
manager = manager_factory() manager = manager_factory()
manager.load_plugins() manager.load_plugins()
manager.activate(poetry, io) manager.activate(poetry, io)
...@@ -106,7 +105,7 @@ def test_load_plugins_with_invalid_plugin( ...@@ -106,7 +105,7 @@ def test_load_plugins_with_invalid_plugin(
poetry: Poetry, poetry: Poetry,
io: BufferedIO, io: BufferedIO,
with_invalid_plugin: None, with_invalid_plugin: None,
): ) -> None:
manager = manager_factory() manager = manager_factory()
with pytest.raises(ValueError): with pytest.raises(ValueError):
...@@ -118,7 +117,7 @@ def test_load_plugins_with_plugins_disabled( ...@@ -118,7 +117,7 @@ def test_load_plugins_with_plugins_disabled(
poetry: Poetry, poetry: Poetry,
io: BufferedIO, io: BufferedIO,
with_my_plugin: None, with_my_plugin: None,
): ) -> None:
no_plugin_manager.load_plugins() no_plugin_manager.load_plugins()
assert poetry.package.version.text == "1.2.3" assert poetry.package.version.text == "1.2.3"
......
...@@ -42,6 +42,7 @@ if TYPE_CHECKING: ...@@ -42,6 +42,7 @@ if TYPE_CHECKING:
from poetry.poetry import Poetry from poetry.poetry import Poetry
from tests.conftest import Config from tests.conftest import Config
from tests.types import FixtureDirGetter
from tests.types import ProjectFactory from tests.types import ProjectFactory
MINIMAL_SCRIPT = """\ MINIMAL_SCRIPT = """\
...@@ -77,9 +78,8 @@ class MockVirtualEnv(VirtualEnv): ...@@ -77,9 +78,8 @@ class MockVirtualEnv(VirtualEnv):
@pytest.fixture() @pytest.fixture()
def poetry(project_factory: ProjectFactory) -> Poetry: def poetry(project_factory: ProjectFactory, fixture_dir: FixtureDirGetter) -> Poetry:
fixture = Path(__file__).parent.parent / "fixtures" / "simple_project" return project_factory("simple", source=fixture_dir("simple_project"))
return project_factory("simple", source=fixture)
@pytest.fixture() @pytest.fixture()
...@@ -100,7 +100,7 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected( ...@@ -100,7 +100,7 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected(
@pytest.mark.skipif(sys.platform != "darwin", reason="requires darwin") @pytest.mark.skipif(sys.platform != "darwin", reason="requires darwin")
def test_venv_backup_exclusion(tmp_path: Path, manager: EnvManager): def test_venv_backup_exclusion(tmp_path: Path, manager: EnvManager) -> None:
import xattr import xattr
venv_path = tmp_path / "Virtual Env" venv_path = tmp_path / "Virtual Env"
...@@ -1042,7 +1042,7 @@ def test_check_output_with_called_process_error( ...@@ -1042,7 +1042,7 @@ def test_check_output_with_called_process_error(
@pytest.mark.parametrize("out", ["sys.stdout", "sys.stderr"]) @pytest.mark.parametrize("out", ["sys.stdout", "sys.stderr"])
def test_call_does_not_block_on_full_pipe( def test_call_does_not_block_on_full_pipe(
tmp_path: Path, tmp_venv: VirtualEnv, out: str tmp_path: Path, tmp_venv: VirtualEnv, out: str
): ) -> None:
"""see https://github.com/python-poetry/poetry/issues/7698""" """see https://github.com/python-poetry/poetry/issues/7698"""
script = tmp_path / "script.py" script = tmp_path / "script.py"
script.write_text( script.write_text(
...@@ -1664,10 +1664,8 @@ def test_generate_env_name_uses_real_path( ...@@ -1664,10 +1664,8 @@ def test_generate_env_name_uses_real_path(
@pytest.fixture() @pytest.fixture()
def extended_without_setup_poetry() -> Poetry: def extended_without_setup_poetry(fixture_dir: FixtureDirGetter) -> Poetry:
poetry = Factory().create_poetry( poetry = Factory().create_poetry(fixture_dir("extended_project_without_setup"))
Path(__file__).parent.parent / "fixtures" / "extended_project_without_setup"
)
return poetry return poetry
...@@ -1713,6 +1711,7 @@ def test_build_environment_not_called_without_build_script_specified( ...@@ -1713,6 +1711,7 @@ def test_build_environment_not_called_without_build_script_specified(
def test_create_venv_project_name_empty_sets_correct_prompt( def test_create_venv_project_name_empty_sets_correct_prompt(
fixture_dir: FixtureDirGetter,
project_factory: ProjectFactory, project_factory: ProjectFactory,
config: Config, config: Config,
mocker: MockerFixture, mocker: MockerFixture,
...@@ -1721,8 +1720,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt( ...@@ -1721,8 +1720,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt(
if "VIRTUAL_ENV" in os.environ: if "VIRTUAL_ENV" in os.environ:
del os.environ["VIRTUAL_ENV"] del os.environ["VIRTUAL_ENV"]
fixture = Path(__file__).parent.parent / "fixtures" / "no_name_project" poetry = project_factory("no", source=fixture_dir("no_name_project"))
poetry = project_factory("no", source=fixture)
manager = EnvManager(poetry) manager = EnvManager(poetry)
poetry.package.python_versions = "^3.7" poetry.package.python_versions = "^3.7"
......
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
import pytest import pytest
...@@ -14,7 +13,7 @@ if TYPE_CHECKING: ...@@ -14,7 +13,7 @@ if TYPE_CHECKING:
from tests.types import FixtureDirGetter from tests.types import FixtureDirGetter
def test_parse_requires(): def test_parse_requires() -> None:
requires = """\ requires = """\
jsonschema>=2.6.0.0,<3.0.0.0 jsonschema>=2.6.0.0,<3.0.0.0
lockfile>=0.12.0.0,<0.13.0.0 lockfile>=0.12.0.0,<0.13.0.0
...@@ -71,10 +70,8 @@ isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e5283576 ...@@ -71,10 +70,8 @@ isort@ git+git://github.com/timothycrosley/isort.git@e63ae06ec7d70b06df9e5283576
def test_default_hash(fixture_dir: FixtureDirGetter) -> None: def test_default_hash(fixture_dir: FixtureDirGetter) -> None:
root_dir = Path(__file__).parent.parent.parent
file_path = root_dir / fixture_dir("distributions/demo-0.1.0.tar.gz")
sha_256 = "9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad" sha_256 = "9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad"
assert get_file_hash(file_path) == sha_256 assert get_file_hash(fixture_dir("distributions") / "demo-0.1.0.tar.gz") == sha_256
try: try:
...@@ -130,6 +127,5 @@ except ImportError: ...@@ -130,6 +127,5 @@ except ImportError:
def test_guaranteed_hash( def test_guaranteed_hash(
hash_name: str, expected: str, fixture_dir: FixtureDirGetter hash_name: str, expected: str, fixture_dir: FixtureDirGetter
) -> None: ) -> None:
root_dir = Path(__file__).parent.parent.parent file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
file_path = root_dir / fixture_dir("distributions/demo-0.1.0.tar.gz")
assert get_file_hash(file_path, hash_name) == expected assert get_file_hash(file_path, hash_name) == expected
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment