Skip to content

Commit b0adb89

Browse files
committed
This test now pass for the new resolver
1 parent c55d17c commit b0adb89

File tree

4 files changed

+149
-18
lines changed

4 files changed

+149
-18
lines changed

src/pip/_internal/models/link.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,12 @@ class _CleanResult(NamedTuple):
274274
def from_link(cls, link: Link) -> "_CleanResult":
275275
parsed = link._parsed_url
276276
netloc = parsed.netloc.rsplit("@", 1)[-1]
277-
# The fragment does not necessarily use the query string format
278-
# (it's a pip-specific syntax), so we set keep_blank_values to keep
279-
# a fragment that's not a key-value pair (e.g. "#title_1").
280-
frag_qs = urllib.parse.parse_qs(parsed.fragment, keep_blank_values=True)
281-
frag_qs.pop("egg", None)
277+
fragment = urllib.parse.parse_qs(parsed.fragment)
278+
fragment.pop("egg", None)
282279
return _CleanResult(
283280
parsed=parsed._replace(netloc=netloc, query="", fragment=""),
284281
query=urllib.parse.parse_qs(parsed.query),
285-
fragment=frag_qs,
282+
fragment=fragment,
286283
)
287284

288285

tests/functional/test_install_reqs.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -423,25 +423,16 @@ def test_constraints_constrain_to_local(script, data, resolver_variant):
423423
assert 'Running setup.py install for singlemodule' in result.stdout
424424

425425

426-
def test_constrained_to_url_install_same_url(script, data, resolver_variant):
426+
def test_constrained_to_url_install_same_url(script, data):
427427
to_install = data.src.joinpath("singlemodule")
428428
constraints = path_to_url(to_install) + "#egg=singlemodule"
429429
script.scratch_path.joinpath("constraints.txt").write_text(constraints)
430430
result = script.pip(
431431
'install', '--no-index', '-f', data.find_links, '-c',
432432
script.scratch_path / 'constraints.txt', to_install,
433433
allow_stderr_warning=True,
434-
expect_error=(resolver_variant == "2020-resolver"),
435434
)
436-
if resolver_variant == "2020-resolver":
437-
assert 'Cannot install singlemodule 0.0.1' in result.stderr, str(result)
438-
assert (
439-
'because these package versions have conflicting dependencies.'
440-
in result.stderr
441-
), str(result)
442-
else:
443-
assert ('Running setup.py install for singlemodule'
444-
in result.stdout), str(result)
435+
assert 'Running setup.py install for singlemodule' in result.stdout, str(result)
445436

446437

