|
2 | 2 |
|
3 | 3 | import importlib.util |
4 | 4 | import json |
| 5 | +import os |
| 6 | +import shutil |
| 7 | +import subprocess |
5 | 8 | import sys |
6 | 9 | import types |
7 | 10 | from pathlib import Path |
@@ -61,6 +64,52 @@ def test_bump_version_computes_candidate_scope_without_mutating_pyproject( |
61 | 64 | assert module.infer_bump(changelog_dir) == "minor" |
62 | 65 |
|
63 | 66 |
|
| 67 | +def test_bump_version_script_runs_from_github_directory_without_installed_package( |
| 68 | + tmp_path, |
| 69 | +): |
| 70 | + repo = tmp_path / "repo" |
| 71 | + script_dir = repo / ".github" |
| 72 | + package_utils_dir = repo / "policyengine_us_data" / "utils" |
| 73 | + changelog_dir = repo / "changelog.d" |
| 74 | + script_dir.mkdir(parents=True) |
| 75 | + package_utils_dir.mkdir(parents=True) |
| 76 | + changelog_dir.mkdir() |
| 77 | + shutil.copyfile( |
| 78 | + REPO_ROOT / ".github" / "bump_version.py", script_dir / "bump_version.py" |
| 79 | + ) |
| 80 | + shutil.copyfile( |
| 81 | + REPO_ROOT / "policyengine_us_data" / "utils" / "run_context.py", |
| 82 | + package_utils_dir / "run_context.py", |
| 83 | + ) |
| 84 | + shutil.copyfile( |
| 85 | + REPO_ROOT / "policyengine_us_data" / "utils" / "canonical_json.py", |
| 86 | + package_utils_dir / "canonical_json.py", |
| 87 | + ) |
| 88 | + (repo / "policyengine_us_data" / "__init__.py").write_text("") |
| 89 | + (package_utils_dir / "__init__.py").write_text("") |
| 90 | + _write_pyproject(repo, "1.73.0") |
| 91 | + (changelog_dir / "123.added").write_text("Added a thing.\n") |
| 92 | + env = os.environ.copy() |
| 93 | + env.pop("PYTHONPATH", None) |
| 94 | + |
| 95 | + result = subprocess.run( |
| 96 | + [sys.executable, str(script_dir / "bump_version.py")], |
| 97 | + cwd=repo, |
| 98 | + env=env, |
| 99 | + text=True, |
| 100 | + capture_output=True, |
| 101 | + check=False, |
| 102 | + ) |
| 103 | + |
| 104 | + assert result.returncode == 0, result.stderr |
| 105 | + assert json.loads((script_dir / "publication_scope.json").read_text()) == { |
| 106 | + "base_release_version": "1.73.0", |
| 107 | + "candidate_scope": "1.73.0-minor", |
| 108 | + "release_bump": "minor", |
| 109 | + "would_release_as_at_build_time": "1.74.0", |
| 110 | + } |
| 111 | + |
| 112 | + |
64 | 113 | def test_fetch_publication_scope_prints_requested_field( |
65 | 114 | tmp_path, |
66 | 115 | monkeypatch, |
|
0 commit comments