Skip to content

Commit

Permalink
This test now pass for the new resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr committed Jun 20, 2021
1 parent c55d17c commit b0adb89
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/pip/_internal/models/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,12 @@ class _CleanResult(NamedTuple):
def from_link(cls, link: Link) -> "_CleanResult":
parsed = link._parsed_url
netloc = parsed.netloc.rsplit("@", 1)[-1]
# The fragment does not necessarily use the query string format
# (it's a pip-specific syntax), so we set keep_blank_values to keep
# a fragment that's not a key-value pair (e.g. "#title_1").
frag_qs = urllib.parse.parse_qs(parsed.fragment, keep_blank_values=True)
frag_qs.pop("egg", None)
fragment = urllib.parse.parse_qs(parsed.fragment)
fragment.pop("egg", None)
return _CleanResult(
parsed=parsed._replace(netloc=netloc, query="", fragment=""),
query=urllib.parse.parse_qs(parsed.query),
fragment=frag_qs,
fragment=fragment,
)


Expand Down
13 changes: 2 additions & 11 deletions tests/functional/test_install_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,25 +423,16 @@ def test_constraints_constrain_to_local(script, data, resolver_variant):
assert 'Running setup.py install for singlemodule' in result.stdout


def test_constrained_to_url_install_same_url(script, data, resolver_variant):
def test_constrained_to_url_install_same_url(script, data):
to_install = data.src.joinpath("singlemodule")
constraints = path_to_url(to_install) + "#egg=singlemodule"
script.scratch_path.joinpath("constraints.txt").write_text(constraints)
result = script.pip(
'install', '--no-index', '-f', data.find_links, '-c',
script.scratch_path / 'constraints.txt', to_install,
allow_stderr_warning=True,
expect_error=(resolver_variant == "2020-resolver"),
)
if resolver_variant == "2020-resolver":
assert 'Cannot install singlemodule 0.0.1' in result.stderr, str(result)
assert (
'because these package versions have conflicting dependencies.'
in result.stderr
), str(result)
else:
assert ('Running setup.py install for singlemodule'
in result.stdout), str(result)
assert 'Running setup.py install for singlemodule' in result.stdout, str(result)


def test_double_install_spurious_hash_mismatch(
Expand Down
90 changes: 90 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,96 @@ def test_new_resolver_avoids_incompatible_wheel_tags_in_constraint_url(
assert_not_installed(script, "dep")


@pytest.mark.parametrize(
"suffixes_equivalent, depend_suffix, request_suffix",
[
pytest.param(
True,
"#egg=foo",
"",
id="drop-depend-egg",
),
pytest.param(
True,
"",
"#egg=foo",
id="drop-request-egg",
),
pytest.param(
True,
"#subdirectory=bar&egg=foo",
"#subdirectory=bar&egg=bar",
id="drop-egg-only",
),
pytest.param(
True,
"#subdirectory=bar&egg=foo",
"#egg=foo&subdirectory=bar",
id="fragment-ordering",
),
pytest.param(
True,
"?a=1&b=2",
"?b=2&a=1",
id="query-opordering",
),
pytest.param(
False,
"#sha512=1234567890abcdef",
"#sha512=abcdef1234567890",
id="different-keys",
),
pytest.param(
False,
"#sha512=1234567890abcdef",
"#md5=1234567890abcdef",
id="different-values",
),
pytest.param(
False,
"#subdirectory=bar&egg=foo",
"#subdirectory=rex",
id="drop-egg-still-different",
),
],
)
def test_new_resolver_direct_url_equivalent(
tmp_path,
script,
suffixes_equivalent,
depend_suffix,
request_suffix,
):
pkga = create_basic_wheel_for_package(script, name="pkga", version="1")
pkgb = create_basic_wheel_for_package(
script,
name="pkgb",
version="1",
depends=[f"pkga@{path_to_url(pkga)}{depend_suffix}"],
)

# Make pkgb visible via --find-links, but not pkga.
find_links = tmp_path.joinpath("find_links")
find_links.mkdir()
with open(pkgb, "rb") as f:
find_links.joinpath(pkgb.name).write_bytes(f.read())

# Install pkgb from --find-links, and pkga directly but from a different
# URL suffix as specified in pkgb. This should work!
script.pip(
"install",
"--no-cache-dir", "--no-index",
"--find-links", str(find_links),
f"{path_to_url(pkga)}{request_suffix}", "pkgb",
expect_error=(not suffixes_equivalent),
)

if suffixes_equivalent:
assert_installed(script, pkga="1", pkgb="1")
else:
assert_not_installed(script, "pkga", "pkgb")


def test_new_resolver_direct_url_with_extras(tmp_path, script):
pkg1 = create_basic_wheel_for_package(script, name="pkg1", version="1")
pkg2 = create_basic_wheel_for_package(
Expand Down
55 changes: 54 additions & 1 deletion tests/unit/test_link.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pip._internal.models.link import Link
from pip._internal.models.link import Link, links_equivalent
from pip._internal.utils.hashes import Hashes


Expand Down Expand Up @@ -138,3 +138,56 @@ def test_is_hash_allowed__none_hashes(self, hashes, expected):
def test_is_vcs(self, url, expected):
link = Link(url)
assert link.is_vcs is expected


@pytest.mark.parametrize(
"url1, url2",
[
pytest.param(
"https://example.com/foo#egg=foo",
"https://example.com/foo",
id="drop-egg",
),
pytest.param(
"https://example.com/foo#subdirectory=bar&egg=foo",
"https://example.com/foo#subdirectory=bar&egg=bar",
id="drop-egg-only",
),
pytest.param(
"https://example.com/foo#subdirectory=bar&egg=foo",
"https://example.com/foo#egg=foo&subdirectory=bar",
id="fragment-ordering",
),
pytest.param(
"https://example.com/foo?a=1&b=2",
"https://example.com/foo?b=2&a=1",
id="query-opordering",
),
],
)
def test_links_equivalent(url1, url2):
assert links_equivalent(Link(url1), Link(url2))


@pytest.mark.parametrize(
"url1, url2",
[
pytest.param(
"https://example.com/foo#sha512=1234567890abcdef",
"https://example.com/foo#sha512=abcdef1234567890",
id="different-keys",
),
pytest.param(
"https://example.com/foo#sha512=1234567890abcdef",
"https://example.com/foo#md5=1234567890abcdef",
id="different-values",
),
pytest.param(
"https://example.com/foo#subdirectory=bar&egg=foo",
"https://example.com/foo#subdirectory=rex",
id="drop-egg-still-different",
),
],
)
def test_links_equivalent_false(url1, url2):
assert not links_equivalent(Link(url1), Link(url2))

0 comments on commit b0adb89

Please sign in to comment.