|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
""" |
|
5
|
|
|
test_cookiecutter_local_no_input |
|
6
|
|
|
-------------------------------- |
|
7
|
|
|
|
|
8
|
|
|
Tests formerly known from a unittest residing in test_main.py named |
|
9
|
|
|
TestCookiecutterLocalNoInput.test_cookiecutter |
|
10
|
|
|
TestCookiecutterLocalNoInput.test_cookiecutter_no_slash |
|
11
|
|
|
TestCookiecutterLocalNoInput.test_cookiecutter_no_input_extra_context |
|
12
|
|
|
TestCookiecutterLocalNoInput.test_cookiecutter_templated_context |
|
13
|
|
|
""" |
|
14
|
|
|
|
|
15
|
|
|
import os |
|
16
|
|
|
import pytest |
|
17
|
|
|
|
|
18
|
|
|
from cookiecutter import main, utils |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
@pytest.fixture(scope='function') |
|
22
|
|
|
def remove_additional_dirs(request): |
|
23
|
|
|
""" |
|
24
|
|
|
Remove special directories which are created during the tests. |
|
25
|
|
|
""" |
|
26
|
|
|
def fin_remove_additional_dirs(): |
|
27
|
|
|
if os.path.isdir('fake-project'): |
|
28
|
|
|
utils.rmtree('fake-project') |
|
29
|
|
|
if os.path.isdir('fake-project-extra'): |
|
30
|
|
|
utils.rmtree('fake-project-extra') |
|
31
|
|
|
if os.path.isdir('fake-project-templated'): |
|
32
|
|
|
utils.rmtree('fake-project-templated') |
|
33
|
|
|
request.addfinalizer(fin_remove_additional_dirs) |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
@pytest.fixture(params=['tests/fake-repo-pre/', 'tests/fake-repo-pre']) |
|
37
|
|
|
def bake(request): |
|
38
|
|
|
""" |
|
39
|
|
|
Run cookiecutter with the given input_dir path. |
|
40
|
|
|
""" |
|
41
|
|
|
main.cookiecutter(request.param, no_input=True) |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs', 'bake') |
|
45
|
|
|
def test_cookiecutter(): |
|
46
|
|
|
assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}') |
|
47
|
|
|
assert not os.path.isdir('tests/fake-repo-pre/fake-project') |
|
48
|
|
|
assert os.path.isdir('fake-project') |
|
49
|
|
|
assert os.path.isfile('fake-project/README.rst') |
|
50
|
|
|
assert not os.path.exists('fake-project/json/') |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs') |
|
54
|
|
|
def test_cookiecutter_no_input_extra_context(): |
|
55
|
|
|
""" |
|
56
|
|
|
`Call cookiecutter()` with `no_input=True` and `extra_context |
|
57
|
|
|
""" |
|
58
|
|
|
main.cookiecutter( |
|
59
|
|
|
'tests/fake-repo-pre', |
|
60
|
|
|
no_input=True, |
|
61
|
|
|
extra_context={'repo_name': 'fake-project-extra'} |
|
62
|
|
|
) |
|
63
|
|
|
assert os.path.isdir('fake-project-extra') |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs') |
|
67
|
|
|
def test_cookiecutter_templated_context(): |
|
68
|
|
|
""" |
|
69
|
|
|
`Call cookiecutter()` with `no_input=True` and templates in the |
|
70
|
|
|
cookiecutter.json file |
|
71
|
|
|
""" |
|
72
|
|
|
main.cookiecutter( |
|
73
|
|
|
'tests/fake-repo-tmpl', |
|
74
|
|
|
no_input=True |
|
75
|
|
|
) |
|
76
|
|
|
assert os.path.isdir('fake-project-templated') |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs') |
|
80
|
|
|
def test_cookiecutter_no_input_return_project_dir(): |
|
81
|
|
|
"""Call `cookiecutter()` with `no_input=True`.""" |
|
82
|
|
|
project_dir = main.cookiecutter('tests/fake-repo-pre', no_input=True) |
|
83
|
|
|
assert project_dir == os.path.abspath('fake-project') |
|
84
|
|
|
|