Skip to content

Commit 13eba86

Browse files
committed
Update tests that were looking for egg-link files to detect editables
1 parent f8d336c commit 13eba86

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

tests/functional/test_install.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytest
1717

1818
from pip._internal.cli.status_codes import ERROR, SUCCESS
19+
from pip._internal.models.direct_url import DirectUrl
1920
from pip._internal.models.index import PyPI, TestPyPI
2021
from pip._internal.utils.misc import rmtree
2122
from pip._internal.utils.urls import path_to_url
@@ -478,8 +479,7 @@ def test_install_editable_uninstalls_existing_from_path(
478479
"-e",
479480
to_install,
480481
)
481-
install_path = script.site_packages / "simplewheel.egg-link"
482-
result.did_create(install_path)
482+
result.assert_installed("simplewheel", editable=True)
483483
assert "Found existing installation: simplewheel 1.0" in result.stdout
484484
assert "Uninstalling simplewheel-" in result.stdout
485485
assert "Successfully uninstalled simplewheel" in result.stdout
@@ -575,7 +575,6 @@ def test_basic_install_relative_directory(
575575
Test installing a requirement using a relative path.
576576
"""
577577
dist_info_folder = script.site_packages / "fspkg-0.1.dev0.dist-info"
578-
egg_link_file = script.site_packages / "FSPkg.egg-link"
579578
package_folder = script.site_packages / "fspkg"
580579

581580
# Compute relative install path to FSPkg from scratch path.
@@ -599,7 +598,9 @@ def test_basic_install_relative_directory(
599598
else:
600599
# Editable install.
601600
result = script.pip("install", "-e", req_path, cwd=script.scratch_path)
602-
result.did_create(egg_link_file)
601+
direct_url = result.get_created_direct_url("fspkg")
602+
assert direct_url
603+
assert direct_url.is_local_editable()
603604

604605

605606
def test_install_quiet(script: PipTestEnvironment, data: TestData) -> None:
@@ -1374,7 +1375,9 @@ def _test_install_editable_with_prefix(
13741375
result = script.pip("install", "--editable", pkga_path, "--prefix", prefix_path)
13751376

13761377
# assert pkga is installed at correct location
1377-
install_path = script.scratch / site_packages / "pkga.egg-link"
1378+
install_path = (
1379+
script.scratch / site_packages / "pkga-0.1.dist-info" / "direct_url.json"
1380+
)
13781381
result.did_create(install_path)
13791382

13801383
return result
@@ -1400,7 +1403,11 @@ def test_install_editable_with_target(script: PipTestEnvironment) -> None:
14001403
target.mkdir()
14011404
result = script.pip("install", "--editable", pkg_path, "--target", target)
14021405

1403-
result.did_create(script.scratch / "target" / "pkg.egg-link")
1406+
direct_url_path = result.get_created_direct_url_path("pkg")
1407+
assert direct_url_path
1408+
assert direct_url_path.parent.parent == target
1409+
direct_url = DirectUrl.from_json(direct_url_path.read_text())
1410+
assert direct_url.is_local_editable()
14041411
result.did_create(script.scratch / "target" / "watching_testrunner.py")
14051412

14061413

tests/functional/test_install_reqs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def test_relative_requirements_file(
217217
218218
"""
219219
dist_info_folder = script.site_packages / "fspkg-0.1.dev0.dist-info"
220-
egg_link_file = script.site_packages / "FSPkg.egg-link"
221220
package_folder = script.site_packages / "fspkg"
222221

223222
# Compute relative install path to FSPkg from scratch path.
@@ -249,7 +248,9 @@ def test_relative_requirements_file(
249248
result = script.pip(
250249
"install", "-vvv", "-r", reqs_file.name, cwd=script.scratch_path
251250
)
252-
result.did_create(egg_link_file)
251+
direct_url = result.get_created_direct_url("fspkg")
252+
assert direct_url
253+
assert direct_url.is_local_editable()
253254

254255

255256
@pytest.mark.xfail
@@ -384,9 +385,8 @@ def test_install_local_editable_with_extras(
384385
res = script.pip_install_local(
385386
"-e", f"{to_install}[bar]", allow_stderr_warning=True
386387
)
387-
res.did_update(script.site_packages / "easy-install.pth")
388-
res.did_create(script.site_packages / "LocalExtras.egg-link")
389-
res.did_create(script.site_packages / "simple")
388+
res.assert_installed("LocalExtras", editable=True, editable_vcs=False)
389+
res.assert_installed("simple", editable=False)
390390

391391

392392
def test_install_collected_dependencies_first(script: PipTestEnvironment) -> None:

tests/functional/test_new_resolver.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import TYPE_CHECKING, Callable, Protocol
66

77
import pytest
8-
from packaging.utils import canonicalize_name
98

109
from tests.conftest import ScriptFactory
1110
from tests.lib import (
@@ -20,20 +19,6 @@
2019
MakeFakeWheel = Callable[[str, str, str], pathlib.Path]
2120

2221

23-
def assert_editable(script: PipTestEnvironment, *args: str) -> None:
24-
# This simply checks whether all of the listed packages have a
25-
# corresponding .egg-link file installed.
26-
# TODO: Implement a more rigorous way to test for editable installations.
27-
egg_links = {f"{canonicalize_name(arg)}.egg-link" for arg in args}
28-
actual_egg_links = {
29-
f"{canonicalize_name(p.stem)}.egg-link"
30-
for p in script.site_packages_path.glob("*.egg-link")
31-
}
32-
assert (
33-
egg_links <= actual_egg_links
34-
), f"{args!r} not all found in {script.site_packages_path!r}"
35-
36-
3722
@pytest.fixture
3823
def make_fake_wheel(script: PipTestEnvironment) -> MakeFakeWheel:
3924
def _make_fake_wheel(name: str, version: str, wheel_tag: str) -> pathlib.Path:
@@ -339,7 +324,7 @@ def test_new_resolver_installs_editable(script: PipTestEnvironment) -> None:
339324
source_dir,
340325
)
341326
script.assert_installed(base="0.1.0", dep="0.1.0")
342-
assert_editable(script, "dep")
327+
script.assert_installed_editable("dep")
343328

344329

345330
@pytest.mark.parametrize(
@@ -1871,7 +1856,7 @@ def test_new_resolver_succeeds_on_matching_constraint_and_requirement(
18711856

18721857
script.assert_installed(test_pkg="0.1.0")
18731858
if editable:
1874-
assert_editable(script, "test_pkg")
1859+
script.assert_installed_editable("test_pkg")
18751860

18761861

18771862
def test_new_resolver_applies_url_constraint_to_dep(script: PipTestEnvironment) -> None:

tests/lib/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,17 @@ def assert_not_installed(self, *args: str) -> None:
738738
expected = {canonicalize_name(k) for k in args}
739739
assert not (expected & installed), f"{expected!r} contained in {installed!r}"
740740

741+
def assert_installed_editable(self, dist_name: str) -> None:
742+
dist_name = canonicalize_name(dist_name)
743+
ret = self.pip("list", "--format=json")
744+
installed = json.loads(ret.stdout)
745+
assert any(
746+
x
747+
for x in installed
748+
if canonicalize_name(x["name"]) == dist_name
749+
and x.get("editable_project_location")
750+
)
751+
741752

742753
# FIXME ScriptTest does something similar, but only within a single
743754
# ProcResult; this generalizes it so states can be compared across

0 commit comments

Comments
 (0)