forked from cookiecutter/cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cookiecutter_local_with_input.py
59 lines (49 loc) · 1.88 KB
/
test_cookiecutter_local_with_input.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
# -*- coding: utf-8 -*-
"""
test_cookiecutter_local_with_input
----------------------------------
Tests formerly known from a unittest residing in test_main.py named
TestCookiecutterLocalWithInput.test_cookiecutter_local_with_input
TestCookiecutterLocalWithInput.test_cookiecutter_input_extra_context
"""
import os
import pytest
from cookiecutter import main, utils
@pytest.fixture(scope='function')
def remove_additional_dirs(request):
"""
Remove special directories which are created during the tests.
"""
def fin_remove_additional_dirs():
if os.path.isdir('fake-project'):
utils.rmtree('fake-project')
if os.path.isdir('fake-project-input-extra'):
utils.rmtree('fake-project-input-extra')
request.addfinalizer(fin_remove_additional_dirs)
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
def test_cookiecutter_local_with_input(monkeypatch):
monkeypatch.setattr(
'cookiecutter.prompt.read_user_variable',
lambda var, default: default
)
main.cookiecutter('tests/fake-repo-pre/', no_input=False)
assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}')
assert not os.path.isdir('tests/fake-repo-pre/fake-project')
assert os.path.isdir('fake-project')
assert os.path.isfile('fake-project/README.rst')
assert not os.path.exists('fake-project/json/')
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
def test_cookiecutter_input_extra_context(monkeypatch):
"""
`Call cookiecutter()` with `no_input=False` and `extra_context`
"""
monkeypatch.setattr(
'cookiecutter.prompt.read_user_variable',
lambda var, default: default
)
main.cookiecutter(
'tests/fake-repo-pre',
no_input=False,
extra_context={'repo_name': 'fake-project-input-extra'}
)
assert os.path.isdir('fake-project-input-extra')