Skip to content

Commit

Permalink
Merge pull request #13 from sjvrijn/1-update-tests
Browse files Browse the repository at this point in the history
Update tests to use copier instead of cookiecutter
  • Loading branch information
lyashevska authored Jul 19, 2024
2 parents 3113ab1 + a212560 commit 4016ac6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 30 deletions.
10 changes: 1 addition & 9 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -62,7 +54,7 @@ copyright_holder:
default: Netherlands eScience Center
code_of_conduct_email:
type: str
default: {{ email }}
default: "{{ email }}"

_subdirectory: template

Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +45,8 @@ install_requires =
dev =
coverage [toml]
pytest
pytest-cookies
pytest-copie
pyprojroot


[tool:pytest]
Expand Down
24 changes: 13 additions & 11 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -41,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):
Expand Down Expand Up @@ -167,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

Expand Down
16 changes: 8 additions & 8 deletions tests/test_values.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4016ac6

Please sign in to comment.