|
| 1 | +"""Exercise candidate installation with an unpublished companion wheel.""" |
| 2 | + |
| 3 | +import sys |
| 4 | +from pathlib import Path |
| 5 | +from zipfile import ZipFile |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from scripts.release_performance._helpers.versions import install_wheel, installed_version |
| 10 | +from tests.integration.scripts.release_performance._test_types import LocalWheelTestCase |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.skipif(sys.platform == "win32", reason="Release comparison uses POSIX environments") |
| 14 | +@pytest.mark.parametrize( |
| 15 | + "test_case", |
| 16 | + [ |
| 17 | + LocalWheelTestCase( |
| 18 | + description="unpublished companion installs offline beside its candidate", |
| 19 | + version="0.1.0", |
| 20 | + expected_version="0.1.0", |
| 21 | + ) |
| 22 | + ], |
| 23 | + ids=lambda case: case.description, |
| 24 | +) |
| 25 | +def test_given_unpublished_companion_when_installing_candidate_then_resolves_local_wheel( |
| 26 | + test_case: LocalWheelTestCase, tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 27 | +) -> None: |
| 28 | + monkeypatch.setenv("UV_NO_INDEX", "1") |
| 29 | + wheels: Path = tmp_path / "wheels" |
| 30 | + wheels.mkdir() |
| 31 | + version: str = test_case.version |
| 32 | + for name, dependency, entry_points in ( |
| 33 | + ("sqlbuild", f"Requires-Dist: sqlbuild-cli=={version}\n", ""), |
| 34 | + ("sqlbuild_cli", "", "[console_scripts]\nsqb = sqlbuild_cli_probe:main\n"), |
| 35 | + ): |
| 36 | + metadata: str = f"Metadata-Version: 2.1\nName: {name}\nVersion: {version}\n{dependency}" |
| 37 | + with ZipFile(wheels / f"{name}-{version}-py3-none-any.whl", "w") as wheel: |
| 38 | + info: str = f"{name}-{version}.dist-info" |
| 39 | + wheel.writestr(f"{info}/METADATA", metadata) |
| 40 | + wheel.writestr( |
| 41 | + f"{info}/WHEEL", |
| 42 | + "Wheel-Version: 1.0\nGenerator: release-probe\n" |
| 43 | + "Root-Is-Purelib: true\nTag: py3-none-any\n", |
| 44 | + ) |
| 45 | + wheel.writestr(f"{info}/RECORD", "") |
| 46 | + wheel.writestr(f"{name}_probe.py", f"def main():\n print('sqlbuild {version}')\n") |
| 47 | + wheel.writestr(f"{info}/entry_points.txt", entry_points) |
| 48 | + sqb: Path = install_wheel( |
| 49 | + wheel=wheels / f"sqlbuild-{version}-py3-none-any.whl", |
| 50 | + venv_dir=tmp_path / "candidate", |
| 51 | + python=sys.executable, |
| 52 | + ) |
| 53 | + assert installed_version(sqb=sqb) == test_case.expected_version |
0 commit comments