Completed
Push — break-up-hooks-tests ( 75c50f...87fe28 )
by Michael
34s
created

modify_syspath()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
1
# -*- coding: utf-8 -*-
2
3
import os
4
import codecs
5
6
import pytest
7
8
from cookiecutter import main
9
10
11
@pytest.fixture(params=[
12
    'custom-extension-pre',
13
    'custom-extension-post',
14
], ids=[
15
    'pre_gen_hook',
16
    'post_gen_hook',
17
])
18
def template(request):
19
    return 'tests/test-extensions/' + request.param
20
21
22
@pytest.fixture
23
def output_dir(tmpdir):
24
    return str(tmpdir.mkdir('hello'))
25
26
27
@pytest.fixture(autouse=True)
28
def modify_syspath(monkeypatch):
29
    # Make sure that the custom extension can be loaded
30
    monkeypatch.syspath_prepend(
31
        'tests/test-extensions/hello_extension'
32
    )
33
34
35
def test_hook_with_extension(template, output_dir):
36
    project_dir = main.cookiecutter(
37
        template,
38
        no_input=True,
39
        output_dir=output_dir,
40
        extra_context={
41
            'project_slug': 'foobar',
42
            'name': 'Cookiemonster',
43
        },
44
    )
45
46
    readme_file = os.path.join(project_dir, 'README.rst')
47
48
    with codecs.open(readme_file, encoding='utf8') as f:
49
        readme = f.read().strip()
50
51
    assert readme == 'Hello Cookiemonster!'
52