447438
def test_double_install_spurious_hash_mismatch(

tests/functional/test_new_resolver.py

+90
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,96 @@ def test_new_resolver_avoids_incompatible_wheel_tags_in_constraint_url(
17911791
assert_not_installed(script, "dep")
17921792

17931793

1794+
@pytest.mark.parametrize(
1795+
"suffixes_equivalent, depend_suffix, request_suffix",
1796+
[
1797+
pytest.param(
1798+
True,
1799+
"#egg=foo",
1800+
"",
1801+
id="drop-depend-egg",
1802+
),
1803+
pytest.param(
1804+
True,
1805+
"",
1806+
"#egg=foo",
1807+
id="drop-request-egg",
1808+
),
1809+
pytest.param(
1810+
True,
1811+
"#subdirectory=bar&egg=foo",
1812+
"#subdirectory=bar&egg=bar",
1813+
id="drop-egg-only",
1814+
),
1815+
pytest.param(
1816+
True,
1817+
"#subdirectory=bar&egg=foo",
1818+
"#egg=foo&subdirectory=bar",
1819+
id="fragment-ordering",
1820+
),
1821+
pytest.param(
1822+
True,
1823+
"?a=1&b=2",
1824+
"?b=2&a=1",
1825+
id="query-opordering",
1826+
),
1827+
pytest.param(
1828+
False,
1829+
"#sha512=1234567890abcdef",
1830+
"#sha512=abcdef1234567890",
1831+
id="different-keys",
1832+
),
1833+
pytest.param(
1834+
False,
1835+
"#sha512=1234567890abcdef",
1836+
"#md5=1234567890abcdef",
1837+
id="different-values",
1838+
),
1839+
pytest.param(
1840+
False,
1841+
"#subdirectory=bar&egg=foo",
1842+
"#subdirectory=rex",
1843+
id="drop-egg-still-different",
1844+
),
1845+
],
1846+
)
1847+
def test_new_resolver_direct_url_equivalent(
1848+
tmp_path,
1849+
script,
1850+
suffixes_equivalent,
1851+
depend_suffix,
1852+
request_suffix,
1853+
):
1854+
pkga = create_basic_wheel_for_package(script, name="pkga", version="1")
1855+
pkgb = create_basic_wheel_for_package(
1856+
script,
1857+
name="pkgb",
1858+
version="1",
1859+
depends=[f"pkga@{path_to_url(pkga)}{depend_suffix}"],
1860+
)
1861+
1862+
# Make pkgb visible via --find-links, but not pkga.
1863+
find_links = tmp_path.joinpath("find_links")
1864+
find_links.mkdir()
1865+
with open(pkgb, "rb") as f:
1866+
find_links.joinpath(pkgb.name).write_bytes(f.read())
1867+
1868+
# Install pkgb from --find-links, and pkga directly but from a different
1869+
# URL suffix as specified in pkgb. This should work!
1870+
script.pip(
1871+
"install",
1872+
"--no-cache-dir", "--no-index",
1873+
"--find-links", str(find_links),
1874+
f"{path_to_url(pkga)}{request_suffix}", "pkgb",
1875+
expect_error=(not suffixes_equivalent),
1876+
)
1877+
1878+
if suffixes_equivalent:
1879+
assert_installed(script, pkga="1", pkgb="1")
1880+
else:
1881+
assert_not_installed(script, "pkga", "pkgb")
1882+
1883+
17941884
def test_new_resolver_direct_url_with_extras(tmp_path, script):
17951885
pkg1 = create_basic_wheel_for_package(script, name="pkg1", version="1")
17961886
pkg2 = create_basic_wheel_for_package(

tests/unit/test_link.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from pip._internal.models.link import Link
3+
from pip._internal.models.link import Link, links_equivalent
44
from pip._internal.utils.hashes import Hashes
55

66

@@ -138,3 +138,56 @@ def test_is_hash_allowed__none_hashes(self, hashes, expected):
138138
def test_is_vcs(self, url, expected):
139139
link = Link(url)
140140
assert link.is_vcs is expected
141+
142+
143+
@pytest.mark.parametrize(
144+
"url1, url2",
145+
[
146+
pytest.param(
147+
"https://example.com/foo#egg=foo",
148+
"https://example.com/foo",
149+
id="drop-egg",
150+
),
151+
pytest.param(
152+
"https://example.com/foo#subdirectory=bar&egg=foo",
153+
"https://example.com/foo#subdirectory=bar&egg=bar",
154+
id="drop-egg-only",
155+
),
156+
pytest.param(
157+
"https://example.com/foo#subdirectory=bar&egg=foo",
158+
"https://example.com/foo#egg=foo&subdirectory=bar",
159+
id="fragment-ordering",
160+
),
161+
pytest.param(
162+
"https://example.com/foo?a=1&b=2",
163+
"https://example.com/foo?b=2&a=1",
164+
id="query-opordering",
165+
),
166+
],
167+
)
168+
def test_links_equivalent(url1, url2):
169+
assert links_equivalent(Link(url1), Link(url2))
170+
171+
172+
@pytest.mark.parametrize(
173+
"url1, url2",
174+
[
175+
pytest.param(
176+
"https://example.com/foo#sha512=1234567890abcdef",
177+
"https://example.com/foo#sha512=abcdef1234567890",
178+
id="different-keys",
179+
),
180+
pytest.param(
181+
"https://example.com/foo#sha512=1234567890abcdef",
182+
"https://example.com/foo#md5=1234567890abcdef",
183+
id="different-values",
184+
),
185+
pytest.param(
186+
"https://example.com/foo#subdirectory=bar&egg=foo",
187+
"https://example.com/foo#subdirectory=rex",
188+
id="drop-egg-still-different",
189+
),
190+
],
191+
)
192+
def test_links_equivalent_false(url1, url2):
193+
assert not links_equivalent(Link(url1), Link(url2))

0 commit comments

Comments
 (0)