forked from cookiecutter/cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_custom_extensions_in_hooks.py
43 lines (32 loc) · 1.23 KB
/
test_custom_extensions_in_hooks.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
"""
test_custom_extension_in_hooks.
Tests to ensure custom cookiecutter extensions are properly made available to
pre- and post-gen hooks.
"""
from pathlib import Path
import pytest
from cookiecutter import main
@pytest.fixture(
params=['custom-extension-pre', 'custom-extension-post'],
ids=['pre_gen_hook', 'post_gen_hook'],
)
def template(request):
"""Fixture. Allows to split pre and post hooks test directories."""
return f"tests/test-extensions/{request.param}"
@pytest.fixture(autouse=True)
def modify_syspath(monkeypatch):
"""Fixture. Make sure that the custom extension can be loaded."""
monkeypatch.syspath_prepend('tests/test-extensions/hello_extension')
def test_hook_with_extension(template, output_dir):
"""Verify custom Jinja2 extension correctly work in hooks and file rendering.
Each file in hooks has simple tests inside and will raise error if not
correctly rendered.
"""
project_dir = main.cookiecutter(
template,
no_input=True,
output_dir=output_dir,
extra_context={'project_slug': 'foobar', 'name': 'Cookiemonster'},
)
readme = Path(project_dir, 'README.rst').read_text(encoding="utf-8")
assert readme.strip() == 'Hello Cookiemonster!'