Skip to content

Commit

Permalink
Update template tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rly committed Oct 22, 2023
1 parent 6df91a5 commit 6d3e423
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 44 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ jobs:
- name: Evaluate template from local source
run: |
cookiecutter -v --no-input --output-dir ./out .
# cookiecutter -v --no-input --output-dir "$(Agent.BuildDirectory)" .
- name: Check files
- name: Check files and run local tests
run: |
python tests/test_template_evaluation.py ./out/ndx-my-namespace/ ndx-my-namespace
# python tests/test_template_evaluation.py "$(Agent.BuildDirectory)/ndx-my-namespace/" "ndx-my-namespace"
python -m pip install pytest pytest-cookies
pytest tests
python tests/test_back_project.py ./out/ndx-my-namespace/ ndx-my-namespace
- name: Run PyNWB tests from generated extension
run: |
Expand Down
8 changes: 0 additions & 8 deletions test.py

This file was deleted.

61 changes: 61 additions & 0 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Test evaluating (baking) the template. Requires pytest-cookies to be installed."""
import os
import sys


def test_bake_project(cookies):
"""Test evaluating the template with default values."""
sys.path.insert(0, ".")
result = cookies.bake()

assert result.exit_code == 0
assert result.exception is None

assert result.project_path.name == "ndx-my-namespace"
assert result.project_path.is_dir()

_check_gen_files(result.project_path, "ndx-my-namespace")


def test_bake_project_extra(cookies):
"""Test evaluating the template with namespace set."""
result = cookies.bake(extra_context={"namespace": "ndx-test"})

assert result.exit_code == 0
assert result.exception is None

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

_check_gen_files(result.project_path, "ndx-test")


def _check_gen_files(project_dir: str, namespace: str):
"""Test that the correct files are generated after the template is evaluated."""
for expected_file in [
# Generated using init_sphinx_extension_doc
"docs/Makefile",
"docs/README.md",
"docs/make.bat",
"docs/source/_static/theme_overrides.css",
"docs/source/conf.py",
"docs/source/conf_doc_autogen.py",
"docs/source/credits.rst",
"docs/source/description.rst",
"docs/source/format.rst",
"docs/source/index.rst",
"docs/source/release_notes.rst",
# Generated using "src/spec/create_extension_spec.py"
"spec/%s.extensions.yaml" % namespace,
"spec/%s.namespace.yaml" % namespace,
]:
expected_file = os.path.join(project_dir, expected_file)
assert os.path.exists(expected_file), f"Missing file: {expected_file}"

with open(expected_file, "r") as fp:
assert fp.read().strip() != "", f"Empty file: {expected_file}"


if __name__ == "__main__":
# python test_bake_project.py ndx-my-namespace ndx-my-namespace
_check_gen_files(sys.argv[1], sys.argv[2])
32 changes: 0 additions & 32 deletions tests/test_template_evaluation.py

This file was deleted.

0 comments on commit 6d3e423

Please sign in to comment.