From ec5b155b6bb9fc1b8a085a773d11eaed7379b0a6 Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Tue, 16 Jul 2024 15:59:55 +0200 Subject: [PATCH 1/4] update basic test to copier using pytest-copie --- copier.yml | 2 +- setup.cfg | 5 +++-- tests/test_project.py | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/copier.yml b/copier.yml index 6e9edd6..b2e213f 100644 --- a/copier.yml +++ b/copier.yml @@ -62,7 +62,7 @@ copyright_holder: default: Netherlands eScience Center code_of_conduct_email: type: str - default: {{ email }} + default: "{{ email }}" _subdirectory: template diff --git a/setup.cfg b/setup.cfg index 5aef066..af88327 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,7 +33,7 @@ include_package_data = True python_requires = >=3.8 packages = install_requires = - cookiecutter==1.7.2 + copier==9.2.0 [options.data_files] # This section requires setuptools>=40.6.0 @@ -45,7 +45,8 @@ install_requires = dev = coverage [toml] pytest - pytest-cookies + pytest-copie + pyprojroot [tool:pytest] diff --git a/tests/test_project.py b/tests/test_project.py index 1163013..636c4a5 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -4,18 +4,19 @@ from sys import platform from typing import Sequence +from pyprojroot.here import here +from copier import run_copy import pytest IS_WINDOWS = platform.startswith('win') -def test_project_folder(cookies): - project = cookies.bake() +def test_project_folder(copie): + project = copie.copy() assert project.exit_code == 0 assert project.exception is None - assert project.project_path.name == 'my-python-project' - assert project.project_path.is_dir() + assert project.project_dir.is_dir() def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProcess: From 2d162d4498a188992e8adbba49f4d6693cbea2ff Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Thu, 18 Jul 2024 16:25:18 +0200 Subject: [PATCH 2/4] remove directory name question --- copier.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/copier.yml b/copier.yml index b2e213f..77fc3fd 100644 --- a/copier.yml +++ b/copier.yml @@ -1,13 +1,5 @@ # Essential questions -directory_name: - type: str - default: my-python-project - help: Enter the name of the directory where the project will be created. - validator: >- - {% if not (directory_name | regex_search('^[a-z0-9\-]+$')) %} - directory_name must be lowercase, and can only contain letters, digits, and hyphens. - {% endif %} package_name: type: str default: my_python_package From 28b34493c3e6bc037ab6eca1d7ef16eec4f49861 Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Tue, 16 Jul 2024 17:23:19 +0200 Subject: [PATCH 3/4] update project tests This adapts the custom session scoped fixture to manually create a copier copy, since the pytest-copie plugin does not yet support a session-scoped fixture --- tests/test_project.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/test_project.py b/tests/test_project.py index 636c4a5..a9cbbdc 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -42,15 +42,16 @@ def project_env_bin_dir(tmp_path_factory): @pytest.fixture(scope='session') -def baked_with_development_dependencies(cookies_session, project_env_bin_dir): - result = cookies_session.bake() - assert result.exit_code == 0 +def baked_with_development_dependencies(tmp_path_factory, project_env_bin_dir): + project = run_copy(src_path=str(here()), dst_path=str(tmp_path_factory.mktemp('projects')), defaults=True) + project_dir = project.dst_path + bin_dir = project_env_bin_dir - latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], result.project_path) + latest_pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools'], project_dir) assert latest_pip_output.returncode == 0 - pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], result.project_path) + pip_output = run([f'{bin_dir}python', '-m', 'pip', 'install', '--editable', '.[dev]'], project_dir) assert pip_output.returncode == 0 - return result.project_path + return project_dir def test_pytest(baked_with_development_dependencies, project_env_bin_dir): @@ -168,7 +169,7 @@ def test_ruff_check(baked_with_development_dependencies, project_env_bin_dir): project_dir = baked_with_development_dependencies bin_dir = project_env_bin_dir - result = run([f'{bin_dir}ruff', '.'], project_dir) + result = run([f'{bin_dir}ruff', 'check', '.'], project_dir) assert result.returncode == 0 assert '' in result.stdout From a2125600408a7bb860795728ab0cf8917b921320 Mon Sep 17 00:00:00 2001 From: Sander van Rijn Date: Thu, 18 Jul 2024 16:30:47 +0200 Subject: [PATCH 4/4] update values tests --- tests/test_values.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_values.py b/tests/test_values.py index 01d748a..1f24032 100644 --- a/tests/test_values.py +++ b/tests/test_values.py @@ -1,36 +1,36 @@ -def test_double_quotes_in_name_and_description(cookies): +def test_double_quotes_in_name_and_description(copie): ctx = { "project_short_description": '"double quotes"', "full_name": '"name"name' } - project = cookies.bake(extra_context=ctx) + project = copie.copy(extra_answers=ctx) assert project.exit_code == 0 -def test_single_quotes_in_name_and_description(cookies): +def test_single_quotes_in_name_and_description(copie): ctx = { "project_short_description": "'single quotes'", "full_name": "Mr. O'Keefe" } - project = cookies.bake(extra_context=ctx) + project = copie.copy(extra_answers=ctx) assert project.exit_code == 0 -def test_dash_in_directory_name(cookies): +def test_dash_in_directory_name(copie): ctx = { "directory_name": "my-python-project" } - project = cookies.bake(extra_context=ctx) + project = copie.copy(extra_answers=ctx) assert project.exit_code == 0 -def test_space_in_directory_name(cookies): +def test_space_in_directory_name(copie): ctx = { "directory_name": "my python project" } - project = cookies.bake(extra_context=ctx) + project = copie.copy(extra_answers=ctx) assert project.exit_code == 0