summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStéphane Bidoul <stephane.bidoul@gmail.com>2023-04-10 11:23:24 +0200
committerGitHub <noreply@github.com>2023-04-10 11:23:24 +0200
commit42b19abb69cbaee09c08a1d9c316553319677e20 (patch)
tree1b5b0b666c87efffa5ef73858f0b42497ed80777 /tests
parentaebc0c5fc321141ede837c80572427ab7b795c3f (diff)
parent89e7208784905d7db6b3bfe75f8be00cc8f65895 (diff)
downloadpip-42b19abb69cbaee09c08a1d9c316553319677e20.tar.gz
Merge pull request #11936 from sbidoul/fix-link-hash-parsing
Various fixes to the link hash parser
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test_collector.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/tests/unit/test_collector.py b/tests/unit/test_collector.py
index 26a2ce4b9..e855d78e1 100644
--- a/tests/unit/test_collector.py
+++ b/tests/unit/test_collector.py
@@ -1052,6 +1052,21 @@ def test_link_collector_create_find_links_expansion(
LinkHash("sha256", "aa113592bbe"),
),
(
+ "https://pypi.org/pip-18.0.tar.gz#sha256=aa113592bbe&subdirectory=setup",
+ LinkHash("sha256", "aa113592bbe"),
+ ),
+ (
+ "https://pypi.org/pip-18.0.tar.gz#subdirectory=setup&sha256=aa113592bbe",
+ LinkHash("sha256", "aa113592bbe"),
+ ),
+ # "xsha256" is not a valid algorithm, so we discard it.
+ ("https://pypi.org/pip-18.0.tar.gz#xsha256=aa113592bbe", None),
+ # Empty hash.
+ (
+ "https://pypi.org/pip-18.0.tar.gz#sha256=",
+ LinkHash("sha256", ""),
+ ),
+ (
"https://pypi.org/pip-18.0.tar.gz#md5=aa113592bbe",
LinkHash("md5", "aa113592bbe"),
),
@@ -1061,4 +1076,21 @@ def test_link_collector_create_find_links_expansion(
],
)
def test_link_hash_parsing(url: str, result: Optional[LinkHash]) -> None:
- assert LinkHash.split_hash_name_and_value(url) == result
+ assert LinkHash.find_hash_url_fragment(url) == result
+
+
+@pytest.mark.parametrize(
+ "dist_info_metadata, result",
+ [
+ ("sha256=aa113592bbe", LinkHash("sha256", "aa113592bbe")),
+ ("sha256=", LinkHash("sha256", "")),
+ ("sha500=aa113592bbe", None),
+ ("true", None),
+ ("", None),
+ ("aa113592bbe", None),
+ ],
+)
+def test_pep658_hash_parsing(
+ dist_info_metadata: str, result: Optional[LinkHash]
+) -> None:
+ assert LinkHash.parse_pep658_hash(dist_info_metadata) == result