diff --git a/tests/conftest.py b/tests/conftest.py index 98e6030dd18..65abc45743a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -282,6 +282,11 @@ def http() -> Iterator[type[httpretty.httpretty]]: yield httpretty +@pytest.fixture +def project_root() -> Path: + return Path(__file__).parent.parent + + @pytest.fixture(scope="session") def fixture_base() -> Path: return Path(__file__).parent / "fixtures" @@ -417,11 +422,6 @@ def _factory( return _factory -@pytest.fixture -def project_root() -> Path: - return Path(__file__).parent.parent - - @pytest.fixture(autouse=True) def set_simple_log_formatter() -> None: """ diff --git a/tests/console/commands/self/test_update.py b/tests/console/commands/self/test_update.py index 6720406de8b..d2c6ef0c933 100644 --- a/tests/console/commands/self/test_update.py +++ b/tests/console/commands/self/test_update.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -20,12 +19,11 @@ from tests.helpers import TestRepository from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter -FIXTURES = Path(__file__).parent.joinpath("fixtures") - -@pytest.fixture() -def setup(mocker: MockerFixture, fixture_dir: Path): +@pytest.fixture +def setup(mocker: MockerFixture, fixture_dir: FixtureDirGetter) -> None: mocker.patch.object( Executor, "_download", @@ -46,7 +44,7 @@ def test_self_update_can_update_from_recommended_installation( tester: CommandTester, repo: TestRepository, installed: TestRepository, -): +) -> None: new_version = Version.parse(__version__).next_minor().text old_poetry = Package("poetry", __version__) diff --git a/tests/console/commands/test_build.py b/tests/console/commands/test_build.py index 2d7ed87007a..ed9f3a3c5fa 100644 --- a/tests/console/commands/test_build.py +++ b/tests/console/commands/test_build.py @@ -3,23 +3,26 @@ import shutil import tarfile -from pathlib import Path from typing import TYPE_CHECKING from poetry.factory import Factory if TYPE_CHECKING: + from pathlib import Path + from poetry.utils.env import VirtualEnv from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter def test_build_with_multiple_readme_files( - tmp_path: Path, tmp_venv: VirtualEnv, command_tester_factory: CommandTesterFactory -): - source_dir = ( - Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files" - ) + fixture_dir: FixtureDirGetter, + tmp_path: Path, + tmp_venv: VirtualEnv, + command_tester_factory: CommandTesterFactory, +) -> None: + source_dir = fixture_dir("with_multiple_readme_files") target_dir = tmp_path / "project" shutil.copytree(str(source_dir), str(target_dir)) diff --git a/tests/console/commands/test_check.py b/tests/console/commands/test_check.py index f23276c5c6d..771f95813dc 100644 --- a/tests/console/commands/test_check.py +++ b/tests/console/commands/test_check.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -11,6 +10,7 @@ from pytest_mock import MockerFixture from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter @pytest.fixture() @@ -18,7 +18,7 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester: return command_tester_factory("check") -def test_check_valid(tester: CommandTester): +def test_check_valid(tester: CommandTester) -> None: tester.execute() expected = """\ @@ -28,17 +28,14 @@ def test_check_valid(tester: CommandTester): 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 mocker.patch( "poetry.poetry.Poetry.file", - return_value=TOMLFile( - Path(__file__).parent.parent.parent - / "fixtures" - / "invalid_pyproject" - / "pyproject.toml" - ), + return_value=TOMLFile(fixture_dir("invalid_pyproject") / "pyproject.toml"), new_callable=mocker.PropertyMock, ) @@ -61,13 +58,12 @@ def test_check_invalid(mocker: MockerFixture, tester: CommandTester): 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( "poetry.factory.Factory.locate", - return_value=Path(__file__).parent.parent.parent - / "fixtures" - / "private_pyproject" - / "pyproject.toml", + return_value=fixture_dir("private_pyproject") / "pyproject.toml", ) tester.execute() diff --git a/tests/console/conftest.py b/tests/console/conftest.py index 7813273e1a8..8d04adf2c42 100644 --- a/tests/console/conftest.py +++ b/tests/console/conftest.py @@ -2,7 +2,6 @@ import os -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -22,6 +21,7 @@ if TYPE_CHECKING: from collections.abc import Iterator + from pathlib import Path from pytest_mock import MockerFixture @@ -31,6 +31,7 @@ from poetry.utils.env import Env from tests.conftest import Config from tests.types import CommandTesterFactory + from tests.types import FixtureDirGetter from tests.types import ProjectFactory @@ -96,11 +97,12 @@ def project_directory() -> str: @pytest.fixture -def poetry(project_directory: str, project_factory: ProjectFactory) -> Poetry: - return project_factory( - name="simple", - source=Path(__file__).parent.parent / "fixtures" / project_directory, - ) +def poetry( + project_directory: str, + project_factory: ProjectFactory, + fixture_dir: FixtureDirGetter, +) -> Poetry: + return project_factory(name="simple", source=fixture_dir(project_directory)) @pytest.fixture diff --git a/tests/helpers.py b/tests/helpers.py index 3ab77da917b..b21de6a551d 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -68,13 +68,6 @@ def get_dependency( 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: if dest.is_symlink() or dest.is_file(): dest.unlink() # missing_ok is only available in Python >= 3.8 @@ -113,7 +106,7 @@ def mock_clone( parsed = ParsedUrl.parse(url) 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: source_root = Path(Config.create().get("cache-dir")) / "src" @@ -128,8 +121,7 @@ def mock_clone( def mock_download(url: str, dest: Path) -> None: parts = urllib.parse.urlparse(url) - fixtures = Path(__file__).parent / "fixtures" - fixture = fixtures / parts.path.lstrip("/") + fixture = FIXTURE_PATH / parts.path.lstrip("/") copy_or_symlink(fixture, dest) diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index 4b529e3bedc..4b1e0335944 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from subprocess import CalledProcessError from typing import TYPE_CHECKING @@ -13,10 +12,11 @@ if TYPE_CHECKING: + from pathlib import Path + from pytest_mock import MockerFixture -FIXTURE_DIR_BASE = Path(__file__).parent.parent / "fixtures" -FIXTURE_DIR_INSPECTIONS = FIXTURE_DIR_BASE / "inspection" + from tests.types import FixtureDirGetter @pytest.fixture(autouse=True) @@ -25,13 +25,13 @@ def pep517_metadata_mock() -> None: @pytest.fixture -def demo_sdist() -> Path: - return FIXTURE_DIR_BASE / "distributions" / "demo-0.1.0.tar.gz" +def demo_sdist(fixture_dir: FixtureDirGetter) -> Path: + return fixture_dir("distributions") / "demo-0.1.0.tar.gz" @pytest.fixture -def demo_wheel() -> Path: - return FIXTURE_DIR_BASE / "distributions" / "demo-0.1.0-py2.py3-none-any.whl" +def demo_wheel(fixture_dir: FixtureDirGetter) -> Path: + return fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl" @pytest.fixture @@ -128,15 +128,15 @@ def test_info_from_bdist(demo_wheel: Path) -> None: 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( - FIXTURE_DIR_INSPECTIONS / "demo", disable_build=True + fixture_dir("inspection") / "demo", disable_build=True ) demo_check_info(info) def test_info_from_poetry_directory_fallback_on_poetry_create_error( - mocker: MockerFixture, + mocker: MockerFixture, fixture_dir: FixtureDirGetter ) -> None: mock_create_poetry = mocker.patch( "poetry.inspection.info.Factory.create_poetry", side_effect=RuntimeError @@ -146,16 +146,16 @@ def test_info_from_poetry_directory_fallback_on_poetry_create_error( "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_get_poetry_package.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( - FIXTURE_DIR_INSPECTIONS / "demo_only_requires_txt.egg-info" + fixture_dir("inspection") / "demo_only_requires_txt.egg-info" ) assert info is not None demo_check_info(info) @@ -171,9 +171,9 @@ def test_info_from_setup_cfg(demo_setup_cfg: Path) -> None: 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( - FIXTURE_DIR_INSPECTIONS / "demo_no_setup_pkg_info_no_deps", + fixture_dir("inspection") / "demo_no_setup_pkg_info_no_deps", disable_build=True, ) assert info.name == "demo" @@ -250,8 +250,8 @@ def test_info_setup_missing_mandatory_should_trigger_pep517( 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( - FIXTURE_DIR_INSPECTIONS / "demo_with_obsolete_egg_info" + fixture_dir("inspection") / "demo_with_obsolete_egg_info" ) demo_check_info(info) diff --git a/tests/installation/test_pip_installer.py b/tests/installation/test_pip_installer.py index fa16adc4aa7..2a07da92f73 100644 --- a/tests/installation/test_pip_installer.py +++ b/tests/installation/test_pip_installer.py @@ -24,6 +24,7 @@ from poetry.utils.env import VirtualEnv from tests.conftest import Config + from tests.types import FixtureDirGetter @pytest.fixture @@ -278,7 +279,10 @@ def test_install_with_trusted_host(config: Config, env: NullEnv) -> None: 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: mock_create_poetry = mocker.patch( "poetry.factory.Factory.create_poetry", side_effect=RuntimeError @@ -293,9 +297,7 @@ def test_install_directory_fallback_on_poetry_create_error( "demo", "1.0.0", source_type="directory", - source_url=str( - Path(__file__).parent.parent / "fixtures/inspection/demo_poetry_package" - ), + source_url=str(fixture_dir("inspection") / "demo_poetry_package"), ) installer = PipInstaller(tmp_venv, NullIO(), pool) diff --git a/tests/masonry/builders/test_editable_builder.py b/tests/masonry/builders/test_editable_builder.py index eab115b3181..28b6628a972 100644 --- a/tests/masonry/builders/test_editable_builder.py +++ b/tests/masonry/builders/test_editable_builder.py @@ -28,51 +28,40 @@ from pytest_mock import MockerFixture from poetry.poetry import Poetry + from tests.types import FixtureDirGetter @pytest.fixture() -def simple_poetry() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent.parent / "fixtures" / "simple_project" - ) +def simple_poetry(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("simple_project")) return poetry @pytest.fixture() -def project_with_include() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent.parent / "fixtures" / "with-include" - ) +def project_with_include(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("with-include")) return poetry @pytest.fixture() -def extended_poetry() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent.parent / "fixtures" / "extended_project" - ) +def extended_poetry(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("extended_project")) return poetry @pytest.fixture() -def extended_without_setup_poetry() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent.parent - / "fixtures" - / "extended_project_without_setup" - ) +def extended_without_setup_poetry(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("extended_project_without_setup")) return poetry @pytest.fixture -def with_multiple_readme_files() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent.parent / "fixtures" / "with_multiple_readme_files" - ) +def with_multiple_readme_files(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("with_multiple_readme_files")) return poetry @@ -235,9 +224,11 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts( 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 - fixture = Path(__file__).parent.parent.parent / "fixtures" / "extended_project" + fixture = fixture_dir("extended_project") extended_project = tmp_path / "extended_project" shutil.copytree(fixture, extended_project) diff --git a/tests/mixology/version_solver/test_unsolvable.py b/tests/mixology/version_solver/test_unsolvable.py index 3886949a672..92cc5a98515 100644 --- a/tests/mixology/version_solver/test_unsolvable.py +++ b/tests/mixology/version_solver/test_unsolvable.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING from poetry.factory import Factory @@ -13,6 +12,7 @@ from poetry.repositories import Repository from tests.mixology.version_solver.conftest import Provider + from tests.types import FixtureDirGetter def test_no_version_matching_constraint( @@ -94,11 +94,13 @@ def test_disjoint_root_constraints( def test_disjoint_root_constraints_path_dependencies( - root: ProjectPackage, provider: Provider, repo: Repository + root: ProjectPackage, + provider: Provider, + repo: Repository, + fixture_dir: FixtureDirGetter, ) -> None: provider.set_package_python_versions("^3.7") - fixtures = Path(__file__).parent.parent.parent / "fixtures" - project_dir = fixtures.joinpath("with_conditional_path_deps") + project_dir = fixture_dir("with_conditional_path_deps") dependency1 = Factory.create_dependency("demo", {"path": project_dir / "demo_one"}) root.add_dependency(dependency1) dependency2 = Factory.create_dependency("demo", {"path": project_dir / "demo_two"}) diff --git a/tests/packages/test_locker.py b/tests/packages/test_locker.py index 80b689b1570..bdd80e4ec86 100644 --- a/tests/packages/test_locker.py +++ b/tests/packages/test_locker.py @@ -737,14 +737,13 @@ def test_locker_should_raise_an_error_if_lock_version_is_newer_and_not_allowed( def test_root_extras_dependencies_are_ordered( - locker: Locker, root: ProjectPackage + locker: Locker, root: ProjectPackage, fixture_base: Path ) -> None: - root_dir = Path(__file__).parent.parent.joinpath("fixtures") - Factory.create_dependency("B", "1.0.0", root_dir=root_dir) - Factory.create_dependency("C", "1.0.0", root_dir=root_dir) - package_first = Factory.create_dependency("first", "1.0.0", root_dir=root_dir) - package_second = Factory.create_dependency("second", "1.0.0", root_dir=root_dir) - package_third = Factory.create_dependency("third", "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=fixture_base) + package_first = Factory.create_dependency("first", "1.0.0", root_dir=fixture_base) + package_second = Factory.create_dependency("second", "1.0.0", root_dir=fixture_base) + package_third = Factory.create_dependency("third", "1.0.0", root_dir=fixture_base) root.extras = { "C": [package_third, package_second, package_first], @@ -834,25 +833,24 @@ def test_locker_should_neither_emit_warnings_nor_raise_error_for_lower_compatibl def test_locker_dumps_dependency_information_correctly( - locker: Locker, root: ProjectPackage + locker: Locker, root: ProjectPackage, fixture_base: Path ) -> None: - root_dir = Path(__file__).parent.parent.joinpath("fixtures") package_a = get_package("A", "1.0.0") package_a.add_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( Factory.create_dependency( "C", {"path": "directory/project_with_transitive_directory_dependencies"}, - root_dir=root_dir, + root_dir=fixture_base, ) ) package_a.add_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( @@ -969,15 +967,14 @@ def test_locker_dumps_subdir(locker: Locker, root: ProjectPackage) -> None: def test_locker_dumps_dependency_extras_in_correct_order( - locker: Locker, root: ProjectPackage + locker: Locker, root: ProjectPackage, fixture_base: Path ) -> None: - root_dir = Path(__file__).parent.parent.joinpath("fixtures") package_a = get_package("A", "1.0.0") - Factory.create_dependency("B", "1.0.0", root_dir=root_dir) - Factory.create_dependency("C", "1.0.0", root_dir=root_dir) - package_first = Factory.create_dependency("first", "1.0.0", root_dir=root_dir) - package_second = Factory.create_dependency("second", "1.0.0", root_dir=root_dir) - package_third = Factory.create_dependency("third", "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=fixture_base) + package_first = Factory.create_dependency("first", "1.0.0", root_dir=fixture_base) + package_second = Factory.create_dependency("second", "1.0.0", root_dir=fixture_base) + package_third = Factory.create_dependency("third", "1.0.0", root_dir=fixture_base) package_a.extras = { "C": [package_third, package_second, package_first], diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index a3fcc4249d1..fb2ce6c94f7 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -21,8 +20,7 @@ from pytest_mock import MockerFixture from tests.conftest import Config - -CWD = Path(__file__).parent.parent / "fixtures" / "simple_project" + from tests.types import FixtureDirGetter class ManagerFactory(Protocol): @@ -46,13 +44,14 @@ def activate(self, poetry: Poetry, io: BufferedIO) -> None: poetry.package.version = "9.9.9" -@pytest.fixture() -def poetry(tmp_path: Path, config: Config) -> Poetry: +@pytest.fixture +def poetry(fixture_dir: FixtureDirGetter, config: Config) -> Poetry: + project_path = fixture_dir("simple_project") poetry = Poetry( - CWD / "pyproject.toml", + project_path / "pyproject.toml", {}, ProjectPackage("simple-project", "1.2.3"), - Locker(CWD / "poetry.lock", {}), + Locker(project_path / "poetry.lock", {}), config, ) @@ -82,7 +81,7 @@ def test_load_plugins_and_activate( poetry: Poetry, io: BufferedIO, with_my_plugin: None, -): +) -> None: manager = manager_factory() manager.load_plugins() manager.activate(poetry, io) @@ -106,7 +105,7 @@ def test_load_plugins_with_invalid_plugin( poetry: Poetry, io: BufferedIO, with_invalid_plugin: None, -): +) -> None: manager = manager_factory() with pytest.raises(ValueError): @@ -118,7 +117,7 @@ def test_load_plugins_with_plugins_disabled( poetry: Poetry, io: BufferedIO, with_my_plugin: None, -): +) -> None: no_plugin_manager.load_plugins() assert poetry.package.version.text == "1.2.3" diff --git a/tests/puzzle/test_provider.py b/tests/puzzle/test_provider.py index 9554a1fdae9..560ae872f05 100644 --- a/tests/puzzle/test_provider.py +++ b/tests/puzzle/test_provider.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from subprocess import CalledProcessError from typing import TYPE_CHECKING @@ -29,6 +28,8 @@ if TYPE_CHECKING: from pytest_mock import MockerFixture + from tests.types import FixtureDirGetter + SOME_URL = "https://example.com/path.tar.gz" @@ -157,7 +158,7 @@ def test_search_for_direct_origin_and_extras( @pytest.mark.parametrize("value", [True, False]) -def test_search_for_vcs_retains_develop_flag(provider: Provider, value: bool): +def test_search_for_vcs_retains_develop_flag(provider: Provider, value: bool) -> None: dependency = VCSDependency( "demo", "git", "https://github.com/demo/demo.git", develop=value ) @@ -165,7 +166,7 @@ def test_search_for_vcs_retains_develop_flag(provider: Provider, value: bool): assert package.develop == value -def test_search_for_vcs_setup_egg_info(provider: Provider): +def test_search_for_vcs_setup_egg_info(provider: Provider) -> None: dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") package = provider.search_for_direct_origin_dependency(dependency) @@ -183,7 +184,7 @@ def test_search_for_vcs_setup_egg_info(provider: Provider): } -def test_search_for_vcs_setup_egg_info_with_extras(provider: Provider): +def test_search_for_vcs_setup_egg_info_with_extras(provider: Provider) -> None: dependency = VCSDependency( "demo", "git", "https://github.com/demo/demo.git", extras=["foo"] ) @@ -203,7 +204,7 @@ def test_search_for_vcs_setup_egg_info_with_extras(provider: Provider): } -def test_search_for_vcs_read_setup(provider: Provider, mocker: MockerFixture): +def test_search_for_vcs_read_setup(provider: Provider, mocker: MockerFixture) -> None: mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = VCSDependency("demo", "git", "https://github.com/demo/demo.git") @@ -225,7 +226,7 @@ def test_search_for_vcs_read_setup(provider: Provider, mocker: MockerFixture): def test_search_for_vcs_read_setup_with_extras( provider: Provider, mocker: MockerFixture -): +) -> None: mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = VCSDependency( @@ -245,7 +246,7 @@ def test_search_for_vcs_read_setup_with_extras( def test_search_for_vcs_read_setup_raises_error_if_no_version( provider: Provider, mocker: MockerFixture -): +) -> None: mocker.patch( "poetry.inspection.info.get_pep517_metadata", return_value=PackageInfo(name="demo", version=None), @@ -258,15 +259,12 @@ def test_search_for_vcs_read_setup_raises_error_if_no_version( @pytest.mark.parametrize("directory", ["demo", "non-canonical-name"]) -def test_search_for_directory_setup_egg_info(provider: Provider, directory: str): +def test_search_for_directory_setup_egg_info( + provider: Provider, directory: str, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / directory, + fixture_dir("git") / "github.com" / "demo" / directory, ) package = provider.search_for_direct_origin_dependency(dependency) @@ -284,15 +282,12 @@ def test_search_for_directory_setup_egg_info(provider: Provider, directory: str) } -def test_search_for_directory_setup_egg_info_with_extras(provider: Provider): +def test_search_for_directory_setup_egg_info_with_extras( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo", + fixture_dir("git") / "github.com" / "demo" / "demo", extras=["foo"], ) @@ -312,21 +307,13 @@ def test_search_for_directory_setup_egg_info_with_extras(provider: Provider): @pytest.mark.parametrize("directory", ["demo", "non-canonical-name"]) -def test_search_for_directory_setup_with_base(provider: Provider, directory: str): +def test_search_for_directory_setup_with_base( + provider: Provider, directory: str, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / directory, - base=Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / directory, + fixture_dir("git") / "github.com" / "demo" / directory, + base=fixture_dir("git") / "github.com" / "demo" / directory, ) package = provider.search_for_direct_origin_dependency(dependency) @@ -342,29 +329,17 @@ def test_search_for_directory_setup_with_base(provider: Provider, directory: str "foo": [get_dependency("cleo")], "bar": [get_dependency("tomlkit")], } - assert package.root_dir == ( - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / directory - ) + assert package.root_dir == (fixture_dir("git") / "github.com" / "demo" / directory) def test_search_for_directory_setup_read_setup( - provider: Provider, mocker: MockerFixture -): + provider: Provider, mocker: MockerFixture, fixture_dir: FixtureDirGetter +) -> None: mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo", + fixture_dir("git") / "github.com" / "demo" / "demo", ) package = provider.search_for_direct_origin_dependency(dependency) @@ -383,18 +358,13 @@ def test_search_for_directory_setup_read_setup( def test_search_for_directory_setup_read_setup_with_extras( - provider: Provider, mocker: MockerFixture -): + provider: Provider, mocker: MockerFixture, fixture_dir: FixtureDirGetter +) -> None: mocker.patch("poetry.utils.env.EnvManager.get", return_value=MockEnv()) dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo", + fixture_dir("git") / "github.com" / "demo" / "demo", extras=["foo"], ) @@ -413,15 +383,12 @@ def test_search_for_directory_setup_read_setup_with_extras( } -def test_search_for_directory_setup_read_setup_with_no_dependencies(provider: Provider): +def test_search_for_directory_setup_read_setup_with_no_dependencies( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "no-dependencies", + fixture_dir("git") / "github.com" / "demo" / "no-dependencies", ) package = provider.search_for_direct_origin_dependency(dependency) @@ -432,10 +399,12 @@ def test_search_for_directory_setup_read_setup_with_no_dependencies(provider: Pr assert package.extras == {} -def test_search_for_directory_poetry(provider: Provider): +def test_search_for_directory_poetry( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "project-with-extras", - Path(__file__).parent.parent / "fixtures" / "project_with_extras", + fixture_dir("project_with_extras"), ) package = provider.search_for_direct_origin_dependency(dependency) @@ -460,10 +429,12 @@ def test_search_for_directory_poetry(provider: Provider): } -def test_search_for_directory_poetry_with_extras(provider: Provider): +def test_search_for_directory_poetry_with_extras( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = DirectoryDependency( "project-with-extras", - Path(__file__).parent.parent / "fixtures" / "project_with_extras", + fixture_dir("project_with_extras"), extras=["extras_a"], ) @@ -489,13 +460,12 @@ def test_search_for_directory_poetry_with_extras(provider: Provider): } -def test_search_for_file_sdist(provider: Provider): +def test_search_for_file_sdist( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = FileDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0.tar.gz", + fixture_dir("distributions") / "demo-0.1.0.tar.gz", ) package = provider.search_for_direct_origin_dependency(dependency) @@ -520,13 +490,12 @@ def test_search_for_file_sdist(provider: Provider): } -def test_search_for_file_sdist_with_extras(provider: Provider): +def test_search_for_file_sdist_with_extras( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = FileDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0.tar.gz", + fixture_dir("distributions") / "demo-0.1.0.tar.gz", extras=["foo"], ) @@ -552,13 +521,12 @@ def test_search_for_file_sdist_with_extras(provider: Provider): } -def test_search_for_file_wheel(provider: Provider): +def test_search_for_file_wheel( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = FileDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl", + fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl", ) package = provider.search_for_direct_origin_dependency(dependency) @@ -583,13 +551,12 @@ def test_search_for_file_wheel(provider: Provider): } -def test_search_for_file_wheel_with_extras(provider: Provider): +def test_search_for_file_wheel_with_extras( + provider: Provider, fixture_dir: FixtureDirGetter +) -> None: dependency = FileDependency( "demo", - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl", + fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl", extras=["foo"], ) @@ -639,10 +606,9 @@ def test_complete_package_does_not_merge_different_source_names( def test_complete_package_preserves_source_type( - provider: Provider, root: ProjectPackage + provider: Provider, root: ProjectPackage, fixture_dir: FixtureDirGetter ) -> None: - fixtures = Path(__file__).parent.parent / "fixtures" - project_dir = fixtures.joinpath("with_conditional_path_deps") + project_dir = fixture_dir("with_conditional_path_deps") for folder in ["demo_one", "demo_two"]: path = (project_dir / folder).as_posix() root.add_dependency(Factory.create_dependency("demo", {"path": path})) @@ -737,7 +703,7 @@ def test_complete_package_with_extras_preserves_source_name( @pytest.mark.parametrize("with_extra", [False, True]) def test_complete_package_fetches_optional_vcs_dependency_only_if_requested( provider: Provider, repository: Repository, mocker: MockerFixture, with_extra: bool -): +) -> None: optional_vcs_dependency = Factory.create_dependency( "demo", {"git": "https://github.com/demo/demo.git", "optional": True} ) diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index 080fa975c63..10e67c9ab6e 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -2,7 +2,6 @@ import re -from pathlib import Path from typing import TYPE_CHECKING from typing import Any @@ -43,6 +42,7 @@ from poetry.installation.operations.operation import Operation from poetry.puzzle.provider import Provider from poetry.puzzle.transaction import Transaction + from tests.types import FixtureDirGetter DEFAULT_SOURCE_REF = ( VCSDependency("poetry", "git", "git@github.com:python-poetry/poetry.git").branch @@ -115,7 +115,7 @@ def check_solver_result( def test_solver_install_single( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -128,7 +128,7 @@ def test_solver_install_single( def test_solver_remove_if_no_longer_locked( package: ProjectPackage, pool: RepositoryPool, io: NullIO -): +) -> None: package_a = get_package("A", "1.0") solver = Solver(package, pool, [package_a], [package_a], io) @@ -139,7 +139,7 @@ def test_solver_remove_if_no_longer_locked( def test_remove_non_installed( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package_a = get_package("A", "1.0") repo.add_package(package_a) @@ -151,7 +151,7 @@ def test_remove_non_installed( def test_install_non_existing_package_fail( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("B", "1")) package_a = get_package("A", "1.0") @@ -163,7 +163,7 @@ def test_install_non_existing_package_fail( def test_install_unpublished_package_does_not_fail( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency(Factory.create_dependency("B", "1")) package_a = get_package("A", "1.0") @@ -188,7 +188,9 @@ def test_install_unpublished_package_does_not_fail( ) -def test_solver_with_deps(solver: Solver, repo: Repository, package: ProjectPackage): +def test_solver_with_deps( + solver: Solver, repo: Repository, package: ProjectPackage +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -214,7 +216,7 @@ def test_solver_with_deps(solver: Solver, repo: Repository, package: ProjectPack def test_install_honours_not_equal( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -244,7 +246,7 @@ def test_install_honours_not_equal( def test_install_with_deps_in_order( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) package.add_dependency(Factory.create_dependency("C", "*")) @@ -275,7 +277,7 @@ def test_install_with_deps_in_order( def test_install_installed( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -291,7 +293,7 @@ def test_install_installed( def test_update_installed( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -309,7 +311,7 @@ def test_update_installed( def test_update_with_use_latest( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) @@ -337,7 +339,9 @@ def test_update_with_use_latest( ) -def test_solver_sets_groups(solver: Solver, repo: Repository, package: ProjectPackage): +def test_solver_sets_groups( + solver: Solver, repo: Repository, package: ProjectPackage +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*", groups=["dev"])) @@ -368,7 +372,7 @@ def test_solver_sets_groups(solver: Solver, repo: Repository, package: ProjectPa def test_solver_respects_root_package_python_versions( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~3.4") package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) @@ -401,7 +405,7 @@ def test_solver_respects_root_package_python_versions( def test_solver_fails_if_mismatch_root_python_versions( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "^3.4") package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) @@ -423,7 +427,7 @@ def test_solver_fails_if_mismatch_root_python_versions( def test_solver_ignores_python_restricted_if_mismatch_root_package_python_versions( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~3.8") package.add_dependency( Factory.create_dependency("A", {"version": "1.0", "python": "<3.8"}) @@ -447,7 +451,7 @@ def test_solver_ignores_python_restricted_if_mismatch_root_package_python_versio def test_solver_solves_optional_and_compatible_packages( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~3.4") package.extras["foo"] = [get_dependency("B")] package.add_dependency( @@ -482,7 +486,7 @@ def test_solver_solves_optional_and_compatible_packages( def test_solver_does_not_return_extras_if_not_requested( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) @@ -509,7 +513,7 @@ def test_solver_does_not_return_extras_if_not_requested( def test_solver_returns_extras_if_requested( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency( Factory.create_dependency("B", {"version": "*", "extras": ["foo"]}) @@ -549,7 +553,7 @@ def test_solver_returns_extras_only_requested( repo: Repository, package: ProjectPackage, enabled_extra: bool | None, -): +) -> None: extras = [enabled_extra] if enabled_extra is not None else [] package.add_dependency(Factory.create_dependency("A", "*")) @@ -611,7 +615,7 @@ def test_solver_returns_extras_when_multiple_extras_use_same_dependency( repo: Repository, package: ProjectPackage, enabled_extra: bool | None, -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -660,7 +664,7 @@ def test_solver_returns_extras_only_requested_nested( repo: Repository, package: ProjectPackage, enabled_extra: bool | None, -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -715,7 +719,7 @@ def test_solver_returns_extras_only_requested_nested( def test_solver_finds_extras_next_to_non_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: # Root depends on A[foo] package.add_dependency( Factory.create_dependency("A", {"version": "*", "extras": ["foo"]}) @@ -762,7 +766,7 @@ def test_solver_finds_extras_next_to_non_extras( def test_solver_merge_extras_into_base_package_multiple_repos_fixes_5727( solver: Solver, repo: Repository, pool: RepositoryPool, package: ProjectPackage -): +) -> None: package.add_dependency( Factory.create_dependency("A", {"version": "*", "source": "legacy"}) ) @@ -794,7 +798,7 @@ def test_solver_merge_extras_into_base_package_multiple_repos_fixes_5727( def test_solver_returns_extras_if_excluded_by_markers_without_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency( Factory.create_dependency("A", {"version": "*", "extras": ["foo"]}) ) @@ -833,7 +837,7 @@ def test_solver_returns_extras_if_excluded_by_markers_without_extras( def test_solver_returns_prereleases_if_requested( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) package.add_dependency( @@ -864,7 +868,7 @@ def test_solver_returns_prereleases_if_requested( def test_solver_does_not_return_prereleases_if_not_requested( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) package.add_dependency(Factory.create_dependency("C", "*")) @@ -893,7 +897,7 @@ def test_solver_does_not_return_prereleases_if_not_requested( def test_solver_sub_dependencies_with_requirements( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) @@ -931,7 +935,7 @@ def test_solver_sub_dependencies_with_requirements( def test_solver_sub_dependencies_with_requirements_complex( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "<5.0"}) ) @@ -990,7 +994,7 @@ def test_solver_sub_dependencies_with_requirements_complex( def test_solver_sub_dependencies_with_not_supported_python_version( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "^3.5") package.add_dependency(Factory.create_dependency("A", "*")) @@ -1012,7 +1016,7 @@ def test_solver_sub_dependencies_with_not_supported_python_version( def test_solver_sub_dependencies_with_not_supported_python_version_transitive( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "^3.4") package.add_dependency( @@ -1056,7 +1060,7 @@ def test_solver_sub_dependencies_with_not_supported_python_version_transitive( def test_solver_with_dependency_in_both_main_and_dev_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "^3.5") package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency( @@ -1109,7 +1113,7 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies( def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_dependent( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("E", "*")) package.add_dependency( @@ -1169,7 +1173,7 @@ def test_solver_with_dependency_in_both_main_and_dev_dependencies_with_one_more_ def test_solver_with_dependency_and_prerelease_sub_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1196,7 +1200,7 @@ def test_solver_with_dependency_and_prerelease_sub_dependencies( def test_solver_circular_dependency( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1228,7 +1232,7 @@ def test_solver_circular_dependency( def test_solver_circular_dependency_chain( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1265,7 +1269,7 @@ def test_solver_circular_dependency_chain( def test_solver_dense_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: # The root package depends on packages A0...An-1, # And package Ai depends on packages A0...Ai-1 # This graph is a transitive tournament @@ -1288,7 +1292,7 @@ def test_solver_dense_dependencies( def test_solver_duplicate_dependencies_same_constraint( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1317,7 +1321,7 @@ def test_solver_duplicate_dependencies_same_constraint( def test_solver_duplicate_dependencies_different_constraints( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1349,7 +1353,7 @@ def test_solver_duplicate_dependencies_different_constraints( def test_solver_duplicate_dependencies_different_constraints_same_requirements( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1376,7 +1380,7 @@ def test_solver_duplicate_dependencies_different_constraints_same_requirements( def test_solver_duplicate_dependencies_different_constraints_merge_by_marker( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1414,7 +1418,7 @@ def test_solver_duplicate_dependencies_different_constraints_merge_by_marker( @pytest.mark.parametrize("git_first", [False, True]) def test_solver_duplicate_dependencies_different_sources_types_are_preserved( solver: Solver, repo: Repository, package: ProjectPackage, git_first: bool -): +) -> None: pendulum = get_package("pendulum", "2.0.3") repo.add_package(pendulum) repo.add_package(get_package("cleo", "1.0.0")) @@ -1482,7 +1486,7 @@ def test_solver_duplicate_dependencies_different_sources_types_are_preserved( def test_solver_duplicate_dependencies_different_constraints_merge_no_markers( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "1.0")) @@ -1683,7 +1687,7 @@ def test_solver_duplicate_dependencies_different_constraints_discard_no_markers3 def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_intersection( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: """ Distinct requirements per marker: * Python 2.7: A (which requires B) and B @@ -1754,7 +1758,7 @@ def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_inters def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_intersection2( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: """ Empty intersection between top level dependency and transient dependency. """ @@ -1797,7 +1801,7 @@ def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_inters def test_solver_duplicate_dependencies_sub_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package_a = get_package("A", "1.0") @@ -1836,10 +1840,11 @@ def test_solver_duplicate_dependencies_sub_dependencies( ) -def test_duplicate_path_dependencies(solver: Solver, package: ProjectPackage) -> None: +def test_duplicate_path_dependencies( + solver: Solver, package: ProjectPackage, fixture_dir: FixtureDirGetter +) -> None: set_package_python_versions(solver.provider, "^3.7") - fixtures = Path(__file__).parent.parent / "fixtures" - project_dir = fixtures / "with_conditional_path_deps" + project_dir = fixture_dir("with_conditional_path_deps") path1 = (project_dir / "demo_one").as_posix() demo1 = Package("demo", "1.2.3", source_type="directory", source_url=path1) @@ -1869,11 +1874,10 @@ def test_duplicate_path_dependencies(solver: Solver, package: ProjectPackage) -> def test_duplicate_path_dependencies_same_path( - solver: Solver, package: ProjectPackage + solver: Solver, package: ProjectPackage, fixture_dir: FixtureDirGetter ) -> None: set_package_python_versions(solver.provider, "^3.7") - fixtures = Path(__file__).parent.parent / "fixtures" - project_dir = fixtures / "with_conditional_path_deps" + project_dir = fixture_dir("with_conditional_path_deps") path1 = (project_dir / "demo_one").as_posix() demo1 = Package("demo", "1.2.3", source_type="directory", source_url=path1) @@ -1895,7 +1899,7 @@ def test_duplicate_path_dependencies_same_path( def test_solver_fails_if_dependency_name_does_not_match_package( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency( Factory.create_dependency( "my-demo", {"git": "https://github.com/demo/demo.git"} @@ -1908,7 +1912,7 @@ def test_solver_fails_if_dependency_name_does_not_match_package( def test_solver_does_not_get_stuck_in_recursion_on_circular_dependency( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package_a = get_package("A", "1.0") package_a.add_dependency(Factory.create_dependency("B", "^1.0")) package_b = get_package("B", "1.0") @@ -1936,7 +1940,7 @@ def test_solver_does_not_get_stuck_in_recursion_on_circular_dependency( def test_solver_can_resolve_git_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -1971,7 +1975,7 @@ def test_solver_can_resolve_git_dependencies( def test_solver_can_resolve_git_dependencies_with_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -2011,7 +2015,7 @@ def test_solver_can_resolve_git_dependencies_with_extras( ) def test_solver_can_resolve_git_dependencies_with_ref( solver: Solver, repo: Repository, package: ProjectPackage, ref: dict[str, str] -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -2046,7 +2050,7 @@ def test_solver_can_resolve_git_dependencies_with_ref( def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requirement_is_compatible( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.4") package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"}) @@ -2064,7 +2068,7 @@ def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requir def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requirement_is_compatible_multiple( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.4") package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"}) @@ -2096,7 +2100,7 @@ def test_solver_does_not_trigger_conflict_for_python_constraint_if_python_requir def test_solver_triggers_conflict_for_dependency_python_not_fully_compatible_with_package_python( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.4") package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"}) @@ -2113,7 +2117,7 @@ def test_solver_triggers_conflict_for_dependency_python_not_fully_compatible_wit def test_solver_finds_compatible_package_for_dependency_python_not_fully_compatible_with_package_python( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.4") package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.5"}) @@ -2135,7 +2139,7 @@ def test_solver_finds_compatible_package_for_dependency_python_not_fully_compati def test_solver_does_not_trigger_new_resolution_on_duplicate_dependencies_if_only_extras( # noqa: E501 solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: dep1 = Dependency.create_from_pep_508('B (>=1.0); extra == "foo"') dep1.activate() dep2 = Dependency.create_from_pep_508('B (>=2.0); extra == "bar"') @@ -2173,7 +2177,7 @@ def test_solver_does_not_trigger_new_resolution_on_duplicate_dependencies_if_onl def test_solver_does_not_raise_conflict_for_locked_conditional_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.4") package.add_dependency( Factory.create_dependency("A", {"version": "^1.0", "python": "^3.6"}) @@ -2205,7 +2209,7 @@ def test_solver_does_not_raise_conflict_for_locked_conditional_dependencies( def test_solver_returns_extras_if_requested_in_dependencies_and_not_in_root_package( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "*")) package.add_dependency(Factory.create_dependency("B", "*")) package.add_dependency(Factory.create_dependency("C", "*")) @@ -2244,7 +2248,7 @@ def test_solver_returns_extras_if_requested_in_dependencies_and_not_in_root_pack def test_solver_should_not_resolve_prerelease_version_if_not_requested( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("A", "~1.8.0")) package.add_dependency(Factory.create_dependency("B", "^0.5.0")) @@ -2263,7 +2267,7 @@ def test_solver_should_not_resolve_prerelease_version_if_not_requested( def test_solver_ignores_dependencies_with_incompatible_python_full_version_marker( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "^3.6") package.add_dependency(Factory.create_dependency("A", "^1.0")) package.add_dependency(Factory.create_dependency("B", "^2.0")) @@ -2296,7 +2300,7 @@ def test_solver_ignores_dependencies_with_incompatible_python_full_version_marke def test_solver_git_dependencies_update( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -2345,7 +2349,7 @@ def test_solver_git_dependencies_update( def test_solver_git_dependencies_update_skipped( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -2378,7 +2382,7 @@ def test_solver_git_dependencies_update_skipped( def test_solver_git_dependencies_short_hash_update_skipped( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) @@ -2423,19 +2427,15 @@ def test_solver_git_dependencies_short_hash_update_skipped( def test_solver_can_resolve_directory_dependencies( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") repo.add_package(pendulum) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo" - ).as_posix() + path = (fixture_dir("git") / "github.com" / "demo" / "demo").as_posix() package.add_dependency(Factory.create_dependency("demo", {"path": path})) @@ -2460,8 +2460,9 @@ def test_solver_can_resolve_directory_dependencies_nested_editable( repo: Repository, pool: RepositoryPool, io: NullIO, -): - base = Path(__file__).parent.parent / "fixtures" / "project_with_nested_local" + fixture_dir: FixtureDirGetter, +) -> None: + base = fixture_dir("project_with_nested_local") poetry = Factory().create_poetry(cwd=base) package = poetry.package @@ -2511,21 +2512,17 @@ def test_solver_can_resolve_directory_dependencies_nested_editable( def test_solver_can_resolve_directory_dependencies_with_extras( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) repo.add_package(cleo) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo" - ).as_posix() + path = (fixture_dir("git") / "github.com" / "demo" / "demo").as_posix() package.add_dependency( Factory.create_dependency("demo", {"path": path, "extras": ["foo"]}) @@ -2553,17 +2550,15 @@ def test_solver_can_resolve_directory_dependencies_with_extras( def test_solver_can_resolve_sdist_dependencies( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") repo.add_package(pendulum) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0.tar.gz" - ).as_posix() + path = (fixture_dir("distributions") / "demo-0.1.0.tar.gz").as_posix() package.add_dependency(Factory.create_dependency("demo", {"path": path})) @@ -2585,19 +2580,17 @@ def test_solver_can_resolve_sdist_dependencies( def test_solver_can_resolve_sdist_dependencies_with_extras( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) repo.add_package(cleo) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0.tar.gz" - ).as_posix() + path = (fixture_dir("distributions") / "demo-0.1.0.tar.gz").as_posix() package.add_dependency( Factory.create_dependency("demo", {"path": path, "extras": ["foo"]}) @@ -2625,17 +2618,15 @@ def test_solver_can_resolve_sdist_dependencies_with_extras( def test_solver_can_resolve_wheel_dependencies( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") repo.add_package(pendulum) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl" - ).as_posix() + path = (fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl").as_posix() package.add_dependency(Factory.create_dependency("demo", {"path": path})) @@ -2657,19 +2648,17 @@ def test_solver_can_resolve_wheel_dependencies( def test_solver_can_resolve_wheel_dependencies_with_extras( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") cleo = get_package("cleo", "1.0.0") repo.add_package(pendulum) repo.add_package(cleo) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl" - ).as_posix() + path = (fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl").as_posix() package.add_dependency( Factory.create_dependency("demo", {"path": path, "extras": ["foo"]}) @@ -2698,7 +2687,7 @@ def test_solver_can_resolve_wheel_dependencies_with_extras( def test_solver_can_solve_with_legacy_repository_using_proper_dists( package: ProjectPackage, io: NullIO -): +) -> None: repo = MockLegacyRepository() pool = RepositoryPool([repo]) @@ -2741,7 +2730,7 @@ def test_solver_can_solve_with_legacy_repository_using_proper_dists( def test_solver_can_solve_with_legacy_repository_using_proper_python_compatible_dists( package: ProjectPackage, io: NullIO, -): +) -> None: package.python_versions = "^3.7" repo = MockLegacyRepository() @@ -2770,7 +2759,7 @@ def test_solver_can_solve_with_legacy_repository_using_proper_python_compatible_ ) -def test_solver_skips_invalid_versions(package: ProjectPackage, io: NullIO): +def test_solver_skips_invalid_versions(package: ProjectPackage, io: NullIO) -> None: package.python_versions = "^3.7" repo = MockPyPIRepository() @@ -2789,7 +2778,7 @@ def test_solver_skips_invalid_versions(package: ProjectPackage, io: NullIO): def test_multiple_constraints_on_root( package: ProjectPackage, solver: Solver, repo: Repository -): +) -> None: package.add_dependency( Factory.create_dependency("foo", {"version": "^1.0", "python": "^2.7"}) ) @@ -2813,7 +2802,7 @@ def test_multiple_constraints_on_root( def test_solver_chooses_most_recent_version_amongst_repositories( package: ProjectPackage, io: NullIO -): +) -> None: package.python_versions = "^3.7" package.add_dependency(Factory.create_dependency("tomlkit", {"version": "^0.5"})) @@ -2834,7 +2823,7 @@ def test_solver_chooses_most_recent_version_amongst_repositories( def test_solver_chooses_from_correct_repository_if_forced( package: ProjectPackage, io: NullIO -): +) -> None: package.python_versions = "^3.7" package.add_dependency( Factory.create_dependency("tomlkit", {"version": "^0.5", "source": "legacy"}) @@ -2869,7 +2858,7 @@ def test_solver_chooses_from_correct_repository_if_forced( def test_solver_chooses_from_correct_repository_if_forced_and_transitive_dependency( package: ProjectPackage, io: NullIO, -): +) -> None: package.python_versions = "^3.7" package.add_dependency(Factory.create_dependency("foo", "^1.0")) package.add_dependency( @@ -2911,7 +2900,7 @@ def test_solver_chooses_from_correct_repository_if_forced_and_transitive_depende def test_solver_does_not_choose_from_secondary_repository_by_default( package: ProjectPackage, io: NullIO -): +) -> None: package.python_versions = "^3.7" package.add_dependency(Factory.create_dependency("clikit", {"version": "^0.2.0"})) @@ -2959,7 +2948,7 @@ def test_solver_does_not_choose_from_secondary_repository_by_default( def test_solver_chooses_from_secondary_if_explicit( package: ProjectPackage, io: NullIO, -): +) -> None: package.python_versions = "^3.7" package.add_dependency( Factory.create_dependency("clikit", {"version": "^0.2.0", "source": "PyPI"}) @@ -3068,7 +3057,7 @@ def test_solver_discards_packages_with_empty_markers( repo: Repository, pool: RepositoryPool, io: NullIO, -): +) -> None: package.python_versions = "~2.7 || ^3.4" package.add_dependency( Factory.create_dependency( @@ -3104,7 +3093,7 @@ def test_solver_discards_packages_with_empty_markers( def test_solver_does_not_raise_conflict_for_conditional_dev_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.5") package.add_dependency( Factory.create_dependency( @@ -3136,7 +3125,7 @@ def test_solver_does_not_raise_conflict_for_conditional_dev_dependencies( def test_solver_does_not_loop_indefinitely_on_duplicate_constraints_with_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.5") package.add_dependency( Factory.create_dependency( @@ -3170,7 +3159,7 @@ def test_solver_does_not_fail_with_locked_git_and_non_git_dependencies( repo: Repository, pool: RepositoryPool, io: NullIO, -): +) -> None: package.add_dependency( Factory.create_dependency("demo", {"git": "https://github.com/demo/demo.git"}) ) @@ -3205,7 +3194,7 @@ def test_solver_does_not_fail_with_locked_git_and_non_git_dependencies( def test_ignore_python_constraint_no_overlap_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: pytest = get_package("demo", "1.0.0") pytest.add_dependency( Factory.create_dependency( @@ -3230,7 +3219,7 @@ def test_ignore_python_constraint_no_overlap_dependencies( def test_solver_should_not_go_into_an_infinite_loop_on_duplicate_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: set_package_python_versions(solver.provider, "~2.7 || ^3.5") package.add_dependency(Factory.create_dependency("A", "^1.0")) @@ -3263,7 +3252,7 @@ def test_solver_should_not_go_into_an_infinite_loop_on_duplicate_dependencies( def test_solver_synchronize_single( package: ProjectPackage, pool: RepositoryPool, io: NullIO -): +) -> None: package_a = get_package("a", "1.0") solver = Solver(package, pool, [package_a], [], io) @@ -3279,7 +3268,7 @@ def test_solver_with_synchronization_keeps_critical_package( package: ProjectPackage, pool: RepositoryPool, io: NullIO, -): +) -> None: package_pip = get_package("setuptools", "1.0") solver = Solver(package, pool, [package_pip], [], io) @@ -3289,8 +3278,11 @@ def test_solver_with_synchronization_keeps_critical_package( def test_solver_cannot_choose_another_version_for_directory_dependencies( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") demo = get_package("demo", "0.1.0") foo = get_package("foo", "1.2.3") @@ -3299,14 +3291,7 @@ def test_solver_cannot_choose_another_version_for_directory_dependencies( repo.add_package(demo) repo.add_package(pendulum) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo" - ).as_posix() + path = (fixture_dir("git") / "github.com" / "demo" / "demo").as_posix() package.add_dependency(Factory.create_dependency("demo", {"path": path})) package.add_dependency(Factory.create_dependency("foo", "^1.2.3")) @@ -3318,8 +3303,11 @@ def test_solver_cannot_choose_another_version_for_directory_dependencies( def test_solver_cannot_choose_another_version_for_file_dependencies( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: pendulum = get_package("pendulum", "2.0.3") demo = get_package("demo", "0.0.8") foo = get_package("foo", "1.2.3") @@ -3328,12 +3316,7 @@ def test_solver_cannot_choose_another_version_for_file_dependencies( repo.add_package(demo) repo.add_package(pendulum) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl" - ).as_posix() + path = (fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl").as_posix() package.add_dependency(Factory.create_dependency("demo", {"path": path})) package.add_dependency(Factory.create_dependency("foo", "^1.2.3")) @@ -3346,7 +3329,7 @@ def test_solver_cannot_choose_another_version_for_file_dependencies( def test_solver_cannot_choose_another_version_for_git_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: pendulum = get_package("pendulum", "2.0.3") demo = get_package("demo", "0.0.8") foo = get_package("foo", "1.2.3") @@ -3371,13 +3354,9 @@ def test_solver_cannot_choose_another_version_for_url_dependencies( repo: Repository, package: ProjectPackage, http: type[httpretty.httpretty], -): - path = ( - Path(__file__).parent.parent - / "fixtures" - / "distributions" - / "demo-0.1.0-py2.py3-none-any.whl" - ) + fixture_dir: FixtureDirGetter, +) -> None: + path = fixture_dir("distributions") / "demo-0.1.0-py2.py3-none-any.whl" http.register_uri( "GET", @@ -3409,7 +3388,7 @@ def test_solver_cannot_choose_another_version_for_url_dependencies( def test_solver_should_not_update_same_version_packages_if_installed_has_no_source_type( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency(Factory.create_dependency("foo", "1.0.0")) foo = Package( @@ -3458,7 +3437,7 @@ def test_solver_should_use_the_python_constraint_from_the_environment_if_availab def test_solver_should_resolve_all_versions_for_multiple_duplicate_dependencies( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.python_versions = "~2.7 || ^3.5" package.add_dependency( Factory.create_dependency( @@ -3506,7 +3485,7 @@ def test_solver_should_resolve_all_versions_for_multiple_duplicate_dependencies( def test_solver_should_not_raise_errors_for_irrelevant_python_constraints( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.python_versions = "^3.6" set_package_python_versions(solver.provider, "^3.6") package.add_dependency( @@ -3524,7 +3503,7 @@ def test_solver_should_not_raise_errors_for_irrelevant_python_constraints( def test_solver_can_resolve_transitive_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency(Factory.create_dependency("requests", "^2.24.0")) package.add_dependency(Factory.create_dependency("PyOTA", "^2.1.0")) @@ -3562,7 +3541,7 @@ def test_solver_can_resolve_transitive_extras( def test_solver_can_resolve_for_packages_with_missing_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.add_dependency( Factory.create_dependency( "django-anymail", {"version": "^6.0", "extras": ["postmark"]} @@ -3599,7 +3578,7 @@ def test_solver_can_resolve_for_packages_with_missing_extras( def test_solver_can_resolve_python_restricted_package_dependencies( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: package.add_dependency( Factory.create_dependency("futures", {"version": "^3.3.0", "python": "~2.7"}) ) @@ -3630,7 +3609,7 @@ def test_solver_can_resolve_python_restricted_package_dependencies( def test_solver_should_not_raise_errors_for_irrelevant_transitive_python_constraints( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: package.python_versions = "~2.7 || ^3.5" set_package_python_versions(solver.provider, "~2.7 || ^3.5") package.add_dependency(Factory.create_dependency("virtualenv", "^20.4.3")) @@ -3685,7 +3664,7 @@ def test_solver_keeps_multiple_locked_dependencies_for_same_package( pool: RepositoryPool, io: NullIO, is_locked: bool, -): +) -> None: package.add_dependency( Factory.create_dependency("A", {"version": "~1.1", "python": "<3.7"}) ) @@ -3739,7 +3718,7 @@ def test_solver_does_not_update_ref_of_locked_vcs_package( pool: RepositoryPool, io: NullIO, is_locked: bool, -): +) -> None: locked_ref = "123456" latest_ref = "9cf87a285a2d3fbb0b9fa621997b3acc3631ed24" demo_locked = Package( @@ -3795,7 +3774,7 @@ def test_solver_does_not_fetch_locked_vcs_package_with_ref( pool: RepositoryPool, io: NullIO, mocker: MockerFixture, -): +) -> None: locked_ref = "123456" demo_locked = Package( "demo", @@ -3824,8 +3803,11 @@ def test_solver_does_not_fetch_locked_vcs_package_with_ref( def test_solver_direct_origin_dependency_with_extras_requested_by_other_package( - solver: Solver, repo: Repository, package: ProjectPackage -): + solver: Solver, + repo: Repository, + package: ProjectPackage, + fixture_dir: FixtureDirGetter, +) -> None: """ Another package requires the same dependency with extras that is required by the project as direct origin dependency without any extras. @@ -3840,14 +3822,7 @@ def test_solver_direct_origin_dependency_with_extras_requested_by_other_package( repo.add_package(pendulum) repo.add_package(cleo) - path = ( - Path(__file__).parent.parent - / "fixtures" - / "git" - / "github.com" - / "demo" - / "demo" - ).as_posix() + path = (fixture_dir("git") / "github.com" / "demo" / "demo").as_posix() # project requires path dependency of demo while demo-foo requires demo[foo] package.add_dependency(Factory.create_dependency("demo", {"path": path})) @@ -3877,7 +3852,7 @@ def test_solver_direct_origin_dependency_with_extras_requested_by_other_package( def test_solver_incompatible_dependency_with_and_without_extras( solver: Solver, repo: Repository, package: ProjectPackage -): +) -> None: """ The solver first encounters a requirement for google-auth and then later an incompatible requirement for google-auth[aiohttp]. @@ -3929,7 +3904,7 @@ def test_solver_incompatible_dependency_with_and_without_extras( def test_update_with_prerelease_and_no_solution( package: ProjectPackage, repo: Repository, pool: RepositoryPool, io: NullIO -): +) -> None: # Locked and installed: cleo which depends on an old version of crashtest. cleo = get_package("cleo", "1.0.0a5") crashtest = get_package("crashtest", "0.3.0") @@ -4001,7 +3976,7 @@ def test_update_with_use_latest_vs_lock( pool: RepositoryPool, io: NullIO, is_locked: bool, -): +) -> None: """ A1 depends on B2, A2 and A3 depend on B1. Same for C. B1 depends on A2/C2, B2 depends on A1/C1. diff --git a/tests/test_factory.py b/tests/test_factory.py index 2ba1104e768..d3a39620e86 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -26,8 +25,6 @@ from poetry.poetry import Poetry from tests.types import FixtureDirGetter -fixtures_dir = Path(__file__).parent / "fixtures" - class MyPlugin(Plugin): def activate(self, poetry: Poetry, io: IO) -> None: @@ -35,8 +32,8 @@ def activate(self, poetry: Poetry, io: IO) -> None: poetry.package.readmes = ("README.md",) -def test_create_poetry(): - poetry = Factory().create_poetry(fixtures_dir / "sample_project") +def test_create_poetry(fixture_dir: FixtureDirGetter) -> None: + poetry = Factory().create_poetry(fixture_dir("sample_project")) package = poetry.package @@ -48,7 +45,7 @@ def test_create_poetry(): for readme in package.readmes: assert ( - readme.relative_to(fixtures_dir).as_posix() == "sample_project/README.rst" + readme.relative_to(fixture_dir("sample_project")).as_posix() == "README.rst" ) assert package.homepage == "https://python-poetry.org" @@ -147,8 +144,10 @@ def test_create_poetry(): ("project_with_extras",), ], ) -def test_create_pyproject_from_package(project: str): - poetry = Factory().create_poetry(fixtures_dir / project) +def test_create_pyproject_from_package( + project: str, fixture_dir: FixtureDirGetter +) -> None: + poetry = Factory().create_poetry(fixture_dir(project)) package = poetry.package pyproject = Factory.create_pyproject_from_package(package) @@ -177,8 +176,10 @@ def test_create_pyproject_from_package(project: str): assert not DeepDiff(expected, result) -def test_create_poetry_with_packages_and_includes(): - poetry = Factory().create_poetry(fixtures_dir / "with-include") +def test_create_poetry_with_packages_and_includes( + fixture_dir: FixtureDirGetter, +) -> None: + poetry = Factory().create_poetry(fixture_dir("with-include")) package = poetry.package @@ -198,9 +199,11 @@ def test_create_poetry_with_packages_and_includes(): ] -def test_create_poetry_with_multi_constraints_dependency(): +def test_create_poetry_with_multi_constraints_dependency( + fixture_dir: FixtureDirGetter, +) -> None: poetry = Factory().create_poetry( - fixtures_dir / "project_with_multi_constraints_dependency" + fixture_dir("project_with_multi_constraints_dependency") ) package = poetry.package @@ -208,30 +211,34 @@ def test_create_poetry_with_multi_constraints_dependency(): assert len(package.requires) == 2 -def test_poetry_with_default_source_legacy(with_simple_keyring: None): +def test_poetry_with_default_source_legacy( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: io = BufferedIO() - poetry = Factory().create_poetry(fixtures_dir / "with_default_source_legacy", io=io) + poetry = Factory().create_poetry(fixture_dir("with_default_source_legacy"), io=io) assert len(poetry.pool.repositories) == 1 assert "Found deprecated key" in io.fetch_error() -def test_poetry_with_default_source(with_simple_keyring: None): +def test_poetry_with_default_source( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: io = BufferedIO() - poetry = Factory().create_poetry(fixtures_dir / "with_default_source", io=io) + poetry = Factory().create_poetry(fixture_dir("with_default_source"), io=io) assert len(poetry.pool.repositories) == 1 assert io.fetch_error() == "" @pytest.mark.parametrize( - "fixture_filename", + "project", ("with_non_default_source_implicit", "with_non_default_source_explicit"), ) def test_poetry_with_non_default_source( - fixture_filename: str, with_simple_keyring: None -): - poetry = Factory().create_poetry(fixtures_dir / fixture_filename) + project: str, fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: + poetry = Factory().create_poetry(fixture_dir(project)) assert not poetry.pool.has_default() assert poetry.pool.has_repository("PyPI") @@ -243,9 +250,11 @@ def test_poetry_with_non_default_source( assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo"} -def test_poetry_with_non_default_secondary_source_legacy(with_simple_keyring: None): +def test_poetry_with_non_default_secondary_source_legacy( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: poetry = Factory().create_poetry( - fixtures_dir / "with_non_default_secondary_source_legacy" + fixture_dir("with_non_default_secondary_source_legacy") ) assert poetry.pool.has_repository("PyPI") @@ -256,8 +265,10 @@ def test_poetry_with_non_default_secondary_source_legacy(with_simple_keyring: No assert [repo.name for repo in poetry.pool.repositories] == ["PyPI", "foo"] -def test_poetry_with_non_default_secondary_source(with_simple_keyring: None): - poetry = Factory().create_poetry(fixtures_dir / "with_non_default_secondary_source") +def test_poetry_with_non_default_secondary_source( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: + poetry = Factory().create_poetry(fixture_dir("with_non_default_secondary_source")) assert poetry.pool.has_repository("PyPI") assert isinstance(poetry.pool.repository("PyPI"), PyPiRepository) @@ -268,10 +279,11 @@ def test_poetry_with_non_default_secondary_source(with_simple_keyring: None): def test_poetry_with_non_default_multiple_secondary_sources_legacy( + fixture_dir: FixtureDirGetter, with_simple_keyring: None, -): +) -> None: poetry = Factory().create_poetry( - fixtures_dir / "with_non_default_multiple_secondary_sources_legacy" + fixture_dir("with_non_default_multiple_secondary_sources_legacy") ) assert poetry.pool.has_repository("PyPI") @@ -284,9 +296,11 @@ def test_poetry_with_non_default_multiple_secondary_sources_legacy( assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo", "bar"} -def test_poetry_with_non_default_multiple_secondary_sources(with_simple_keyring: None): +def test_poetry_with_non_default_multiple_secondary_sources( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: poetry = Factory().create_poetry( - fixtures_dir / "with_non_default_multiple_secondary_sources" + fixture_dir("with_non_default_multiple_secondary_sources") ) assert poetry.pool.has_repository("PyPI") @@ -299,9 +313,11 @@ def test_poetry_with_non_default_multiple_secondary_sources(with_simple_keyring: assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "foo", "bar"} -def test_poetry_with_non_default_multiple_sources_legacy(with_simple_keyring: None): +def test_poetry_with_non_default_multiple_sources_legacy( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: poetry = Factory().create_poetry( - fixtures_dir / "with_non_default_multiple_sources_legacy" + fixture_dir("with_non_default_multiple_sources_legacy") ) assert not poetry.pool.has_default() @@ -315,8 +331,10 @@ def test_poetry_with_non_default_multiple_sources_legacy(with_simple_keyring: No assert {repo.name for repo in poetry.pool.repositories} == {"bar", "PyPI", "foo"} -def test_poetry_with_non_default_multiple_sources(with_simple_keyring: None): - poetry = Factory().create_poetry(fixtures_dir / "with_non_default_multiple_sources") +def test_poetry_with_non_default_multiple_sources( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: + poetry = Factory().create_poetry(fixture_dir("with_non_default_multiple_sources")) assert not poetry.pool.has_default() assert poetry.pool.has_repository("PyPI") @@ -329,8 +347,8 @@ def test_poetry_with_non_default_multiple_sources(with_simple_keyring: None): assert {repo.name for repo in poetry.pool.repositories} == {"PyPI", "bar", "foo"} -def test_poetry_with_no_default_source(): - poetry = Factory().create_poetry(fixtures_dir / "sample_project") +def test_poetry_with_no_default_source(fixture_dir: FixtureDirGetter) -> None: + poetry = Factory().create_poetry(fixture_dir("sample_project")) assert poetry.pool.has_repository("PyPI") assert poetry.pool.get_priority("PyPI") is Priority.DEFAULT @@ -338,8 +356,10 @@ def test_poetry_with_no_default_source(): assert {repo.name for repo in poetry.pool.repositories} == {"PyPI"} -def test_poetry_with_explicit_source(with_simple_keyring: None) -> None: - poetry = Factory().create_poetry(fixtures_dir / "with_explicit_source") +def test_poetry_with_explicit_source( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: + poetry = Factory().create_poetry(fixture_dir("with_explicit_source")) assert len(poetry.pool.repositories) == 1 assert len(poetry.pool.all_repositories) == 2 @@ -351,29 +371,33 @@ def test_poetry_with_explicit_source(with_simple_keyring: None) -> None: assert [repo.name for repo in poetry.pool.repositories] == ["PyPI"] -def test_poetry_with_two_default_sources_legacy(with_simple_keyring: None): +def test_poetry_with_two_default_sources_legacy( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: with pytest.raises(ValueError) as e: - Factory().create_poetry(fixtures_dir / "with_two_default_sources_legacy") + Factory().create_poetry(fixture_dir("with_two_default_sources_legacy")) assert str(e.value) == "Only one repository can be the default." -def test_poetry_with_two_default_sources(with_simple_keyring: None): +def test_poetry_with_two_default_sources( + fixture_dir: FixtureDirGetter, with_simple_keyring: None +) -> None: with pytest.raises(ValueError) as e: - Factory().create_poetry(fixtures_dir / "with_two_default_sources") + Factory().create_poetry(fixture_dir("with_two_default_sources")) assert str(e.value) == "Only one repository can be the default." -def test_validate(): - complete = TOMLFile(fixtures_dir / "complete.toml") +def test_validate(fixture_dir: FixtureDirGetter) -> None: + complete = TOMLFile(fixture_dir("complete.toml")) content = complete.read()["tool"]["poetry"] assert Factory.validate(content) == {"errors": [], "warnings": []} -def test_validate_fails(): - complete = TOMLFile(fixtures_dir / "complete.toml") +def test_validate_fails(fixture_dir: FixtureDirGetter) -> None: + complete = TOMLFile(fixture_dir("complete.toml")) content = complete.read()["tool"]["poetry"] content["this key is not in the schema"] = "" @@ -385,11 +409,11 @@ def test_validate_fails(): assert Factory.validate(content) == {"errors": [expected], "warnings": []} -def test_create_poetry_fails_on_invalid_configuration(): +def test_create_poetry_fails_on_invalid_configuration( + fixture_dir: FixtureDirGetter, +) -> None: with pytest.raises(RuntimeError) as e: - Factory().create_poetry( - Path(__file__).parent / "fixtures" / "invalid_pyproject" / "pyproject.toml" - ) + Factory().create_poetry(fixture_dir("invalid_pyproject") / "pyproject.toml") expected = """\ The Poetry configuration is invalid: @@ -398,7 +422,7 @@ def test_create_poetry_fails_on_invalid_configuration(): assert str(e.value) == expected -def test_create_poetry_with_local_config(fixture_dir: FixtureDirGetter): +def test_create_poetry_with_local_config(fixture_dir: FixtureDirGetter) -> None: poetry = Factory().create_poetry(fixture_dir("with_local_config")) assert not poetry.config.get("virtualenvs.in-project") @@ -409,9 +433,11 @@ def test_create_poetry_with_local_config(fixture_dir: FixtureDirGetter): assert not poetry.config.get("virtualenvs.options.system-site-packages") -def test_create_poetry_with_plugins(mocker: MockerFixture): +def test_create_poetry_with_plugins( + mocker: MockerFixture, fixture_dir: FixtureDirGetter +) -> None: mock_metadata_entry_points(mocker, MyPlugin) - poetry = Factory().create_poetry(fixtures_dir / "sample_project") + poetry = Factory().create_poetry(fixture_dir("sample_project")) assert poetry.package.readmes == ("README.md",) diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index c8589f48594..a5f8957424f 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -42,6 +42,7 @@ from poetry.poetry import Poetry from tests.conftest import Config + from tests.types import FixtureDirGetter from tests.types import ProjectFactory MINIMAL_SCRIPT = """\ @@ -77,9 +78,8 @@ def sys_path(self) -> list[str]: @pytest.fixture() -def poetry(project_factory: ProjectFactory) -> Poetry: - fixture = Path(__file__).parent.parent / "fixtures" / "simple_project" - return project_factory("simple", source=fixture) +def poetry(project_factory: ProjectFactory, fixture_dir: FixtureDirGetter) -> Poetry: + return project_factory("simple", source=fixture_dir("simple_project")) @pytest.fixture() @@ -100,7 +100,7 @@ def test_virtualenvs_with_spaces_in_their_path_work_as_expected( @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 venv_path = tmp_path / "Virtual Env" @@ -1042,7 +1042,7 @@ def test_check_output_with_called_process_error( @pytest.mark.parametrize("out", ["sys.stdout", "sys.stderr"]) def test_call_does_not_block_on_full_pipe( tmp_path: Path, tmp_venv: VirtualEnv, out: str -): +) -> None: """see https://github.com/python-poetry/poetry/issues/7698""" script = tmp_path / "script.py" script.write_text( @@ -1664,10 +1664,8 @@ def test_generate_env_name_uses_real_path( @pytest.fixture() -def extended_without_setup_poetry() -> Poetry: - poetry = Factory().create_poetry( - Path(__file__).parent.parent / "fixtures" / "extended_project_without_setup" - ) +def extended_without_setup_poetry(fixture_dir: FixtureDirGetter) -> Poetry: + poetry = Factory().create_poetry(fixture_dir("extended_project_without_setup")) return poetry @@ -1713,6 +1711,7 @@ def test_build_environment_not_called_without_build_script_specified( def test_create_venv_project_name_empty_sets_correct_prompt( + fixture_dir: FixtureDirGetter, project_factory: ProjectFactory, config: Config, mocker: MockerFixture, @@ -1721,8 +1720,7 @@ def test_create_venv_project_name_empty_sets_correct_prompt( if "VIRTUAL_ENV" in os.environ: del os.environ["VIRTUAL_ENV"] - fixture = Path(__file__).parent.parent / "fixtures" / "no_name_project" - poetry = project_factory("no", source=fixture) + poetry = project_factory("no", source=fixture_dir("no_name_project")) manager = EnvManager(poetry) poetry.package.python_versions = "^3.7" diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index dad06297609..55314a7d743 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -1,6 +1,5 @@ from __future__ import annotations -from pathlib import Path from typing import TYPE_CHECKING import pytest @@ -14,7 +13,7 @@ from tests.types import FixtureDirGetter -def test_parse_requires(): +def test_parse_requires() -> None: requires = """\ jsonschema>=2.6.0.0,<3.0.0.0 lockfile>=0.12.0.0,<0.13.0.0 @@ -71,10 +70,8 @@ def test_parse_requires(): 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" - assert get_file_hash(file_path) == sha_256 + assert get_file_hash(fixture_dir("distributions") / "demo-0.1.0.tar.gz") == sha_256 try: @@ -130,6 +127,5 @@ def test_default_hash(fixture_dir: FixtureDirGetter) -> None: def test_guaranteed_hash( hash_name: str, expected: str, fixture_dir: FixtureDirGetter ) -> None: - root_dir = Path(__file__).parent.parent.parent - file_path = root_dir / fixture_dir("distributions/demo-0.1.0.tar.gz") + file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz" assert get_file_hash(file_path, hash_name) == expected