-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathconftest.py
More file actions
80 lines (62 loc) · 2.1 KB
/
conftest.py
File metadata and controls
80 lines (62 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""Fixtures for the cookiecutter template tests."""
import pathlib
import subprocess
import typing
import pytest
@pytest.fixture
def default_config() -> dict[str, str]:
"""
Get the minimal default configuration for cutting a cookie in tests.
This is used if `generate_package` is called without arguments.
"""
return {
"github_owner": "test-user",
"project_short_description": "description",
"project_name": "Cookiecutter Test",
"project_slug": "cookiecutter-test",
}
@pytest.fixture
def default_config_with(default_config: dict[str, str]) -> typing.Callable:
"""Extend or modify the default configuration with one additional value."""
def _wrapped_with(key: str, value: str) -> dict[str, str]:
default_config[key] = value
return default_config
return _wrapped_with
def _generate_package(
config: dict[str, str],
path: pathlib.Path,
) -> tuple[subprocess.CompletedProcess[str], pathlib.Path]:
"""
Generate a project from the cookiecutter template.
Parameters
----------
config
A dictionary with values for the cookiecutter template,
as defined in the cookiecutter.json
path
Directory to create package in.
Returns
-------
subprocess.CompletedProcess, pathlib.Path
The result of the cookiecutter command and the path to the generated package.
"""
args = [f"{key}={val}" for key, val in config.items()]
cmd = ["cookiecutter", ".", "--no-input", "--output-dir", f"{path}"]
return subprocess.run( # noqa: S603
cmd + args,
check=False,
shell=False,
capture_output=True,
text=True,
), path / config["project_slug"]
@pytest.fixture
def generate_package(
default_config: dict[str, str],
tmp_path: pathlib.Path,
) -> typing.Callable:
"""Generate project from cookiecutter template."""
def _wrapped_with_tmp_path(
config: dict[str, str] = default_config,
) -> tuple[subprocess.CompletedProcess, pathlib.Path]:
return _generate_package(config, tmp_path)
return _wrapped_with_tmp_path