1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
from cookiecutter.main import cookiecutter |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
def test_replay_dump_template_name( |
6
|
|
|
monkeypatch, mocker, user_config_data, user_config_file): |
7
|
|
|
"""Check that replay_dump is called with a valid template_name that is |
8
|
|
|
not a relative path. |
9
|
|
|
|
10
|
|
|
Otherwise files such as ``..json`` are created, which are not just cryptic |
11
|
|
|
but also later mistaken for replay files of other templates if invoked with |
12
|
|
|
'.' and '--replay'. |
13
|
|
|
|
14
|
|
|
Change the current working directory temporarily to 'tests/fake-repo-tmpl' |
15
|
|
|
for this test and call cookiecutter with '.' for the target template. |
16
|
|
|
""" |
17
|
|
|
monkeypatch.chdir('tests/fake-repo-tmpl') |
18
|
|
|
|
19
|
|
|
mock_replay_dump = mocker.patch('cookiecutter.main.dump') |
20
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
21
|
|
|
|
22
|
|
|
cookiecutter( |
23
|
|
|
'.', |
24
|
|
|
no_input=True, |
25
|
|
|
replay=False, |
26
|
|
|
config_file=user_config_file, |
27
|
|
|
) |
28
|
|
|
|
29
|
|
|
mock_replay_dump.assert_called_once_with( |
30
|
|
|
user_config_data['replay_dir'], |
31
|
|
|
'fake-repo-tmpl', |
32
|
|
|
mocker.ANY, |
33
|
|
|
) |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def test_replay_load_template_name( |
37
|
|
|
monkeypatch, mocker, user_config_data, user_config_file): |
38
|
|
|
"""Check that replay_load is called with a valid template_name that is |
39
|
|
|
not a relative path. |
40
|
|
|
|
41
|
|
|
Change the current working directory temporarily to 'tests/fake-repo-tmpl' |
42
|
|
|
for this test and call cookiecutter with '.' for the target template. |
43
|
|
|
""" |
44
|
|
|
monkeypatch.chdir('tests/fake-repo-tmpl') |
45
|
|
|
|
46
|
|
|
mock_replay_load = mocker.patch('cookiecutter.main.load') |
47
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
48
|
|
|
|
49
|
|
|
cookiecutter( |
50
|
|
|
'.', |
51
|
|
|
replay=True, |
52
|
|
|
config_file=user_config_file, |
53
|
|
|
) |
54
|
|
|
|
55
|
|
|
mock_replay_load.assert_called_once_with( |
56
|
|
|
user_config_data['replay_dir'], |
57
|
|
|
'fake-repo-tmpl', |
58
|
|
|
) |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
def test_version_2_load_context_call( |
62
|
|
|
monkeypatch, mocker, user_config_file): |
63
|
|
|
"""Check that the version 2 load_context() is called. |
64
|
|
|
|
65
|
|
|
Change the current working directory temporarily to |
66
|
|
|
'tests/test-generate-context-v2/min-v2-cookiecutter' |
67
|
|
|
for this test and call cookiecutter with '.' for the target template. |
68
|
|
|
""" |
69
|
|
|
monkeypatch.chdir('tests/test-generate-context-v2/min-v2-cookiecutter') |
70
|
|
|
|
71
|
|
|
mock_replay_dump = mocker.patch('cookiecutter.main.dump') |
72
|
|
|
|
73
|
|
|
mock_version_1_prompt_for_config = mocker.patch( |
74
|
|
|
'cookiecutter.main.prompt_for_config') |
75
|
|
|
mock_version_2_load_context = mocker.patch( |
76
|
|
|
'cookiecutter.main.load_context') |
77
|
|
|
|
78
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
79
|
|
|
|
80
|
|
|
cookiecutter( |
81
|
|
|
'.', |
82
|
|
|
no_input=True, |
83
|
|
|
replay=False, |
84
|
|
|
config_file=user_config_file, |
85
|
|
|
) |
86
|
|
|
|
87
|
|
|
assert mock_version_1_prompt_for_config.call_count == 0 |
88
|
|
|
assert mock_version_2_load_context.call_count == 1 |
89
|
|
|
assert mock_replay_dump.call_count == 1 |
90
|
|
|
|