Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
"author_email": "",
"project_name": "",
"project_slug": "{{ cookiecutter.project_name|lower|replace('-', '_') }}",
"project_description": "",
"project_license": [
"GPL-3.0-or-later",
"GPL-3.0-only",
"LGPL-3.0-or-later",
"LGPL-3.0-only",
"BSD-3-Clause",
"MIT"
],
"enable_coverage": "yes",
"enable_pypi_publish": "no"
}
6 changes: 6 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
import shutil
import subprocess

TEMPLATE_ONLY_DATA = "cookiecutter_template_data"

# Remove template-only data files
shutil.rmtree(os.path.join(os.getcwd(), TEMPLATE_ONLY_DATA))

# Create empty git repository and add generated files
environ = os.environ.copy()
environ.update(
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ build-backend = "poetry.core.masonry.api"
name = "cookie-python"
version = "0.0.1"
description = ""
license = "GPL-3.0-or-later"
authors = ["Stephen Kent <smkent@smkent.net>"]
readme = "README.md"
classifiers = [
"Operating System :: OS Independent",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Libraries :: Python Modules",
]
packages = [
{ include = "{{cookiecutter.project_name}}" }
]
Expand Down
94 changes: 84 additions & 10 deletions tests/test_cookiecutter.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,102 @@
import datetime
import os
import subprocess
from typing import Any
from typing import Any, Dict

import pytest
import yaml

TEMPLATE_ONLY_DATA = "cookiecutter_template_data"

def test_bake_project(cookies: Any) -> None:
result = cookies.bake(
extra_context=dict(
author_name="Ness",
author_email="pk-fire@onett.example.com",
project_name="test-baked-cookie",
)
)

assert result.exit_code == 0
def _bake(cookies: Any, extra_context: Dict[str, Any]) -> Any:
result = cookies.bake(extra_context=extra_context)

assert not result.exception
assert result.exit_code == 0

assert result.project_path.name == "test-baked-cookie"
assert result.project_path.is_dir()

assert os.path.isdir(
os.path.join(result.project_path, "test_baked_cookie")
)
return result


@pytest.mark.parametrize(
"project_license",
[
"GPL-3.0-or-later",
"GPL-3.0-only",
"LGPL-3.0-or-later",
"LGPL-3.0-only",
"BSD-3-Clause",
"MIT",
],
)
def test_project_license(cookies: Any, project_license: str) -> None:
result = _bake(
cookies,
extra_context=dict(
author_name="Ness",
author_email="pk-fire@onett.example.com",
project_name="test-baked-cookie",
project_description=(
'This is a test project called "test-baked-cookie"'
),
project_license=project_license,
),
)

print(result.project_path)
print(os.listdir(result.project_path))
license_data = open(os.path.join(result.project_path, "LICENSE")).read()
expected_license_data = open(
os.path.join(
"{{cookiecutter.project_name}}",
TEMPLATE_ONLY_DATA,
"licenses",
project_license,
)
).read()

if project_license in ("MIT", "BSD-3-Clause"):
# Compare copyright line separately
if project_license == "MIT":
expected_copyright = "Copyright (c) {0} Ness".format(
datetime.date.today().year
)
elif project_license == "BSD-3-Clause":
expected_copyright = "Copyright (c) {0}, Ness".format(
datetime.date.today().year
)
assert license_data.splitlines()[0] == expected_copyright
license_data = os.linesep.join(license_data.split(os.linesep)[1:])
expected_license_data = os.linesep.join(
expected_license_data.split(os.linesep)[1:]
)

if project_license == "BSD-3-Clause":
expected_license_data = expected_license_data.replace(
"{{ cookiecutter.project_name }}", "test-baked-cookie"
)

assert license_data == expected_license_data


def test_rendered_project(cookies: Any) -> None:
result = _bake(
cookies,
extra_context=dict(
author_name="Ness",
author_email="pk-fire@onett.example.com",
project_name="test-baked-cookie",
project_description=(
'This is a test project called "test-baked-cookie"'
),
),
)

# Validate CI configuration
data = yaml.safe_load(
Expand Down
Loading