73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""Tests for the full scaffold flow."""
|
|
|
|
import subprocess
|
|
|
|
import pytest
|
|
|
|
from new_python.render import DEFAULT_PYTHON
|
|
from new_python.scaffold import INITIAL_COMMIT_MESSAGE, ScaffoldError, scaffold
|
|
|
|
|
|
def test_scaffold_creates_the_full_project(stubs, calls, parent):
|
|
"""Scaffold writes the template, inits git, pins pipenv, commits, installs hooks."""
|
|
target = scaffold("demo-project", parent=parent)
|
|
|
|
assert target == parent / "demo-project"
|
|
assert (target / "AGENTS.md").read_text().startswith("# demo-project\n")
|
|
assert (target / "demo_project" / "__init__.py").exists()
|
|
assert (target / ".git").is_dir()
|
|
assert (target / "hooks" / "pre-commit").stat().st_mode & 0o111
|
|
|
|
subject = subprocess.run(
|
|
["git", "-C", str(target), "log", "--format=%s"],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
assert subject.stdout.strip() == INITIAL_COMMIT_MESSAGE
|
|
status = subprocess.run(
|
|
["git", "-C", str(target), "status", "--porcelain"],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True,
|
|
)
|
|
assert status.stdout == ""
|
|
|
|
assert calls(stubs.pyenv) == [["prefix", DEFAULT_PYTHON]]
|
|
assert calls(stubs.pipenv) == [["install", "--dev", "--python", DEFAULT_PYTHON]]
|
|
assert calls(stubs.just) == [["install-hooks"]]
|
|
|
|
|
|
def test_scaffold_passes_packages_to_a_second_pipenv_call(stubs, calls, parent):
|
|
"""Runtime packages reach pipenv after the dev environment install."""
|
|
scaffold("demo-project", packages=["mutagen"], parent=parent)
|
|
|
|
assert calls(stubs.pipenv) == [
|
|
["install", "--dev", "--python", DEFAULT_PYTHON],
|
|
["install", "mutagen"],
|
|
]
|
|
|
|
|
|
def test_scaffold_refuses_missing_python_before_creating_anything(stub_cmd, parent):
|
|
"""An unavailable python pin refuses loudly and creates nothing."""
|
|
stub_cmd("pyenv", exit_code=1)
|
|
stub_cmd("pipenv")
|
|
stub_cmd("just")
|
|
|
|
with pytest.raises(ScaffoldError) as exc:
|
|
scaffold("demo-project", parent=parent)
|
|
|
|
assert f"pyenv install {DEFAULT_PYTHON}" in str(exc.value)
|
|
assert not (parent / "demo-project").exists()
|
|
|
|
|
|
def test_scaffold_refuses_invalid_names_first(stub_cmd, parent):
|
|
"""An invalid name refuses before any other work happens."""
|
|
pyenv = stub_cmd("pyenv")
|
|
|
|
with pytest.raises(ScaffoldError):
|
|
scaffold("Demo-Project", parent=parent)
|
|
|
|
assert not pyenv.exists()
|
|
assert not (parent / "Demo-Project").exists()
|