diff options
author | Stéphane Bidoul <stephane.bidoul@gmail.com> | 2023-04-14 08:02:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-14 08:02:57 +0200 |
commit | f7787f8798712e475ebbf71f5487f92158f043a9 (patch) | |
tree | 2d84dd527b2e9324aa8358a4356cffae6ce3bf11 /tests | |
parent | 5d3f24dac1c461ec095d879aa4984ae09916be88 (diff) | |
parent | 030d2d425b0919dc3ca81820e110aabbddb2ef77 (diff) | |
download | pip-f7787f8798712e475ebbf71f5487f92158f043a9.tar.gz |
Merge pull request #11949 from sbidoul/hash2hashes-sbi
Generate download_info.info.hashes in install report for direct URL archives
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/test_install_report.py | 33 | ||||
-rw-r--r-- | tests/unit/test_direct_url.py | 30 |
2 files changed, 63 insertions, 0 deletions
diff --git a/tests/functional/test_install_report.py b/tests/functional/test_install_report.py index b8df6936f..003b29d38 100644 --- a/tests/functional/test_install_report.py +++ b/tests/functional/test_install_report.py @@ -94,6 +94,39 @@ def test_install_report_index(script: PipTestEnvironment, tmp_path: Path) -> Non @pytest.mark.network +def test_install_report_direct_archive( + script: PipTestEnvironment, tmp_path: Path, shared_data: TestData +) -> None: + """Test report for direct URL archive.""" + report_path = tmp_path / "report.json" + script.pip( + "install", + str(shared_data.root / "packages" / "simplewheel-1.0-py2.py3-none-any.whl"), + "--dry-run", + "--no-index", + "--report", + str(report_path), + ) + report = json.loads(report_path.read_text()) + assert "install" in report + assert len(report["install"]) == 1 + simplewheel_report = _install_dict(report)["simplewheel"] + assert simplewheel_report["metadata"]["name"] == "simplewheel" + assert simplewheel_report["requested"] is True + assert simplewheel_report["is_direct"] is True + url = simplewheel_report["download_info"]["url"] + assert url.startswith("file://") + assert url.endswith("/packages/simplewheel-1.0-py2.py3-none-any.whl") + assert ( + simplewheel_report["download_info"]["archive_info"]["hash"] + == "sha256=e63aa139caee941ec7f33f057a5b987708c2128238357cf905429846a2008718" + ) + assert simplewheel_report["download_info"]["archive_info"]["hashes"] == { + "sha256": "e63aa139caee941ec7f33f057a5b987708c2128238357cf905429846a2008718" + } + + +@pytest.mark.network def test_install_report_vcs_and_wheel_cache( script: PipTestEnvironment, tmp_path: Path ) -> None: 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"} |