forked from cookiecutter/cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_custom_extensions_in_hooks.py
51 lines (37 loc) · 1.04 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
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
import os
import codecs
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):
return 'tests/test-extensions/' + request.param
@pytest.fixture
def output_dir(tmpdir):
return str(tmpdir.mkdir('hello'))
@pytest.fixture(autouse=True)
def modify_syspath(monkeypatch):
# 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):
project_dir = main.cookiecutter(
template,
no_input=True,
output_dir=output_dir,
extra_context={
'project_slug': 'foobar',
'name': 'Cookiemonster',
},
)
readme_file = os.path.join(project_dir, 'README.rst')
with codecs.open(readme_file, encoding='utf8') as f:
readme = f.read().strip()
assert readme == 'Hello Cookiemonster!'