1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
""" |
5
|
|
|
test_vcs_prompt |
6
|
|
|
--------------- |
7
|
|
|
""" |
8
|
|
|
|
9
|
|
|
import os |
10
|
|
|
import pytest |
11
|
|
|
|
12
|
|
|
from cookiecutter import vcs |
13
|
|
|
from tests.skipif_markers import skipif_no_network, skipif_no_hg |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
@pytest.fixture(autouse=True) |
17
|
|
|
def setup(tmpdir): |
18
|
|
|
tmpdir.mkdir('cookiecutter-pypackage/') |
19
|
|
|
tmpdir.mkdir('cookiecutter-trytonmodule/') |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
@skipif_no_network |
23
|
|
|
def test_git_clone_overwrite(monkeypatch): |
24
|
|
|
monkeypatch.setattr( |
25
|
|
|
'cookiecutter.vcs.read_user_yes_no', |
26
|
|
|
lambda question, default: True |
27
|
|
|
) |
28
|
|
|
repo_dir = vcs.clone( |
29
|
|
|
'https://github.com/audreyr/cookiecutter-pypackage.git' |
30
|
|
|
) |
31
|
|
|
assert repo_dir == 'cookiecutter-pypackage' |
32
|
|
|
assert os.path.isfile('cookiecutter-pypackage/README.rst') |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
@skipif_no_network |
36
|
|
|
def test_git_clone_overwrite_with_no_prompt(): |
37
|
|
|
repo_dir = vcs.clone( |
38
|
|
|
'https://github.com/audreyr/cookiecutter-pypackage.git', |
39
|
|
|
no_input=True |
40
|
|
|
) |
41
|
|
|
assert repo_dir == 'cookiecutter-pypackage' |
42
|
|
|
assert os.path.isfile('cookiecutter-pypackage/README.rst') |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
@skipif_no_network |
46
|
|
|
def test_git_clone_cancel(monkeypatch): |
47
|
|
|
monkeypatch.setattr( |
48
|
|
|
'cookiecutter.vcs.read_user_yes_no', |
49
|
|
|
lambda question, default: False |
50
|
|
|
) |
51
|
|
|
|
52
|
|
|
with pytest.raises(SystemExit): |
53
|
|
|
vcs.clone('https://github.com/audreyr/cookiecutter-pypackage.git') |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
@skipif_no_hg |
57
|
|
|
@skipif_no_network |
58
|
|
|
def test_hg_clone_overwrite(monkeypatch): |
59
|
|
|
monkeypatch.setattr( |
60
|
|
|
'cookiecutter.vcs.read_user_yes_no', |
61
|
|
|
lambda question, default: True |
62
|
|
|
) |
63
|
|
|
repo_dir = vcs.clone( |
64
|
|
|
'https://bitbucket.org/pokoli/cookiecutter-trytonmodule' |
65
|
|
|
) |
66
|
|
|
assert repo_dir == 'cookiecutter-trytonmodule' |
67
|
|
|
assert os.path.isfile('cookiecutter-trytonmodule/README.rst') |
68
|
|
|
|
69
|
|
|
|
70
|
|
|
@skipif_no_hg |
71
|
|
|
@skipif_no_network |
72
|
|
|
def test_hg_clone_cancel(monkeypatch): |
73
|
|
|
monkeypatch.setattr( |
74
|
|
|
'cookiecutter.vcs.read_user_yes_no', |
75
|
|
|
lambda question, default: False |
76
|
|
|
) |
77
|
|
|
|
78
|
|
|
with pytest.raises(SystemExit): |
79
|
|
|
vcs.clone('https://bitbucket.org/pokoli/cookiecutter-trytonmodule') |
80
|
|
|
|