From 0d0c54f3a7c705aff7bc93e7cca219829abbf3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Wed, 29 May 2024 12:06:35 -0300 Subject: [PATCH] Flag to add distribution trove classifier --- backend_addon/cookiecutter.json | 1 + backend_addon/tests/conftest.py | 9 +++++ .../tests/test_cutter_distribution.py | 35 +++++++++++++++++++ .../tests/test_cutter_no_headless.py | 2 +- .../{{ cookiecutter.__folder_name }}/setup.py | 4 ++- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 backend_addon/tests/test_cutter_distribution.py diff --git a/backend_addon/cookiecutter.json b/backend_addon/cookiecutter.json index 59e934b..be7b4b6 100644 --- a/backend_addon/cookiecutter.json +++ b/backend_addon/cookiecutter.json @@ -10,6 +10,7 @@ "0" ], "__feature_headless": "{{ cookiecutter.feature_headless }}", + "__feature_distribution": "0", "__package_name": "{{ cookiecutter.python_package_name | package_name }}", "__package_namespace": "{{ cookiecutter.python_package_name | package_namespace }}", "__folder_name": "{{ cookiecutter.python_package_name }}", diff --git a/backend_addon/tests/conftest.py b/backend_addon/tests/conftest.py index 5f5d0bc..2bf346f 100644 --- a/backend_addon/tests/conftest.py +++ b/backend_addon/tests/conftest.py @@ -97,6 +97,15 @@ def context_no_headless(context) -> dict: return new_context +@pytest.fixture(scope="session") +def context_distribution(context) -> dict: + """Cookiecutter context with distribution enabled.""" + new_context = deepcopy(context) + new_context["python_package_name"] = "plonedistribution.myplone" + new_context["__feature_distribution"] = "1" + return new_context + + @pytest.fixture(scope="session") def context_no_git(context) -> dict: """Cookiecutter context without Git repository.""" diff --git a/backend_addon/tests/test_cutter_distribution.py b/backend_addon/tests/test_cutter_distribution.py new file mode 100644 index 0000000..67dd05e --- /dev/null +++ b/backend_addon/tests/test_cutter_distribution.py @@ -0,0 +1,35 @@ +"""Test cookiecutter generation with distribution feature enabled.""" + +import pytest + + +@pytest.fixture(scope="session") +def cutter_result(cookies_session, context_distribution): + """Cookiecutter result.""" + return cookies_session.bake(extra_context=context_distribution) + + +def test_creation(cookies, context_distribution: dict): + """Generated project should match provided value.""" + result = cookies.bake(extra_context=context_distribution) + assert result.exception is None + assert result.exit_code == 0 + assert result.project_path.name == context_distribution["python_package_name"] + assert result.project_path.is_dir() + + +def test_variable_substitution(build_files_list, variable_pattern, cutter_result): + """Check if no file was unprocessed.""" + paths = build_files_list(cutter_result.project_path) + for path in paths: + for line in open(path): + match = variable_pattern.search(line) + msg = f"cookiecutter variable not replaced in {path}" + assert match is None, msg + + +def test_trove_classifier_set(cutter_result): + """Check feature-specific files were not generated.""" + trove_classifier = "Framework :: Plone :: Distribution" + setup_py = cutter_result.project_path / "setup.py" + assert trove_classifier in setup_py.read_text() diff --git a/backend_addon/tests/test_cutter_no_headless.py b/backend_addon/tests/test_cutter_no_headless.py index 50efa96..c06b566 100644 --- a/backend_addon/tests/test_cutter_no_headless.py +++ b/backend_addon/tests/test_cutter_no_headless.py @@ -1,4 +1,4 @@ -"""Test cookiecutter generation with features enabled.""" +"""Test cookiecutter generation withoyt headeless feature.""" import pytest diff --git a/backend_addon/{{ cookiecutter.__folder_name }}/setup.py b/backend_addon/{{ cookiecutter.__folder_name }}/setup.py index 2812a14..b0587bd 100644 --- a/backend_addon/{{ cookiecutter.__folder_name }}/setup.py +++ b/backend_addon/{{ cookiecutter.__folder_name }}/setup.py @@ -22,7 +22,9 @@ "Environment :: Web Environment", "Framework :: Plone", "Framework :: Plone :: Addon", + {%- if cookiecutter.__feature_distribution == '1' %} "Framework :: Plone :: Distribution", + {%- endif %} "Framework :: Plone :: 6.0", "Programming Language :: Python", "Programming Language :: Python :: 3.8", @@ -50,7 +52,7 @@ python_requires=">=3.8", install_requires=[ "setuptools", - "Plone", + "Products.CMFPlone", "plone.api", {%- if cookiecutter.__feature_headless == '1' %} "plone.restapi",