Skip to content

Commit

Permalink
More test suite fixes for setuptools 69 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jan 14, 2024
1 parent d123a0b commit f00a2be
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 22 deletions.
20 changes: 16 additions & 4 deletions tests/functional/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ def test_check_complicated_name_missing(script: PipTestEnvironment) -> None:

# Without dependency
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
assert "Successfully installed package_A-1.0" in result.stdout, str(result)
assert (
"Successfully installed package_A-1.0" in result.stdout
or "Successfully installed package-A-1.0" in result.stdout
), str(result)

result = script.pip("check", expect_error=True)
expected_lines = ("package-a 1.0 requires dependency-b, which is not installed.",)
Expand All @@ -142,7 +145,10 @@ def test_check_complicated_name_broken(script: PipTestEnvironment) -> None:

# With broken dependency
result = script.pip("install", "--no-index", package_a_path, "--no-deps")
assert "Successfully installed package_A-1.0" in result.stdout, str(result)
assert (
"Successfully installed package_A-1.0" in result.stdout
or "Successfully installed package-A-1.0" in result.stdout
), str(result)

result = script.pip(
"install",
Expand Down Expand Up @@ -175,7 +181,10 @@ def test_check_complicated_name_clean(script: PipTestEnvironment) -> None:
)

result = script.pip("install", "--no-index", package_a_path, "--no-deps")
assert "Successfully installed package_A-1.0" in result.stdout, str(result)
assert (
"Successfully installed package_A-1.0" in result.stdout
or "Successfully installed package-A-1.0" in result.stdout
), str(result)

result = script.pip(
"install",
Expand Down Expand Up @@ -203,7 +212,10 @@ def test_check_considers_conditional_reqs(script: PipTestEnvironment) -> None:
)

result = script.pip("install", "--no-index", package_a_path, "--no-deps")
assert "Successfully installed package_A-1.0" in result.stdout, str(result)
assert (
"Successfully installed package_A-1.0" in result.stdout
or "Successfully installed package-A-1.0" in result.stdout
), str(result)

