Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Oct 31, 2024
1 parent e634689 commit eece2f9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
36 changes: 36 additions & 0 deletions backend_addon/tests/test_cutter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test cookiecutter generation with all features enabled."""

from copy import deepcopy
from pathlib import Path

import pytest
Expand Down Expand Up @@ -86,3 +87,38 @@ def test_git_initialization_not_set(cookies, context_no_git):
cutter_result = cookies.bake(extra_context=context_no_git)
path = cutter_result.project_path
assert git.check_path_is_repository(path) is False


@pytest.fixture(scope="session")
def cutter_result_no_namespace(context, cookies_session) -> dict:
"""Cookiecutter context without namespace package."""
new_context = deepcopy(context)
new_context["python_package_name"] = "addon"
return cookies_session.bake(extra_context=new_context)


@pytest.fixture(scope="session")
def cutter_result_two_namespaces(context, cookies_session) -> dict:
"""Cookiecutter context with 2 namespace packages."""
new_context = deepcopy(context)
new_context["python_package_name"] = "foo.bar.baz"
return cookies_session.bake(extra_context=new_context)



@pytest.mark.parametrize("file_path", PKG_SRC_FILES)
def test_pkg_src_files_generated_without_namespace(cutter_result_no_namespace, file_path: str):
"""Check package contents with no namespaces."""
src_path = cutter_result_no_namespace.project_path / "src/addon"
path = src_path / file_path
assert path.exists()
assert path.is_file()


@pytest.mark.parametrize("file_path", PKG_SRC_FILES)
def test_pkg_src_files_generated_with_two_namespaces(cutter_result_two_namespaces, file_path: str):
"""Check package contents with 2 namespaces."""
src_path = cutter_result_two_namespaces.project_path / "src/foo/bar/baz"
path = src_path / file_path
assert path.exists()
assert path.is_file()
2 changes: 0 additions & 2 deletions backend_addon/tests/test_cutter_no_headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,3 @@ def test_pkg_src_headless_files_not_generated(cutter_result, file_path: str):
src_path = cutter_result.project_path / "src" / package_path
path = src_path / file_path
assert path.exists() is False

# test with 0 and 2 namespaces
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ isort
pytest
pytest-cookies
pytest-jsonschema >= 1.0.0a2
cookieplone @ git+https://github.com/plone/cookieplone@variable-namespace-length
cookieplone @ git+https://github.com/plone/cookieplone@main
GitPython
wheel

0 comments on commit eece2f9

Please sign in to comment.