1
|
|
|
"""Collection of tests around cookiecutter's replay feature.""" |
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
|
|
|
): |
8
|
|
|
"""Check that replay_dump is called with a valid template_name. |
9
|
|
|
|
10
|
|
|
Template name must not be a relative path. |
11
|
|
|
|
12
|
|
|
Otherwise files such as ``..json`` are created, which are not just cryptic |
13
|
|
|
but also later mistaken for replay files of other templates if invoked with |
14
|
|
|
'.' and '--replay'. |
15
|
|
|
|
16
|
|
|
Change the current working directory temporarily to 'tests/fake-repo-tmpl' |
17
|
|
|
for this test and call cookiecutter with '.' for the target template. |
18
|
|
|
""" |
19
|
|
|
monkeypatch.chdir('tests/fake-repo-tmpl') |
20
|
|
|
|
21
|
|
|
mock_replay_dump = mocker.patch('cookiecutter.main.dump') |
22
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
23
|
|
|
|
24
|
|
|
cookiecutter( |
25
|
|
|
'.', no_input=True, replay=False, config_file=user_config_file, |
26
|
|
|
) |
27
|
|
|
|
28
|
|
|
mock_replay_dump.assert_called_once_with( |
29
|
|
|
user_config_data['replay_dir'], 'fake-repo-tmpl', mocker.ANY, |
30
|
|
|
) |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
def test_replay_load_template_name( |
34
|
|
|
monkeypatch, mocker, user_config_data, user_config_file |
35
|
|
|
): |
36
|
|
|
"""Check that replay_load is called correctly. |
37
|
|
|
|
38
|
|
|
Calls require valid template_name that is not a relative path. |
39
|
|
|
|
40
|
|
|
Change the current working directory temporarily to 'tests/fake-repo-tmpl' |
41
|
|
|
for this test and call cookiecutter with '.' for the target template. |
42
|
|
|
""" |
43
|
|
|
monkeypatch.chdir('tests/fake-repo-tmpl') |
44
|
|
|
|
45
|
|
|
mock_replay_load = mocker.patch('cookiecutter.main.load') |
46
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
47
|
|
|
|
48
|
|
|
cookiecutter( |
49
|
|
|
'.', replay=True, config_file=user_config_file, |
50
|
|
|
) |
51
|
|
|
|
52
|
|
|
mock_replay_load.assert_called_once_with( |
53
|
|
|
user_config_data['replay_dir'], 'fake-repo-tmpl', |
54
|
|
|
) |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
def test_custom_replay_file(monkeypatch, mocker, user_config_file): |
58
|
|
|
"""Check that reply.load is called with the custom replay_file.""" |
59
|
|
|
monkeypatch.chdir('tests/fake-repo-tmpl') |
60
|
|
|
|
61
|
|
|
mock_replay_load = mocker.patch('cookiecutter.main.load') |
62
|
|
|
mocker.patch('cookiecutter.main.generate_files') |
63
|
|
|
|
64
|
|
|
cookiecutter( |
65
|
|
|
'.', replay='./custom-replay-file', config_file=user_config_file, |
66
|
|
|
) |
67
|
|
|
|
68
|
|
|
mock_replay_load.assert_called_once_with( |
69
|
|
|
'.', 'custom-replay-file', |
70
|
|
|
) |
71
|
|
|
|