|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from ..lib import PipTestEnvironment, TestData |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.usefixtures("with_wheel") |
| 10 | +def test_install_report_basic( |
| 11 | + script: PipTestEnvironment, shared_data: TestData, tmp_path: Path |
| 12 | +) -> None: |
| 13 | + report_path = tmp_path / "report.json" |
| 14 | + script.pip( |
| 15 | + "install", |
| 16 | + "simplewheel", |
| 17 | + "--dry-run", |
| 18 | + "--no-index", |
| 19 | + "--find-links", |
| 20 | + str(shared_data.root / "packages/"), |
| 21 | + "--report", |
| 22 | + str(report_path), |
| 23 | + ) |
| 24 | + report = json.loads(report_path.read_text()) |
| 25 | + assert "install" in report |
| 26 | + assert len(report["install"]) == 1 |
| 27 | + assert "simplewheel" in report["install"] |
| 28 | + simplewheel_report = report["install"]["simplewheel"] |
| 29 | + assert simplewheel_report["metadata"]["name"] == "simplewheel" |
| 30 | + assert simplewheel_report["requested"] is True |
| 31 | + assert simplewheel_report["is_direct"] is False |
| 32 | + url = simplewheel_report["download_info"]["url"] |
| 33 | + assert url.startswith("file://") |
| 34 | + assert url.endswith("/packages/simplewheel-2.0-1-py2.py3-none-any.whl") |
| 35 | + assert ( |
| 36 | + simplewheel_report["download_info"]["archive_info"]["hash"] |
| 37 | + == "sha256=191d6520d0570b13580bf7642c97ddfbb46dd04da5dd2cf7bef9f32391dfe716" |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.usefixtures("with_wheel") |
| 42 | +def test_install_report_dep( |
| 43 | + script: PipTestEnvironment, shared_data: TestData, tmp_path: Path |
| 44 | +) -> None: |
| 45 | + """Test dependencies are present in the install report with requested=False.""" |
| 46 | + report_path = tmp_path / "report.json" |
| 47 | + script.pip( |
| 48 | + "install", |
| 49 | + "require_simple", |
| 50 | + "--dry-run", |
| 51 | + "--no-index", |
| 52 | + "--find-links", |
| 53 | + str(shared_data.root / "packages/"), |
| 54 | + "--report", |
| 55 | + str(report_path), |
| 56 | + ) |
| 57 | + report = json.loads(report_path.read_text()) |
| 58 | + assert len(report["install"]) == 2 |
| 59 | + assert report["install"]["require-simple"]["requested"] is True |
| 60 | + assert report["install"]["simple"]["requested"] is False |
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.network |
| 64 | +@pytest.mark.usefixtures("with_wheel") |
| 65 | +def test_install_report_index(script: PipTestEnvironment, tmp_path: Path) -> None: |
| 66 | + """Test report for wheels obtained from index.""" |
| 67 | + report_path = tmp_path / "report.json" |
| 68 | + script.pip( |
| 69 | + "install", |
| 70 | + "--dry-run", |
| 71 | + "Paste[openid]==1.7.5.1", |
| 72 | + "--report", |
| 73 | + str(report_path), |
| 74 | + ) |
| 75 | + report = json.loads(report_path.read_text()) |
| 76 | + assert len(report["install"]) == 2 |
| 77 | + assert report["install"]["paste"]["requested"] is True |
| 78 | + assert report["install"]["python-openid"]["requested"] is False |
| 79 | + paste_report = report["install"]["paste"] |
| 80 | + assert paste_report["download_info"]["url"].startswith( |
| 81 | + "https://files.pythonhosted.org/" |
| 82 | + ) |
| 83 | + assert paste_report["download_info"]["url"].endswith("/Paste-1.7.5.1.tar.gz") |
| 84 | + assert ( |
| 85 | + paste_report["download_info"]["archive_info"]["hash"] |
| 86 | + == "sha256=11645842ba8ec986ae8cfbe4c6cacff5c35f0f4527abf4f5581ae8b4ad49c0b6" |
| 87 | + ) |
| 88 | + |
| 89 | + |
| 90 | +@pytest.mark.network |
| 91 | +@pytest.mark.usefixtures("with_wheel") |
| 92 | +def test_install_report_vcs_and_wheel_cache( |
| 93 | + script: PipTestEnvironment, tmp_path: Path |
| 94 | +) -> None: |
| 95 | + """Test report for wheels obtained from index.""" |
| 96 | + cache_dir = tmp_path / "cache" |
| 97 | + report_path = tmp_path / "report.json" |
| 98 | + script.pip( |
| 99 | + "install", |
| 100 | + "git+https://github.com/pypa/pip-test-package" |
| 101 | + "@5547fa909e83df8bd743d3978d6667497983a4b7", |
| 102 | + "--cache-dir", |
| 103 | + str(cache_dir), |
| 104 | + "--report", |
| 105 | + str(report_path), |
| 106 | + ) |
| 107 | + report = json.loads(report_path.read_text()) |
| 108 | + assert len(report["install"]) == 1 |
| 109 | + pip_test_package_report = report["install"]["pip-test-package"] |
| 110 | + assert pip_test_package_report["is_direct"] is True |
| 111 | + assert pip_test_package_report["requested"] is True |
| 112 | + assert ( |
| 113 | + pip_test_package_report["download_info"]["url"] |
| 114 | + == "https://github.com/pypa/pip-test-package" |
| 115 | + ) |
| 116 | + assert pip_test_package_report["download_info"]["vcs_info"]["vcs"] == "git" |
| 117 | + assert ( |
| 118 | + pip_test_package_report["download_info"]["vcs_info"]["commit_id"] |
| 119 | + == "5547fa909e83df8bd743d3978d6667497983a4b7" |
| 120 | + ) |
| 121 | + # Now do it again to make sure the cache is used and that the report still contains |
| 122 | + # the original VCS url. |
| 123 | + report_path.unlink() |
| 124 | + result = script.pip( |
| 125 | + "install", |
| 126 | + "pip-test-package @ git+https://github.com/pypa/pip-test-package" |
| 127 | + "@5547fa909e83df8bd743d3978d6667497983a4b7", |
| 128 | + "--ignore-installed", |
| 129 | + "--cache-dir", |
| 130 | + str(cache_dir), |
| 131 | + "--report", |
| 132 | + str(report_path), |
| 133 | + ) |
| 134 | + assert "Using cached pip_test_package" in result.stdout |
| 135 | + report = json.loads(report_path.read_text()) |
| 136 | + assert len(report["install"]) == 1 |
| 137 | + pip_test_package_report = report["install"]["pip-test-package"] |
| 138 | + assert pip_test_package_report["is_direct"] is True |
| 139 | + assert pip_test_package_report["requested"] is True |
| 140 | + assert ( |
| 141 | + pip_test_package_report["download_info"]["url"] |
| 142 | + == "https://github.com/pypa/pip-test-package" |
| 143 | + ) |
| 144 | + assert pip_test_package_report["download_info"]["vcs_info"]["vcs"] == "git" |
| 145 | + assert ( |
| 146 | + pip_test_package_report["download_info"]["vcs_info"]["commit_id"] |
| 147 | + == "5547fa909e83df8bd743d3978d6667497983a4b7" |
| 148 | + ) |
| 149 | + |
| 150 | + |
| 151 | +@pytest.mark.network |
| 152 | +@pytest.mark.usefixtures("with_wheel") |
| 153 | +def test_install_report_vcs_editable( |
| 154 | + script: PipTestEnvironment, tmp_path: Path |
| 155 | +) -> None: |
| 156 | + """Test report for wheels obtained from index.""" |
| 157 | + report_path = tmp_path / "report.json" |
| 158 | + script.pip( |
| 159 | + "install", |
| 160 | + "--editable", |
| 161 | + "git+https://github.com/pypa/pip-test-package" |
| 162 | + "@5547fa909e83df8bd743d3978d6667497983a4b7" |
| 163 | + "#egg=pip-test-package", |
| 164 | + "--report", |
| 165 | + str(report_path), |
| 166 | + ) |
| 167 | + report = json.loads(report_path.read_text()) |
| 168 | + assert len(report["install"]) == 1 |
| 169 | + pip_test_package_report = report["install"]["pip-test-package"] |
| 170 | + assert pip_test_package_report["is_direct"] is True |
| 171 | + assert pip_test_package_report["download_info"]["url"].startswith("file://") |
| 172 | + assert pip_test_package_report["download_info"]["url"].endswith( |
| 173 | + "/src/pip-test-package" |
| 174 | + ) |
| 175 | + assert pip_test_package_report["download_info"]["dir_info"]["editable"] is True |
0 commit comments