1
|
|
|
"""test_replay.""" |
2
|
|
|
import os |
3
|
|
|
|
4
|
|
|
import pytest |
5
|
|
|
|
6
|
|
|
from cookiecutter import exceptions, main, replay |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
@pytest.mark.parametrize("replay_file_name", ['bar', 'bar.json']) |
10
|
|
|
def test_get_replay_file_name(replay_file_name): |
11
|
|
|
"""Make sure that replay.get_file_name generates a valid json file path.""" |
12
|
|
|
exp_replay_file_path = os.path.join('foo', 'bar.json') |
13
|
|
|
replay_file_path = replay.get_file_name('foo', replay_file_name) |
14
|
|
|
assert replay_file_path == exp_replay_file_path |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
@pytest.mark.parametrize( |
18
|
|
|
'invalid_kwargs', |
19
|
|
|
( |
20
|
|
|
{'no_input': True}, |
21
|
|
|
{'extra_context': {}}, |
22
|
|
|
{'no_input': True, 'extra_context': {}}, |
23
|
|
|
), |
24
|
|
|
) |
25
|
|
|
def test_raise_on_invalid_mode(invalid_kwargs): |
26
|
|
|
"""Test `cookiecutter` raise exception on unacceptable `replay` request.""" |
27
|
|
|
with pytest.raises(exceptions.InvalidModeException): |
28
|
|
|
main.cookiecutter('foo', replay=True, **invalid_kwargs) |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
def test_main_does_not_invoke_dump_but_load(mocker): |
32
|
|
|
"""Test `cookiecutter` calling correct functions on `replay`.""" |
33
|
|
|
mock_prompt = mocker.patch('cookiecutter.main.prompt_for_config') |
34
|
|
|
mock_gen_context = mocker.patch('cookiecutter.main.generate_context') |
35
|
|
|
mock_gen_files = mocker.patch('cookiecutter.main.generate_files') |
36
|
|
|
mock_replay_dump = mocker.patch('cookiecutter.main.dump') |
37
|
|
|
mock_replay_load = mocker.patch('cookiecutter.main.load') |
38
|
|
|
|
39
|
|
|
main.cookiecutter('tests/fake-repo-tmpl/', replay=True) |
40
|
|
|
|
41
|
|
|
assert not mock_prompt.called |
42
|
|
|
assert not mock_gen_context.called |
43
|
|
|
assert not mock_replay_dump.called |
44
|
|
|
assert mock_replay_load.called |
45
|
|
|
assert mock_gen_files.called |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def test_main_does_not_invoke_load_but_dump(mocker): |
49
|
|
|
"""Test `cookiecutter` calling correct functions on non-replay launch.""" |
50
|
|
|
mock_prompt = mocker.patch('cookiecutter.main.prompt_for_config') |
51
|
|
|
mock_gen_context = mocker.patch('cookiecutter.main.generate_context') |
52
|
|
|
mock_gen_files = mocker.patch('cookiecutter.main.generate_files') |
53
|
|
|
mock_replay_dump = mocker.patch('cookiecutter.main.dump') |
54
|
|
|
mock_replay_load = mocker.patch('cookiecutter.main.load') |
55
|
|
|
|
56
|
|
|
main.cookiecutter('tests/fake-repo-tmpl/', replay=False) |
57
|
|
|
|
58
|
|
|
assert mock_prompt.called |
59
|
|
|
assert mock_gen_context.called |
60
|
|
|
assert mock_replay_dump.called |
61
|
|
|
assert not mock_replay_load.called |
62
|
|
|
assert mock_gen_files.called |
63
|
|
|
|