40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Tests for rendering the project template."""
|
|
|
|
from new_python.render import DEFAULT_PYTHON, render
|
|
|
|
TEMPLATE_FILES = {
|
|
".gitignore",
|
|
"AGENTS.md",
|
|
"Pipfile",
|
|
"conftest.py",
|
|
"hooks/pre-commit",
|
|
"justfile",
|
|
"pyproject.toml",
|
|
}
|
|
|
|
TEMPLATE_TOKENS = ("{{PKG}}", "{{NAME}}", "{{PYVER}}")
|
|
|
|
|
|
def test_render_substitutes_all_tokens_for_a_dashed_name():
|
|
"""Rendering a dashed name derives the package and substitutes every token."""
|
|
files = render("demo-project")
|
|
|
|
assert set(files) == TEMPLATE_FILES | {"demo_project/__init__.py"}
|
|
assert files["demo_project/__init__.py"] == ""
|
|
|
|
justfile = files["justfile"]
|
|
assert justfile.count("demo_project") == 7
|
|
assert "{{args}}" in justfile
|
|
|
|
assert 'known_first_party = ["demo_project"]' in files["pyproject.toml"]
|
|
assert files["AGENTS.md"].startswith("# demo-project\n")
|
|
assert f'python_version = "{DEFAULT_PYTHON}"' in files["Pipfile"]
|
|
|
|
assert "Put the repo root on sys.path" in files["conftest.py"]
|
|
assert "__pycache__/" in files[".gitignore"]
|
|
assert "just ci" in files["hooks/pre-commit"]
|
|
|
|
for rel, content in files.items():
|
|
for token in TEMPLATE_TOKENS:
|
|
assert token not in content, f"{token} left unsubstituted in {rel}"
|