Skip to content

Commit bc11f0e

Browse files
committed
added tests for template generation
1 parent eb9426b commit bc11f0e

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ classifiers = [
3030
"Typing :: Typed",
3131
]
3232
dynamic = ["version"]
33-
dependencies = ["pybamm"]
33+
dependencies = ["pybamm", "cookiecutter"]
3434

3535
[project.optional-dependencies]
3636
dev = [
3737
"pytest >=6",
3838
"pytest-cov >=3",
3939
"nox",
4040
"pre-commit",
41+
"pytest-cookies",
4142
]
4243
docs = [
4344
"sphinx",

src/pybamm_cookiecutter/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
"""
66
from __future__ import annotations
77

8+
import pybamm
9+
810
from ._version import version as __version__
911

10-
__all__ : tuple[str] = ("__version__",)
12+
__all__ : list[str] = [
13+
"__version__",
14+
"pybamm",
15+
]

tests/test_package.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/test_project_generation.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pybamm_cookiecutter as m
2+
import pytest
3+
4+
def test_version() -> None:
5+
assert m.__version__
6+
7+
@pytest.fixture
8+
def custom_template(tmpdir):
9+
"""
10+
Generating a project using the template into a tempdir
11+
"""
12+
template = tmpdir.ensure("cookiecutter-template", dir=True)
13+
template.join("cookiecutter.json").write('{"project_name": "pybamm_cookie"}')
14+
15+
repo_dir = template.ensure("{{cookiecutter.project_name}}", dir=True)
16+
repo_dir.join("README.rst").write("{{cookiecutter.project_name}}")
17+
18+
return template
19+
20+
21+
def test_bake_custom_project(cookies, custom_template):
22+
"""
23+
Testing if the projects exists in the tempdir
24+
"""
25+
result = cookies.bake(template=str(custom_template))
26+
27+
assert result.exit_code == 0
28+
assert result.exception is None
29+
30+
assert result.project_path.name == "pybamm_cookie"
31+
assert result.project_path.is_dir()

0 commit comments

Comments
 (0)