Skip to content

Commit

Permalink
restore _clean_link method from collector.py to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Dec 28, 2021
1 parent e326ca3 commit 72d8357
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tests/unit/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@
from pip._internal.index.sources import _FlatDirectorySource, _IndexDirectorySource
from pip._internal.models.candidate import InstallationCandidate
from pip._internal.models.index import PyPI
from pip._internal.models.link import Link, _clean_link, _clean_url_path
from pip._internal.models.link import Link, _clean_url_path
from pip._internal.network.session import PipSession
from tests.lib import TestData, make_test_link_collector
from tests.lib.path import Path


def _clean_link(url: str) -> str:
"""
Make sure a link is fully quoted.
For example, if ' ' occurs in the URL, it will be replaced with "%20",
and without double-quoting other characters.
"""
# Split the URL into parts according to the general structure
# `scheme://netloc/path;parameters?query#fragment`.
result = urllib.parse.urlparse(url)
# If the netloc is empty, then the URL refers to a local filesystem path.
is_local_path = not result.netloc
path = _clean_url_path(result.path, is_local_path=is_local_path)
return urllib.parse.urlunparse(result._replace(path=path))


@pytest.mark.parametrize(
"url",
[
Expand Down Expand Up @@ -414,7 +429,7 @@ def test_clean_url_path_with_local_path(path: str, expected: str) -> None:
],
)
def test_clean_link(url: str, clean_url: str) -> None:
assert _clean_link(Link(url)).parsed == urllib.parse.urlsplit(clean_url)
assert _clean_link(url) == clean_url


def _test_parse_links_data_attribute(
Expand Down

0 comments on commit 72d8357

Please sign in to comment.