result = script.pip("check", expect_error=True)
expected_lines = ("package-a 1.0 requires dependency-b, which is not installed.",)
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/test_freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_freeze_editable_not_vcs(script: PipTestEnvironment) -> None:
# the freeze code does.
expected = textwrap.dedent(
f"""\
...# Editable install with no version control (version-pkg==0.1)
...# Editable install with no version control (version...pkg==0.1)
-e {os.path.normcase(pkg_path)}
..."""
)
Expand All @@ -245,7 +245,7 @@ def test_freeze_editable_git_with_no_remote(
# the freeze code does.
expected = textwrap.dedent(
f"""\
...# Editable Git install with no remote (version-pkg==0.1)
...# Editable Git install with no remote (version...pkg==0.1)
-e {os.path.normcase(pkg_path)}
..."""
)
Expand Down Expand Up @@ -483,7 +483,7 @@ def test_freeze_git_remote(script: PipTestEnvironment) -> None:
expected = os.path.normcase(
textwrap.dedent(
f"""
...# Editable Git...(version-pkg...)...
...# Editable Git...(version...pkg...)...
# '{other_remote}'
-e {repo_dir}...
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def test_install_local_editable_with_subdirectory(script: PipTestEnvironment) ->
),
)

result.assert_installed("version-subpkg", sub_dir="version_subdir")
result.assert_installed("version_subpkg", sub_dir="version_subdir")


@pytest.mark.network
Expand Down
11 changes: 8 additions & 3 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING, Callable, Dict, List, Tuple

import pytest
from packaging.utils import canonicalize_name

from tests.conftest import ScriptFactory
from tests.lib import (
Expand All @@ -27,9 +28,13 @@ def assert_editable(script: PipTestEnvironment, *args: str) -> None:
# This simply checks whether all of the listed packages have a
# corresponding .egg-link file installed.
# TODO: Implement a more rigorous way to test for editable installations.
egg_links = {f"{arg}.egg-link" for arg in args}
assert egg_links <= set(
os.listdir(script.site_packages_path)
egg_links = {f"{canonicalize_name(arg)}.egg-link" for arg in args}
actual_egg_links = {
f"{canonicalize_name(p.stem)}.egg-link"
for p in script.site_packages_path.glob("*.egg-link")
}
assert (
egg_links <= actual_egg_links
), f"{args!r} not all found in {script.site_packages_path!r}"


Expand Down
19 changes: 15 additions & 4 deletions tests/functional/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ def test_show_required_by_packages_basic(
lines = result.stdout.splitlines()

assert "Name: simple" in lines
assert "Required-by: requires_simple" in lines
assert (
"Required-by: requires_simple" in lines
or "Required-by: requires-simple" in lines
)


def test_show_required_by_packages_capitalized(
Expand All @@ -294,7 +297,10 @@ def test_show_required_by_packages_capitalized(
lines = result.stdout.splitlines()

assert "Name: simple" in lines
assert "Required-by: Requires_Capitalized" in lines
assert (
"Required-by: Requires_Capitalized" in lines
or "Required-by: Requires-Capitalized" in lines
)


def test_show_required_by_packages_requiring_capitalized(
Expand All @@ -314,8 +320,13 @@ def test_show_required_by_packages_requiring_capitalized(
lines = result.stdout.splitlines()
print(lines)

assert "Name: Requires_Capitalized" in lines
assert "Required-by: requires_requires_capitalized" in lines
assert (
"Name: Requires_Capitalized" in lines or "Name: Requires-Capitalized" in lines
)
assert (
"Required-by: requires_requires_capitalized" in lines
or "Required-by: requires-requires-capitalized" in lines
)


def test_show_skip_work_dir_pkg(script: PipTestEnvironment) -> None:
Expand Down
29 changes: 22 additions & 7 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from pip._internal.models.selection_prefs import SelectionPreferences
from pip._internal.models.target_python import TargetPython
from pip._internal.network.session import PipSession
from pip._internal.utils.egg_link import _egg_link_names
from tests.lib.venv import VirtualEnvironment
from tests.lib.wheel import make_wheel

Expand Down Expand Up @@ -305,6 +306,12 @@ def files_updated(self) -> FoundFiles:
def files_deleted(self) -> FoundFiles:
return FoundFiles(self._impl.files_deleted)

def _get_egg_link_path_created(self, egg_link_paths: List[str]) -> Optional[str]:
for egg_link_path in egg_link_paths:
if egg_link_path in self.files_created:
return egg_link_path
return None

def assert_installed(
self,
pkg_name: str,
Expand All @@ -329,22 +336,30 @@ def assert_installed(
pkg_dir = e.site_packages / pkg_name

if use_user_site:
egg_link_path = e.user_site / f"{pkg_name}.egg-link"
egg_link_paths = [
e.user_site / egg_link_name
for egg_link_name in _egg_link_names(pkg_name)
]
else:
egg_link_path = e.site_packages / f"{pkg_name}.egg-link"
egg_link_paths = [
e.site_packages / egg_link_name
for egg_link_name in _egg_link_names(pkg_name)
]

egg_link_path_created = self._get_egg_link_path_created(egg_link_paths)
if without_egg_link:
if egg_link_path in self.files_created:
if egg_link_path_created:
raise TestFailure(
f"unexpected egg link file created: {egg_link_path!r}\n{self}"
f"unexpected egg link file created: {egg_link_path_created!r}\n"
f"{self}"
)
else:
if egg_link_path not in self.files_created:
if not egg_link_path_created:
raise TestFailure(
f"expected egg link file missing: {egg_link_path!r}\n{self}"
f"expected egg link file missing: {egg_link_paths!r}\n{self}"
)

egg_link_file = self.files_created[egg_link_path]
egg_link_file = self.files_created[egg_link_path_created]
egg_link_contents = egg_link_file.bytes.replace(os.linesep, "\n")

# FIXME: I don't understand why there's a trailing . here
Expand Down

0 comments on commit f00a2be

Please sign in to comment.