-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_template.py
88 lines (62 loc) · 2.11 KB
/
test_template.py
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
81
82
83
84
85
86
87
88
"""
Test the Cookiecutter template.
"""
from cookiecutter.generate import generate_context
from cookiecutter.main import cookiecutter
from pathlib import Path
from shlex import split
from subprocess import run
from venv import create
import pytest
@pytest.fixture(scope="session")
def template() -> Path:
""" The template under test.
"""
return Path(__file__).resolve().parents[1]
@pytest.fixture(scope="module")
def tmpdir(tmp_path_factory) -> Path:
""" Test directory.
"""
return tmp_path_factory.mktemp("test_template")
@pytest.fixture(scope="module")
def context(template) -> dict:
""" Template context for testing.
"""
context = generate_context(template.joinpath("cookiecutter.json"))
context["cookiecutter"].update({
"project_slug": "slugify"
})
return context["cookiecutter"]
@pytest.fixture(scope="module")
def project(tmpdir, template, context) -> Path:
""" Create a test project from the Cookiecutter template.
"""
cookiecutter(str(template), no_input=True, output_dir=tmpdir, extra_context=context)
return tmpdir / context["project_slug"]
@pytest.fixture
def python(tmp_path):
""" Create a Python virtual environment for testing.
"""
venv = tmp_path / ".venv"
create(venv, with_pip=True)
return venv / "bin" / "python"
def test_project(project):
""" Verify that the project was created correctly.
"""
# Just a basic sanity test.
assert len(list(project.iterdir())) == 4
return
@pytest.fixture
def install_render_engine_cli(python):
install_cli = "pip install render_engine[cli]"
install_args = split(f"{python} -m {install_cli}")
install_process = run(install_args)
assert install_process.returncode == 0
def test_site_generation(context, project, python, install_render_engine_cli):
generate_site = "render_engine build app:app"
generate_args = split(f"{python} -m {generate_site}")
generate_process = run(generate_args, cwd=project)
assert generate_process.returncode == 0
# Make the script executable.
if __name__ == "__main__":
raise SystemExit(pytest.main([__file__]))