diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml new file mode 100644 index 0000000..0748299 --- /dev/null +++ b/.github/test_on_push.yml @@ -0,0 +1,55 @@ +name: Test template generation + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main +jobs: + style: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 + + - name: Check style + run: | + python -m pip install pre-commit + pre-commit run -a + + template_test: + needs: style + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-13, macos-14, windows-latest] + python-version: ["3.9", "3.10", "3.11", "3.12"] + name: + Template Tests (${{ matrix.os }} / Python ${{ matrix.python-version }}) + steps: + - name: Checkout pybamm-cookiecutter + uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + id: setup-python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: 'pip' + + - name: Set up uv + uses: yezz123/setup-uv@v4 + with: + uv-venv: ".venv" + + - name: Install nox + run: uv pip install nox[uv] + + - name: Test Template Generation + run: | + nox -s test-generation diff --git a/noxfile.py b/noxfile.py index 11cc5e0..a42638e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,6 +1,7 @@ import nox # Options to modify nox behaviour +nox.options.default_venv_backend = "uv|virtualenv" nox.options.reuse_existing_virtualenvs = True @nox.session(name="docs") @@ -18,3 +19,10 @@ def build_docs(session: nox.Session) -> None: ".", f"{envbindir}/../tmp/html", ) + +@nox.session(name="test-generation") +def run_template_generation(session): + """Run the tests for testing template generation""" + session.install("setuptools", silent=False) + session.install("-e", ".[dev]", silent=False) + session.run("pytest", "tests") diff --git a/pyproject.toml b/pyproject.toml index 21fe37f..a55dc6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,14 +30,15 @@ classifiers = [ "Typing :: Typed", ] dynamic = ["version"] -dependencies = ["pybamm"] +dependencies = ["pybamm", "cookiecutter"] [project.optional-dependencies] dev = [ "pytest >=6", "pytest-cov >=3", - "nox", + "nox[uv]", "pre-commit", + "pytest-cookies", ] docs = [ "sphinx", diff --git a/src/pybamm_cookiecutter/__init__.py b/src/pybamm_cookiecutter/__init__.py index 61c58e4..53e47d1 100644 --- a/src/pybamm_cookiecutter/__init__.py +++ b/src/pybamm_cookiecutter/__init__.py @@ -5,6 +5,10 @@ """ from __future__ import annotations +import pybamm + from ._version import version as __version__ -__all__ : tuple[str] = ("__version__",) +__all__ : list[str] = [ + "__version__", +] diff --git a/tests/test_package.py b/tests/test_package.py deleted file mode 100644 index 6202318..0000000 --- a/tests/test_package.py +++ /dev/null @@ -1,5 +0,0 @@ -import pybamm_cookiecutter as m - - -def test_version() -> None: - assert m.__version__ diff --git a/tests/test_project_generation.py b/tests/test_project_generation.py new file mode 100644 index 0000000..6e959d4 --- /dev/null +++ b/tests/test_project_generation.py @@ -0,0 +1,37 @@ +import pybamm_cookiecutter as m +import pytest +from pytest_cookies.plugin import Cookies + +def test_version() -> None: + assert m.__version__ + +def test_bake_project(cookies: Cookies): + """ + Testing the template generation with default values + """ + result = cookies.bake() + assert result.exit_code == 0, f"Exited with code {result.exit_code}, expected 0" + assert result.exception is None, result.exception + assert result.project_path.name == "pybamm-example-project" + assert result.project_path.is_dir(), f"Project directory {result.project_path} not found" + + +def test_bake_custom_project(cookies: Cookies): + """ + Testing the template generation with custom template and checking if the projects exists in the tmp_path + """ + result = cookies.bake(extra_context={ + "author_full_name": "pybamm_user", + "author_email": "pybamm@pybamm.org", + "project_name": "pybamm_cookie", + "project_slug": "example", + "project_short_description": "This is an example pybamm cookiecutter template", + "project_url": "pybamm.org", + "project_version": "0.1.0", + "documentation_engine": "sphinx(rst)", + }) + + assert result.exit_code == 0, f"Exited with code {result.exit_code}, expected 0" + assert result.exception is None, result.exception + assert result.project_path.name == "pybamm_cookie" + assert result.project_path.is_dir(), f"Project directory {result.project_path} not found"