|
| 1 | +import importlib.util |
| 2 | +import json |
| 3 | +from pathlib import Path |
| 4 | +from typing import Any |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | + |
| 9 | +def load_merge_upload_module(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Any: |
| 10 | + for name in ( |
| 11 | + "INDEX_FILE", |
| 12 | + "LOCAL_INDEX", |
| 13 | + "MAKECAT", |
| 14 | + "MANIFEST_FILE", |
| 15 | + "NO_UPLOAD", |
| 16 | + "PLINK", |
| 17 | + "PSCP", |
| 18 | + "SIGN_COMMAND", |
| 19 | + "UPLOAD_HOST", |
| 20 | + "UPLOAD_HOST_KEY", |
| 21 | + "UPLOAD_KEYFILE", |
| 22 | + "UPLOAD_PATH_PREFIX", |
| 23 | + "UPLOAD_URL_PREFIX", |
| 24 | + "UPLOAD_USER", |
| 25 | + ): |
| 26 | + monkeypatch.delenv(name, raising=False) |
| 27 | + |
| 28 | + monkeypatch.chdir(tmp_path) |
| 29 | + script = Path(__file__).parents[1] / "windows-release" / "merge-and-upload.py" |
| 30 | + spec = importlib.util.spec_from_file_location("merge_and_upload_for_test", script) |
| 31 | + assert spec is not None |
| 32 | + assert spec.loader is not None |
| 33 | + module = importlib.util.module_from_spec(spec) |
| 34 | + |
| 35 | + with pytest.raises(SystemExit) as exc_info: |
| 36 | + spec.loader.exec_module(module) |
| 37 | + |
| 38 | + assert exc_info.value.code == 1 |
| 39 | + return module |
| 40 | + |
| 41 | + |
| 42 | +def test_calculate_uploads_uses_full_artifact_sbom_name( |
| 43 | + monkeypatch: pytest.MonkeyPatch, tmp_path: Path |
| 44 | +) -> None: |
| 45 | + module = load_merge_upload_module(monkeypatch, tmp_path) |
| 46 | + artifact = tmp_path / "python-3.14.0-amd64.exe" |
| 47 | + sbom = tmp_path / "python-3.14.0-amd64.exe.spdx.json" |
| 48 | + artifact.write_bytes(b"installer") |
| 49 | + sbom.write_text("{}", encoding="utf-8") |
| 50 | + (tmp_path / "__install__.amd64.json").write_text( |
| 51 | + json.dumps( |
| 52 | + { |
| 53 | + "url": ( |
| 54 | + "https://www.python.org/ftp/python/3.14.0/python-3.14.0-amd64.exe" |
| 55 | + ) |
| 56 | + } |
| 57 | + ), |
| 58 | + encoding="utf-8", |
| 59 | + ) |
| 60 | + |
| 61 | + uploads = list(module.calculate_uploads()) |
| 62 | + |
| 63 | + assert len(uploads) == 1 |
| 64 | + _, _, _, upload_sbom, sbom_dest = uploads[0] |
| 65 | + assert upload_sbom == sbom |
| 66 | + assert ( |
| 67 | + sbom_dest |
| 68 | + == "/srv/www.python.org/ftp/python/3.14.0/python-3.14.0-amd64.exe.spdx.json" |
| 69 | + ) |
0 commit comments