Skip to content

test: Extend pip_install_local() test helper #13484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions tests/functional/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
64 changes: 14 additions & 50 deletions tests/functional/test_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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 = (
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
34 changes: 12 additions & 22 deletions tests/functional/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
17 changes: 15 additions & 2 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Loading