1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
|
3
|
|
|
""" |
4
|
|
|
test_cookiecutter_local_with_input |
5
|
|
|
---------------------------------- |
6
|
|
|
|
7
|
|
|
Tests formerly known from a unittest residing in test_main.py named |
8
|
|
|
TestCookiecutterLocalWithInput.test_cookiecutter_local_with_input |
9
|
|
|
TestCookiecutterLocalWithInput.test_cookiecutter_input_extra_context |
10
|
|
|
""" |
11
|
|
|
|
12
|
|
|
import os |
13
|
|
|
import pytest |
14
|
|
|
|
15
|
|
|
from cookiecutter import main, utils |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
@pytest.fixture(scope='function') |
19
|
|
|
def remove_additional_dirs(request): |
20
|
|
|
""" |
21
|
|
|
Remove special directories which are created during the tests. |
22
|
|
|
""" |
23
|
|
|
def fin_remove_additional_dirs(): |
24
|
|
|
if os.path.isdir('fake-project'): |
25
|
|
|
utils.rmtree('fake-project') |
26
|
|
|
if os.path.isdir('fake-project-input-extra'): |
27
|
|
|
utils.rmtree('fake-project-input-extra') |
28
|
|
|
request.addfinalizer(fin_remove_additional_dirs) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs') |
32
|
|
|
def test_cookiecutter_local_with_input(monkeypatch): |
33
|
|
|
monkeypatch.setattr( |
34
|
|
|
'cookiecutter.prompt.read_user_variable', |
35
|
|
|
lambda var, default: default |
36
|
|
|
) |
37
|
|
|
main.cookiecutter('tests/fake-repo-pre/', no_input=False) |
38
|
|
|
assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}') |
39
|
|
|
assert not os.path.isdir('tests/fake-repo-pre/fake-project') |
40
|
|
|
assert os.path.isdir('fake-project') |
41
|
|
|
assert os.path.isfile('fake-project/README.rst') |
42
|
|
|
assert not os.path.exists('fake-project/json/') |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs') |
46
|
|
|
def test_cookiecutter_input_extra_context(monkeypatch): |
47
|
|
|
""" |
48
|
|
|
`Call cookiecutter()` with `no_input=False` and `extra_context` |
49
|
|
|
""" |
50
|
|
|
monkeypatch.setattr( |
51
|
|
|
'cookiecutter.prompt.read_user_variable', |
52
|
|
|
lambda var, default: default |
53
|
|
|
) |
54
|
|
|
main.cookiecutter( |
55
|
|
|
'tests/fake-repo-pre', |
56
|
|
|
no_input=False, |
57
|
|
|
extra_context={'repo_name': 'fake-project-input-extra'} |
58
|
|
|
) |
59
|
|
|
assert os.path.isdir('fake-project-input-extra') |
60
|
|
|
|