|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
|
|
4
|
|
|
""" |
|
5
|
|
|
test_real_hooks_acceptance |
|
6
|
|
|
-------------------------- |
|
7
|
|
|
|
|
8
|
|
|
Additional tests for `cookiecutter.hooks` module. |
|
9
|
|
|
""" |
|
10
|
|
|
|
|
11
|
|
|
import os |
|
12
|
|
|
import sys |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
from .support import read_file, AbstractAcceptanceTest |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class TestRealHooksAcceptance(AbstractAcceptanceTest): |
|
19
|
|
|
|
|
20
|
|
|
def _repo_id(self): |
|
21
|
|
|
return 'test-real-hooks-acceptance' |
|
22
|
|
|
|
|
23
|
|
|
def assert_real_hook_is_run_in_place(self, template): |
|
24
|
|
|
""" |
|
25
|
|
|
assert that the real hook is run in place |
|
26
|
|
|
:param template: template id |
|
27
|
|
|
""" |
|
28
|
|
|
template_dir = os.path.join(self.templates_path, template) |
|
29
|
|
|
file = os.path.join(self.project_dir, template) |
|
30
|
|
|
self.run(template) |
|
31
|
|
|
assert os.path.exists(file) |
|
32
|
|
|
content = read_file(file) |
|
33
|
|
|
assert template_dir == content.strip() |
|
34
|
|
|
|
|
35
|
|
|
def test_renderable_hooks_can_be_run(self): |
|
36
|
|
|
""" |
|
37
|
|
|
regression test |
|
38
|
|
|
""" |
|
39
|
|
|
template = 'renderable' |
|
40
|
|
|
self.run(template) |
|
41
|
|
|
assert os.path.exists(os.path.join(self.project_dir, template)) |
|
42
|
|
|
|
|
43
|
|
|
def test_run_real_hook_in_place(self): |
|
44
|
|
|
""" |
|
45
|
|
|
run a real hook in place: python file |
|
46
|
|
|
""" |
|
47
|
|
|
self.assert_real_hook_is_run_in_place('inplace') |
|
48
|
|
|
|
|
49
|
|
|
def test_run_real_hook_in_place_shell(self): |
|
50
|
|
|
""" |
|
51
|
|
|
run a real hook in place: bash or batch file depending on the OS |
|
52
|
|
|
""" |
|
53
|
|
|
template = 'batch' if sys.platform.startswith('win') else 'bash' |
|
54
|
|
|
self.assert_real_hook_is_run_in_place(template) |
|
55
|
|
|
|
|
56
|
|
|
def test_run_pre_user_prompt_hook(self, mocker): |
|
57
|
|
|
""" |
|
58
|
|
|
used to populate the context before the user is prompted for config |
|
59
|
|
|
""" |
|
60
|
|
|
self.configure('pre_user_prompt') |
|
61
|
|
|
self.settings.no_input = False |
|
62
|
|
|
license = u'BSD-3' |
|
63
|
|
|
variables = { |
|
64
|
|
|
'project_name': self.project, |
|
65
|
|
|
'project_slug': self.project_dir |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
def _read_user_variable(*args, **kwargs): |
|
69
|
|
|
return variables[args[0]] if args[0] in variables else args[1] |
|
70
|
|
|
|
|
71
|
|
|
read_variable = mocker.patch('cookiecutter.prompt.read_user_variable') |
|
72
|
|
|
read_variable.side_effect = _read_user_variable |
|
73
|
|
|
read_choice = mocker.patch('cookiecutter.prompt.read_user_choice') |
|
74
|
|
|
read_choice.return_value = license |
|
75
|
|
|
|
|
76
|
|
|
self.run() |
|
77
|
|
|
assert os.path.exists(os.path.join(self.project_dir, license)) |
|
78
|
|
|
|