diff --git a/tests/functional/test_check.py b/tests/functional/test_check.py index 06ed1b08eac..f0180ba32bb 100644 --- a/tests/functional/test_check.py +++ b/tests/functional/test_check.py @@ -333,14 +333,7 @@ def test_check_unsupported( script.scratch_path.joinpath("base-0.1.0-py2.py3-none-any.whl").write_bytes( create_really_basic_wheel("base", "0.1.0") ) - script.pip( - "install", - "--no-cache-dir", - "--no-index", - "--find-links", - script.scratch_path, - "base==0.1.0", - ) + script.pip_install_local("base==0.1.0", find_links=script.scratch_path) with open( script.site_packages_path.joinpath("base-0.1.0.dist-info/WHEEL"), "a" ) as f: diff --git a/tests/functional/test_pep517.py b/tests/functional/test_pep517.py index 9be3834241f..edcdbc048fa 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -197,16 +197,11 @@ def test_validate_missing_pep517_backend_requirements( project_dir = make_project( tmpdir, requires=["test_backend", "simplewheel==1.0"], backend="test_backend" ) - result = script.pip( - "install", - "--no-index", - "-f", - data.backends, - "-f", - data.packages, + result = script.pip_install_local( "--no-build-isolation", "--check-build-dependencies", project_dir, + find_links=[data.backends, data.packages], expect_error=True, ) msg = ( @@ -224,16 +219,11 @@ def test_validate_conflicting_pep517_backend_requirements( tmpdir, requires=["simplewheel==1.0"], backend="test_backend" ) script.pip("install", "simplewheel==2.0", "--no-index", "-f", data.packages) - result = script.pip( - "install", - "--no-index", - "-f", - data.backends, - "-f", - data.packages, + result = script.pip_install_local( "--no-build-isolation", "--check-build-dependencies", project_dir, + find_links=[data.backends, data.packages], expect_error=True, ) msg = ( @@ -271,14 +261,8 @@ def test_pep517_backend_requirements_already_satisfied( tmpdir, requires=["test_backend", "simplewheel==1.0"], backend="test_backend" ) project_dir.joinpath("backend_reqs.txt").write_text("simplewheel") - result = script.pip( - "install", - "--no-index", - "-f", - data.backends, - "-f", - data.packages, - project_dir, + result = script.pip_install_local( + project_dir, find_links=[data.backends, data.packages] ) assert "Installing backend dependencies:" not in result.stdout @@ -290,13 +274,8 @@ def test_pep517_install_with_no_cache_dir( project_dir = make_project( tmpdir, requires=["test_backend"], backend="test_backend" ) - result = script.pip( - "install", - "--no-cache-dir", - "--no-index", - "-f", - data.backends, - project_dir, + result = script.pip_install_local( + "--no-cache-dir", project_dir, find_links=data.backends ) result.assert_installed("project", editable=False) @@ -346,13 +325,8 @@ def test_no_build_system_section( ) -> None: """Check builds with setup.py, pyproject.toml, but no build-system section.""" project_dir, name = make_pyproject_with_setup(tmpdir, build_system=False) - result = script.pip( - "install", - "--no-cache-dir", - "--no-index", - "-f", - common_wheels, - project_dir, + result = script.pip_install_local( + "--no-cache-dir", project_dir, find_links=common_wheels ) result.assert_installed(name, editable=False) @@ -362,13 +336,8 @@ def test_no_build_backend_entry( ) -> None: """Check builds with setup.py, pyproject.toml, but no build-backend entry.""" project_dir, name = make_pyproject_with_setup(tmpdir, set_backend=False) - result = script.pip( - "install", - "--no-cache-dir", - "--no-index", - "-f", - common_wheels, - project_dir, + result = script.pip_install_local( + "--no-cache-dir", project_dir, find_links=common_wheels ) result.assert_installed(name, editable=False) @@ -378,13 +347,8 @@ def test_explicit_setuptools_backend( ) -> None: """Check builds with setup.py, pyproject.toml, and a build-backend entry.""" project_dir, name = make_pyproject_with_setup(tmpdir) - result = script.pip( - "install", - "--no-cache-dir", - "--no-index", - "-f", - common_wheels, - project_dir, + result = script.pip_install_local( + "--no-cache-dir", project_dir, find_links=common_wheels ) result.assert_installed(name, editable=False) diff --git a/tests/functional/test_show.py b/tests/functional/test_show.py index ea831935372..5fefe9bd2ea 100644 --- a/tests/functional/test_show.py +++ b/tests/functional/test_show.py @@ -52,8 +52,7 @@ def test_show_with_files_from_wheel(script: PipTestEnvironment, data: TestData) """ Test that a wheel's files can be listed. """ - wheel_file = data.packages.joinpath("simple.dist-0.1-py2.py3-none-any.whl") - script.pip("install", "--no-index", wheel_file) + script.pip_install_local(data.packages / "simple.dist-0.1-py2.py3-none-any.whl") result = script.pip("show", "-f", "simple.dist") lines = result.stdout.splitlines() assert "Name: simple.dist" in lines @@ -181,8 +180,7 @@ def test_show_verbose_installer(script: PipTestEnvironment, data: TestData) -> N """ Test that the installer is shown (this currently needs a wheel install) """ - wheel_file = data.packages.joinpath("simple.dist-0.1-py2.py3-none-any.whl") - script.pip("install", "--no-index", wheel_file) + script.pip_install_local(data.packages / "simple.dist-0.1-py2.py3-none-any.whl") result = script.pip("show", "--verbose", "simple.dist") lines = result.stdout.splitlines() assert "Name: simple.dist" in lines @@ -260,20 +258,18 @@ def test_pip_show_is_short(script: PipTestEnvironment) -> None: assert len(lines) <= 11 -def test_pip_show_divider(script: PipTestEnvironment, data: TestData) -> None: +def test_pip_show_divider(script: PipTestEnvironment) -> None: """ Expect a divider between packages """ - script.pip("install", "pip-test-package", "--no-index", "-f", data.packages) + script.pip_install_local("pip-test-package") result = script.pip("show", "pip", "pip-test-package") lines = result.stdout.splitlines() assert "---" in lines -def test_package_name_is_canonicalized( - script: PipTestEnvironment, data: TestData -) -> None: - script.pip("install", "pip-test-package", "--no-index", "-f", data.packages) +def test_package_name_is_canonicalized(script: PipTestEnvironment) -> None: + script.pip_install_local("pip-test-package") dash_show_result = script.pip("show", "pip-test-package") underscore_upper_show_result = script.pip("show", "pip-test_Package") @@ -288,8 +284,7 @@ def test_show_required_by_packages_basic( """ Test that installed packages that depend on this package are shown """ - editable_path = os.path.join(data.src, "requires_simple") - script.pip("install", "--no-index", "-f", data.find_links, editable_path) + script.pip_install_local(data.src / "requires_simple") result = script.pip("show", "simple") lines = result.stdout.splitlines() @@ -308,8 +303,7 @@ def test_show_required_by_packages_capitalized( Test that the installed packages which depend on a package are shown where the package has a capital letter """ - editable_path = os.path.join(data.src, "requires_capitalized") - script.pip("install", "--no-index", "-f", data.find_links, editable_path) + script.pip_install_local(data.src / "requires_capitalized") result = script.pip("show", "simple") lines = result.stdout.splitlines() @@ -329,10 +323,8 @@ def test_show_required_by_packages_requiring_capitalized( where the package has a name with a mix of lower and upper case letters """ - required_package_path = os.path.join(data.src, "requires_capitalized") - script.pip("install", "--no-index", "-f", data.find_links, required_package_path) - editable_path = os.path.join(data.src, "requires_requires_capitalized") - script.pip("install", "--no-index", "-f", data.find_links, editable_path) + script.pip_install_local(data.src / "requires_capitalized") + script.pip_install_local(data.src / "requires_requires_capitalized") result = script.pip("show", "Requires_Capitalized") lines = result.stdout.splitlines() @@ -432,8 +424,7 @@ def test_show_license_expression(script: PipTestEnvironment, data: TestData) -> """ Show License-Expression if present in metadata >= 2.4. """ - wheel_file = data.packages.joinpath("license.dist-0.1-py2.py3-none-any.whl") - script.pip("install", "--no-index", wheel_file) + script.pip_install_local(data.packages / "license.dist-0.1-py2.py3-none-any.whl") result = script.pip("show", "license.dist") lines = result.stdout.splitlines() assert "License-Expression: MIT AND MIT-0" in lines @@ -446,8 +437,7 @@ def test_show_license_for_metadata_24( """ Show License if License-Expression is not there for metadata >= 2.4. """ - wheel_file = data.packages.joinpath("license.dist-0.2-py2.py3-none-any.whl") - script.pip("install", "--no-index", wheel_file) + script.pip_install_local(data.packages / "license.dist-0.2-py2.py3-none-any.whl") result = script.pip("show", "license.dist") lines = result.stdout.splitlines() assert "License-Expression: " not in lines diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index d67271e1885..e37ba50d426 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -725,13 +725,26 @@ def pip( def pip_install_local( self, *args: StrPath, + find_links: StrPath | list[StrPath] = pathlib.Path(DATA_DIR, "packages"), **kwargs: Any, ) -> TestPipResult: + """Invoke pip install without PyPI access. By default, only local + packages are included via --find-links.""" + # Convert find links paths to absolute file: URIs + if not isinstance(find_links, list): + find_links = [find_links] + find_links_args: list[StrPath] = [] + for folder in find_links: + if isinstance(folder, str) and folder.startswith("file:"): + find_links_args.extend(("--find-links", folder)) + else: + path = pathlib.Path(folder).resolve() + find_links_args.extend(("--find-links", path.as_uri())) + return self.pip( "install", "--no-index", - "--find-links", - pathlib.Path(DATA_DIR, "packages").as_uri(), + *find_links_args, *args, **kwargs, )