-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure 'package_name' always uses underscores
Without this fix, entering 'my-package' as the project name results in a directory called 'src/my-package', which is not importable in Python. Also adds a test.
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"project_name": "My Project", | ||
"__project_slug": "{{cookiecutter.project_name|lower|replace(' ', '-')}}", | ||
"__package_name": "{{cookiecutter.project_name|lower|replace(' ', '_')}}", | ||
"__package_name": "{{cookiecutter.project_name|lower|replace(' ', '_')|replace('-', '_')}}", | ||
"short_description": "", | ||
"author": "Mozilla Release Engineering <[email protected]>", | ||
"github_slug": "mozilla-releng/{{cookiecutter.__project_slug}}", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
from pprint import pprint | ||
|
||
import pytest | ||
from cookiecutter.generate import generate_context | ||
from cookiecutter.prompt import prompt_for_config | ||
|
||
|
||
def test_generated_files(reps_new): | ||
name = "foo" | ||
expected = [ | ||
|
@@ -48,3 +55,45 @@ def test_generated_files(reps_new): | |
actual.append(str(path.relative_to(project))) | ||
|
||
assert sorted(actual) == sorted(expected) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"extra_context,expected", | ||
( | ||
pytest.param( | ||
{"project_name": "My Package"}, | ||
{ | ||
"__project_slug": "my-package", | ||
"__package_name": "my_package", | ||
"short_description": "", | ||
"author": "Mozilla Release Engineering <[email protected]>", | ||
"github_slug": "mozilla-releng/my-package", | ||
"min_python_version": "3.7", | ||
"__min_tox_python_version": "37", | ||
"__max_tox_python_version": "311", | ||
"trust_domain": "mozilla", | ||
"trust_project": "my-package", | ||
"level": "1", | ||
"__codecov_secrets_path": "project/mozilla/my-package/level-any/codecov", # noqa | ||
"_copy_without_render": [".github/workflows/codeql-analysis.yml"], | ||
}, | ||
id="defaults", | ||
), | ||
pytest.param( | ||
{"project_name": "foo-bar"}, | ||
{"__package_name": "foo_bar"}, | ||
id="package_name_normalized", | ||
), | ||
), | ||
) | ||
def test_cookiecutter_json(project_root, extra_context, expected): | ||
cookiecutter_json = ( | ||
project_root / "reps" / "templates" / "python" / "cookiecutter.json" | ||
) | ||
context = generate_context(cookiecutter_json, extra_context=extra_context) | ||
config = prompt_for_config(context, no_input=True) | ||
pprint(config, indent=2) | ||
|
||
for key, val in expected.items(): | ||
assert key in config | ||
assert config[key] == val |