diff options
author | Stéphane Bidoul <stephane.bidoul@gmail.com> | 2023-04-11 14:41:36 +0200 |
---|---|---|
committer | Stéphane Bidoul <stephane.bidoul@gmail.com> | 2023-04-11 14:49:30 +0200 |
commit | 5119d4651e7881401315be7d262a19b762d636c0 (patch) | |
tree | 30da465538a45293eda57467d05e1d9e865a2804 /tests | |
parent | cdd9c95eacd58237f8dd800aa40756f9cf8e9b81 (diff) | |
download | pip-5119d4651e7881401315be7d262a19b762d636c0.tar.gz |
Improve conversion of direct_url.hash to hashes
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/test_direct_url.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/unit/test_direct_url.py b/tests/unit/test_direct_url.py index 3ca982b50..151e0a30f 100644 --- a/tests/unit/test_direct_url.py +++ b/tests/unit/test_direct_url.py @@ -140,3 +140,33 @@ def test_redact_url() -> None: == "https://${PIP_TOKEN}@g.c/u/p.git" ) assert _redact_git("ssh://git@g.c/u/p.git") == "ssh://git@g.c/u/p.git" + + +def test_hash_to_hashes() -> None: + direct_url = DirectUrl(url="https://e.c/archive.tar.gz", info=ArchiveInfo()) + assert isinstance(direct_url.info, ArchiveInfo) + direct_url.info.hash = "sha256=abcdef" + assert direct_url.info.hashes == {"sha256": "abcdef"} + + +def test_hash_to_hashes_constructor() -> None: + direct_url = DirectUrl( + url="https://e.c/archive.tar.gz", info=ArchiveInfo(hash="sha256=abcdef") + ) + assert isinstance(direct_url.info, ArchiveInfo) + assert direct_url.info.hashes == {"sha256": "abcdef"} + direct_url = DirectUrl( + url="https://e.c/archive.tar.gz", + info=ArchiveInfo(hash="sha256=abcdef", hashes={"sha512": "123456"}), + ) + assert isinstance(direct_url.info, ArchiveInfo) + assert direct_url.info.hashes == {"sha256": "abcdef", "sha512": "123456"} + # In case of conflict between hash and hashes, hashes wins. + direct_url = DirectUrl( + url="https://e.c/archive.tar.gz", + info=ArchiveInfo( + hash="sha256=abcdef", hashes={"sha256": "012345", "sha512": "123456"} + ), + ) + assert isinstance(direct_url.info, ArchiveInfo) + assert direct_url.info.hashes == {"sha256": "012345", "sha512": "123456"} |