|
| 1 | +"""End-to-end tests for the template customization script.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import shutil |
| 6 | +import subprocess |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | + |
| 10 | +REPO_ROOT = Path(__file__).resolve().parent.parent |
| 11 | + |
| 12 | + |
| 13 | +def _make_scaffold(tmp_path: Path, extra_pyproject: str = "") -> Path: |
| 14 | + root = tmp_path / "scaffold" |
| 15 | + (root / "bin").mkdir(parents=True) |
| 16 | + (root / "placeholder").mkdir() |
| 17 | + (root / "placeholder" / "module.py").write_text( |
| 18 | + "from placeholder.feature_groups import manifest\n", encoding="utf-8" |
| 19 | + ) |
| 20 | + shutil.copy2(REPO_ROOT / "bin" / "customize.sh", root / "bin" / "customize.sh") |
| 21 | + shutil.copy2(REPO_ROOT / "pyproject.toml", root / "pyproject.toml") |
| 22 | + shutil.copy2(REPO_ROOT / ".releaserc.yaml", root / ".releaserc.yaml") |
| 23 | + if extra_pyproject: |
| 24 | + pyproject = root / "pyproject.toml" |
| 25 | + pyproject.write_text( |
| 26 | + pyproject.read_text(encoding="utf-8") + extra_pyproject, |
| 27 | + encoding="utf-8", |
| 28 | + ) |
| 29 | + return root |
| 30 | + |
| 31 | + |
| 32 | +def _run_customize(root: Path, *args: str) -> subprocess.CompletedProcess[str]: |
| 33 | + return subprocess.run( |
| 34 | + ["bash", "bin/customize.sh", *args], |
| 35 | + cwd=root, |
| 36 | + capture_output=True, |
| 37 | + check=False, |
| 38 | + text=True, |
| 39 | + ) |
| 40 | + |
| 41 | + |
| 42 | +def test_optional_fields_can_be_left_for_manual_editing(tmp_path: Path) -> None: |
| 43 | + """Omitting optional flags does not make the scaffold command fail.""" |
| 44 | + root = _make_scaffold(tmp_path) |
| 45 | + |
| 46 | + result = _run_customize(root, "acme") |
| 47 | + |
| 48 | + assert result.returncode == 0, result.stdout + result.stderr |
| 49 | + assert (root / "acme").is_dir() |
| 50 | + |
| 51 | + |
| 52 | +def test_unexpected_entry_point_placeholder_still_fails(tmp_path: Path) -> None: |
| 53 | + """The stale-reference check still rejects a missed entry-point rename.""" |
| 54 | + root = _make_scaffold( |
| 55 | + tmp_path, |
| 56 | + '\n[project.entry-points."mloda.feature_groups.extra"]\nleftover = "placeholder.unrelated:FEATURE_GROUPS"\n', |
| 57 | + ) |
| 58 | + |
| 59 | + result = _run_customize(root, "acme") |
| 60 | + |
| 61 | + assert result.returncode == 1 |
| 62 | + assert "stale 'placeholder' references" in result.stderr |
0 commit comments