diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py index 0fc97b14c1c..577fa375697 100644 --- a/tests/unit/test_collector.py +++ b/tests/unit/test_collector.py @@ -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", [ @@ -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(