-
-
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.
Added tests for template generation (#9)
# Description - Added basic tests for template generation using `pytest-cookies`. - Added `cookiecutter` as a dependency and setup `___init.py__` for the src layout. --------- Co-authored-by: Arjun Verma <[email protected]> Co-authored-by: Saransh Chopra <[email protected]> Co-authored-by: Agriya Khetarpal <[email protected]>
- Loading branch information
1 parent
6ea83fd
commit dca6946
Showing
6 changed files
with
108 additions
and
8 deletions.
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 |
---|---|---|
@@ -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 |
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
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
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
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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": "[email protected]", | ||
"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" |