Skip to content

Commit 8f6814d

Browse files
committed
!squash
1 parent 447e57b commit 8f6814d

File tree

5 files changed

+379
-5
lines changed

5 files changed

+379
-5
lines changed

cookiecutter.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author_email": "your.email@example.com",
99
"github_username": "username",
1010
"github_repo": "{{ cookiecutter.project_slug }}",
11-
"version": "0.0.1",
11+
"version": "0.1.0",
1212
"python_version": "3.9",
1313
"license": ["MIT", "BSD-3", "GPL-3.0", "Apache-2.0"],
1414
"include_docs": ["y", "n"],

hooks/post_gen_project.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def generate_apache2_license():
142142
# Create a basic test file
143143
with open("tests/test_cli.py", "w") as f:
144144
f.write("""#!/usr/bin/env python
145-
"""Test CLI for {{cookiecutter.package_name}}."""
145+
\"\"\"Test CLI for {{cookiecutter.package_name}}.\"\"\"
146146
147147
from __future__ import annotations
148148
@@ -157,7 +157,7 @@ def generate_apache2_license():
157157
158158
159159
def test_run():
160-
"""Test run."""
160+
\"\"\"Test run.\"\"\"
161161
# Test that the function doesn't error
162162
proc = {{cookiecutter.package_name}}.run(cmd="echo", cmd_args=["hello"])
163163
assert proc is None
@@ -216,10 +216,10 @@ def test_run():
216216
217217
steps:
218218
- uses: actions/checkout@v3
219-
- name: Set up Python ${{ matrix.python-version }}
219+
- name: Set up Python ${{ "{{" }} matrix.python-version {{ "}}" }}
220220
uses: actions/setup-python@v4
221221
with:
222-
python-version: ${{ matrix.python-version }}
222+
python-version: ${{ "{{" }} matrix.python-version {{ "}}" }}
223223
- name: Install dependencies
224224
run: |
225225
python -m pip install --upgrade pip

tests/README.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Testing the Cookiecutter Template
2+
3+
This directory contains tests for the cookiecutter template. The tests use [pytest-cookies](https://github.com/hackebrot/pytest-cookies), a pytest plugin for testing cookiecutter templates.
4+
5+
## Running the Tests
6+
7+
1. Install pytest and pytest-cookies:
8+
9+
```bash
10+
pip install pytest pytest-cookies
11+
```
12+
13+
2. Run the tests:
14+
15+
```bash
16+
pytest -xvs tests/test_cookiecutter.py
17+
```
18+
19+
Alternatively, if you're using `uv` (the fast Python package installer and resolver):
20+
21+
```bash
22+
uv run pytest -xvs tests/test_cookiecutter.py
23+
```
24+
25+
## Test Overview
26+
27+
The tests in `test_cookiecutter.py` cover the following scenarios:
28+
29+
1. **Default template generation**: Tests that the template generates correctly with default values.
30+
2. **Test execution in generated project**: Tests that the generated project's own tests run successfully.
31+
3. **VCS path registry**: Tests proper configuration of supported version control systems.
32+
4. **License file generation**: Tests that the correct license file is generated based on selection.
33+
5. **GitHub Actions workflow creation**: Tests optional GitHub Actions workflow generation.
34+
6. **Documentation creation**: Tests optional documentation generation.
35+
7. **pyproject.toml configuration**: Tests proper project metadata configuration.
36+
8. **README badge inclusion**: Tests conditional inclusion of status badges in README.
37+
9. **Package structure**: Tests proper Python package directory structure.
38+
39+
## Debugging
40+
41+
If you encounter issues with the tests, you can keep the generated projects for inspection by adding the `--keep-baked-projects` flag:
42+
43+
```bash
44+
pytest -xvs tests/test_cookiecutter.py --keep-baked-projects
45+
```
46+
47+
This can be helpful for debugging test failures as you can inspect the actual generated files.

0 commit comments

Comments
 (0)