From bc11f0ee66f88dc0bab9d842dcc19d178a89d931 Mon Sep 17 00:00:00 2001 From: Santhosh Sundaram Date: Fri, 31 May 2024 22:22:35 +0530 Subject: [PATCH 01/10] added tests for template generation --- pyproject.toml | 3 ++- src/pybamm_cookiecutter/__init__.py | 7 ++++++- tests/test_package.py | 5 ----- tests/test_project_generation.py | 31 +++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) delete mode 100644 tests/test_package.py create mode 100644 tests/test_project_generation.py diff --git a/pyproject.toml b/pyproject.toml index 21fe37f..126d127 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ "Typing :: Typed", ] dynamic = ["version"] -dependencies = ["pybamm"] +dependencies = ["pybamm", "cookiecutter"] [project.optional-dependencies] dev = [ @@ -38,6 +38,7 @@ dev = [ "pytest-cov >=3", "nox", "pre-commit", + "pytest-cookies", ] docs = [ "sphinx", diff --git a/src/pybamm_cookiecutter/__init__.py b/src/pybamm_cookiecutter/__init__.py index 61c58e4..678b215 100644 --- a/src/pybamm_cookiecutter/__init__.py +++ b/src/pybamm_cookiecutter/__init__.py @@ -5,6 +5,11 @@ """ from __future__ import annotations +import pybamm + from ._version import version as __version__ -__all__ : tuple[str] = ("__version__",) +__all__ : list[str] = [ + "__version__", + "pybamm", +] 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..34827ae --- /dev/null +++ b/tests/test_project_generation.py @@ -0,0 +1,31 @@ +import pybamm_cookiecutter as m +import pytest + +def test_version() -> None: + assert m.__version__ + +@pytest.fixture +def custom_template(tmpdir): + """ + Generating a project using the template into a tempdir + """ + template = tmpdir.ensure("cookiecutter-template", dir=True) + template.join("cookiecutter.json").write('{"project_name": "pybamm_cookie"}') + + repo_dir = template.ensure("{{cookiecutter.project_name}}", dir=True) + repo_dir.join("README.rst").write("{{cookiecutter.project_name}}") + + return template + + +def test_bake_custom_project(cookies, custom_template): + """ + Testing if the projects exists in the tempdir + """ + result = cookies.bake(template=str(custom_template)) + + assert result.exit_code == 0 + assert result.exception is None + + assert result.project_path.name == "pybamm_cookie" + assert result.project_path.is_dir() From 7055ba0a6ad533eb427464e5e009c3e6d35d4240 Mon Sep 17 00:00:00 2001 From: Santhosh <52504160+santacodes@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:22:13 +0530 Subject: [PATCH 02/10] Apply suggestions from code review Co-authored-by: Arjun Verma --- tests/test_project_generation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_project_generation.py b/tests/test_project_generation.py index 34827ae..a4f1b96 100644 --- a/tests/test_project_generation.py +++ b/tests/test_project_generation.py @@ -1,5 +1,6 @@ import pybamm_cookiecutter as m import pytest +from pytest_cookies.plugin import Cookies def test_version() -> None: assert m.__version__ @@ -18,7 +19,7 @@ def custom_template(tmpdir): return template -def test_bake_custom_project(cookies, custom_template): +def test_bake_custom_project(cookies: Cookies, custom_template): """ Testing if the projects exists in the tempdir """ From 13e225176653fa62daa8e6a1859caedc3c728a87 Mon Sep 17 00:00:00 2001 From: Santhosh Sundaram Date: Sun, 9 Jun 2024 19:14:16 +0530 Subject: [PATCH 03/10] added assertion logs --- tests/test_project_generation.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_project_generation.py b/tests/test_project_generation.py index a4f1b96..e2e40f0 100644 --- a/tests/test_project_generation.py +++ b/tests/test_project_generation.py @@ -24,9 +24,7 @@ def test_bake_custom_project(cookies: Cookies, custom_template): Testing if the projects exists in the tempdir """ result = cookies.bake(template=str(custom_template)) - - assert result.exit_code == 0 - assert result.exception is None - + assert result.exit_code == 0, "Exited with code 0" + assert result.exception is None, result.exception assert result.project_path.name == "pybamm_cookie" - assert result.project_path.is_dir() + assert result.project_path.is_dir(), "Project directory not found" From 647504352ca058b24a82e864ee3ddddfd8ba2b1f Mon Sep 17 00:00:00 2001 From: Santhosh Sundaram Date: Sun, 9 Jun 2024 22:43:52 +0530 Subject: [PATCH 04/10] added tests for template generation in ci --- .github/test_on_push.yml | 53 ++++++++++++++++++++++++++++++++++++++++ noxfile.py | 10 ++++++++ 2 files changed, 63 insertions(+) create mode 100644 .github/test_on_push.yml diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml new file mode 100644 index 0000000..fb27754 --- /dev/null +++ b/.github/test_on_push.yml @@ -0,0 +1,53 @@ +name: pybamm_cookiecutter + +on: + workflow_dispatch: + pull_request: + +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-12, 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 + + - name: Test Template Generation + run: | + nox -s test-generation diff --git a/noxfile.py b/noxfile.py index 11cc5e0..35c1e43 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,12 @@ def build_docs(session: nox.Session) -> None: ".", f"{envbindir}/../tmp/html", ) + +@nox.session(name="test-generation") +def run_template_generation(session): + """Run the tests tests for testing template generation""" + session.install("setuptools", silent=False) + session.install("pytest", silent=False) + session.install("pytest-cookies", silent=False) + session.install("-e", ".", silent=False) + session.run("pytest", "tests") From bb87ed6857d6f131ba1b931865abefc3615296dc Mon Sep 17 00:00:00 2001 From: Santhosh <52504160+santacodes@users.noreply.github.com> Date: Mon, 10 Jun 2024 19:28:47 +0530 Subject: [PATCH 05/10] Apply suggestions from code review Co-authored-by: Saransh Chopra --- noxfile.py | 4 +--- src/pybamm_cookiecutter/__init__.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index 35c1e43..37a6e72 100644 --- a/noxfile.py +++ b/noxfile.py @@ -24,7 +24,5 @@ def build_docs(session: nox.Session) -> None: def run_template_generation(session): """Run the tests tests for testing template generation""" session.install("setuptools", silent=False) - session.install("pytest", silent=False) - session.install("pytest-cookies", silent=False) - session.install("-e", ".", silent=False) + session.install("-e", ".[dev]", silent=False) session.run("pytest", "tests") diff --git a/src/pybamm_cookiecutter/__init__.py b/src/pybamm_cookiecutter/__init__.py index 678b215..53e47d1 100644 --- a/src/pybamm_cookiecutter/__init__.py +++ b/src/pybamm_cookiecutter/__init__.py @@ -11,5 +11,4 @@ __all__ : list[str] = [ "__version__", - "pybamm", ] From e645022d2d22e34135096cbbd2c36b65e25a14b0 Mon Sep 17 00:00:00 2001 From: Santhosh Sundaram Date: Mon, 10 Jun 2024 19:32:18 +0530 Subject: [PATCH 06/10] added push on main branch ci job --- .github/test_on_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml index fb27754..f052dfd 100644 --- a/.github/test_on_push.yml +++ b/.github/test_on_push.yml @@ -3,7 +3,7 @@ name: pybamm_cookiecutter on: workflow_dispatch: pull_request: - + push: [main] jobs: style: runs-on: ubuntu-latest From bad7af8f6af6fa9214c2533ca9f21b6091802f69 Mon Sep 17 00:00:00 2001 From: Santhosh <52504160+santacodes@users.noreply.github.com> Date: Wed, 12 Jun 2024 14:30:27 +0530 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Arjun Verma --- .github/test_on_push.yml | 4 +++- tests/test_project_generation.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml index f052dfd..edc07bd 100644 --- a/.github/test_on_push.yml +++ b/.github/test_on_push.yml @@ -3,7 +3,9 @@ name: pybamm_cookiecutter on: workflow_dispatch: pull_request: - push: [main] + push: + branches: + - main jobs: style: runs-on: ubuntu-latest diff --git a/tests/test_project_generation.py b/tests/test_project_generation.py index e2e40f0..d87aa56 100644 --- a/tests/test_project_generation.py +++ b/tests/test_project_generation.py @@ -24,7 +24,7 @@ def test_bake_custom_project(cookies: Cookies, custom_template): Testing if the projects exists in the tempdir """ result = cookies.bake(template=str(custom_template)) - assert result.exit_code == 0, "Exited with code 0" + 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(), "Project directory not found" + assert result.project_path.is_dir(), f"Project directory {result.project_path} not found" From 0e2683d02cc9015375b39063233bd889847921a2 Mon Sep 17 00:00:00 2001 From: Santhosh <52504160+santacodes@users.noreply.github.com> Date: Wed, 12 Jun 2024 15:19:48 +0530 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --- .github/test_on_push.yml | 6 +++--- noxfile.py | 2 +- pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml index edc07bd..3755c74 100644 --- a/.github/test_on_push.yml +++ b/.github/test_on_push.yml @@ -1,4 +1,4 @@ -name: pybamm_cookiecutter +name: Test template generation on: workflow_dispatch: @@ -27,12 +27,12 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-12, macos-14, windows-latest] + 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 + - name: Checkout pybamm-cookiecutter uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} diff --git a/noxfile.py b/noxfile.py index 37a6e72..a42638e 100644 --- a/noxfile.py +++ b/noxfile.py @@ -22,7 +22,7 @@ def build_docs(session: nox.Session) -> None: @nox.session(name="test-generation") def run_template_generation(session): - """Run the tests tests for testing template generation""" + """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 126d127..a55dc6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = ["pybamm", "cookiecutter"] dev = [ "pytest >=6", "pytest-cov >=3", - "nox", + "nox[uv]", "pre-commit", "pytest-cookies", ] From 2f51084ec3229e16ed558c36e820deef8bf24220 Mon Sep 17 00:00:00 2001 From: Santhosh Sundaram Date: Wed, 12 Jun 2024 20:58:07 +0530 Subject: [PATCH 09/10] modified test cases for bake() --- tests/test_project_generation.py | 33 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/test_project_generation.py b/tests/test_project_generation.py index d87aa56..6e959d4 100644 --- a/tests/test_project_generation.py +++ b/tests/test_project_generation.py @@ -5,25 +5,32 @@ def test_version() -> None: assert m.__version__ -@pytest.fixture -def custom_template(tmpdir): +def test_bake_project(cookies: Cookies): """ - Generating a project using the template into a tempdir + Testing the template generation with default values """ - template = tmpdir.ensure("cookiecutter-template", dir=True) - template.join("cookiecutter.json").write('{"project_name": "pybamm_cookie"}') - - repo_dir = template.ensure("{{cookiecutter.project_name}}", dir=True) - repo_dir.join("README.rst").write("{{cookiecutter.project_name}}") - - return template + 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, custom_template): +def test_bake_custom_project(cookies: Cookies): """ - Testing if the projects exists in the tempdir + Testing the template generation with custom template and checking if the projects exists in the tmp_path """ - result = cookies.bake(template=str(custom_template)) + 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" From 0cacd051a67f58f94aeb38b9d620ef6253b67757 Mon Sep 17 00:00:00 2001 From: Arjun Verma Date: Thu, 13 Jun 2024 21:19:47 +0530 Subject: [PATCH 10/10] Update .github/test_on_push.yml Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> --- .github/test_on_push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/test_on_push.yml b/.github/test_on_push.yml index 3755c74..0748299 100644 --- a/.github/test_on_push.yml +++ b/.github/test_on_push.yml @@ -48,7 +48,7 @@ jobs: uv-venv: ".venv" - name: Install nox - run: uv pip install nox + run: uv pip install nox[uv] - name: Test Template Generation run: |