From eece2f94568bd01ba9969a0d4f0dc07c772ba1be Mon Sep 17 00:00:00 2001 From: David Glick Date: Thu, 31 Oct 2024 13:20:14 -0700 Subject: [PATCH] Add tests --- backend_addon/tests/test_cutter.py | 36 +++++++++++++++++++ .../tests/test_cutter_no_headless.py | 2 -- requirements.txt | 2 +- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/backend_addon/tests/test_cutter.py b/backend_addon/tests/test_cutter.py index 7acc297..42e7be7 100644 --- a/backend_addon/tests/test_cutter.py +++ b/backend_addon/tests/test_cutter.py @@ -1,5 +1,6 @@ """Test cookiecutter generation with all features enabled.""" +from copy import deepcopy from pathlib import Path import pytest @@ -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() diff --git a/backend_addon/tests/test_cutter_no_headless.py b/backend_addon/tests/test_cutter_no_headless.py index 75133ad..0295b21 100644 --- a/backend_addon/tests/test_cutter_no_headless.py +++ b/backend_addon/tests/test_cutter_no_headless.py @@ -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 diff --git a/requirements.txt b/requirements.txt index 9079ddb..f5bae42 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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