|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
import os |
|
4
|
|
|
import shutil |
|
5
|
|
|
|
|
6
|
|
|
import pytest |
|
7
|
|
|
|
|
8
|
|
|
from cookiecutter import repository |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
@pytest.fixture(params=[ |
|
12
|
|
|
'gitolite@server:team/repo', |
|
13
|
|
|
'[email protected]:audreyr/cookiecutter.git', |
|
14
|
|
|
'https://github.com/audreyr/cookiecutter.git', |
|
15
|
|
|
'git+https://private.com/gitrepo', |
|
16
|
|
|
'hg+https://private.com/mercurialrepo', |
|
17
|
|
|
'https://bitbucket.org/pokoli/cookiecutter.hg', |
|
18
|
|
|
]) |
|
19
|
|
|
def remote_repo_url(request): |
|
20
|
|
|
return request.param |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
def test_is_repo_url_for_remote_urls(remote_repo_url): |
|
24
|
|
|
"""Verify is_repo_url works.""" |
|
25
|
|
|
assert repository.is_repo_url(remote_repo_url) is True |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
@pytest.fixture(params=[ |
|
29
|
|
|
'/audreyr/cookiecutter.git', |
|
30
|
|
|
'/home/audreyr/cookiecutter', |
|
31
|
|
|
( |
|
32
|
|
|
'c:\\users\\appveyor\\appdata\\local\\temp\\1\\pytest-0\\' |
|
33
|
|
|
'test_default_output_dir0\\template' |
|
34
|
|
|
), |
|
35
|
|
|
]) |
|
36
|
|
|
def local_repo_url(request): |
|
37
|
|
|
return request.param |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
def test_is_repo_url_for_local_urls(local_repo_url): |
|
41
|
|
|
"""Verify is_repo_url works.""" |
|
42
|
|
|
assert repository.is_repo_url(local_repo_url) is False |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
def test_expand_abbreviations(): |
|
46
|
|
|
template = 'gh:audreyr/cookiecutter-pypackage' |
|
47
|
|
|
|
|
48
|
|
|
# This is not a valid repo url just yet! |
|
49
|
|
|
# First `main.expand_abbreviations` needs to translate it |
|
50
|
|
|
assert repository.is_repo_url(template) is False |
|
51
|
|
|
|
|
52
|
|
|
expanded_template = repository.expand_abbreviations(template, {}) |
|
53
|
|
|
assert repository.is_repo_url(expanded_template) is True |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
@pytest.fixture |
|
57
|
|
|
def template_url(): |
|
58
|
|
|
"""URL to example Cookiecutter template on GitHub. |
|
59
|
|
|
|
|
60
|
|
|
Note: when used, git clone is mocked. |
|
61
|
|
|
""" |
|
62
|
|
|
return 'https://github.com/pytest-dev/cookiecutter-pytest-plugin.git' |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
def test_repository_url_should_clone( |
|
66
|
|
|
mocker, template_url, output_dir, user_config_file, user_config_data): |
|
67
|
|
|
"""`clone()` should be called with correct args when `resolve_repo_dir()` is |
|
68
|
|
|
called. |
|
69
|
|
|
""" |
|
70
|
|
|
mock_clone = mocker.patch( |
|
71
|
|
|
'cookiecutter.repository.clone', |
|
72
|
|
|
return_value='tests/fake-repo-tmpl', |
|
73
|
|
|
autospec=True |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
project_dir = repository.resolve_repo_dir( |
|
77
|
|
|
template=template_url, |
|
78
|
|
|
checkout=None, |
|
79
|
|
|
cookiecutters_dir=user_config_data['cookiecutters_dir'], |
|
80
|
|
|
no_input=True |
|
81
|
|
|
) |
|
82
|
|
|
|
|
83
|
|
|
mock_clone.assert_called_once_with( |
|
84
|
|
|
repo_url=template_url, |
|
85
|
|
|
checkout=None, |
|
86
|
|
|
clone_to_dir=user_config_data['cookiecutters_dir'], |
|
87
|
|
|
no_input=True |
|
88
|
|
|
) |
|
89
|
|
|
|
|
90
|
|
|
assert os.path.isdir(project_dir) |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
def test_local_repo_template(user_config_data): |
|
94
|
|
|
template = 'tests/fake-repo-tmpl' |
|
95
|
|
|
|
|
96
|
|
|
project_dir = repository.resolve_repo_dir( |
|
97
|
|
|
template=template, |
|
98
|
|
|
checkout=None, |
|
99
|
|
|
cookiecutters_dir=user_config_data['cookiecutters_dir'], |
|
100
|
|
|
no_input=True |
|
101
|
|
|
) |
|
102
|
|
|
|
|
103
|
|
|
assert os.path.isdir(project_dir) |
|
104
|
|
|
assert project_dir == template |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
def test_already_cloned_repo(user_config_data): |
|
108
|
|
|
cookiecutters_dir = user_config_data['cookiecutters_dir'] |
|
109
|
|
|
cloned_template = os.path.join(cookiecutters_dir, 'fake-repo-tmpl') |
|
110
|
|
|
shutil.copytree('tests/fake-repo-tmpl', cloned_template) |
|
111
|
|
|
|
|
112
|
|
|
project_dir = repository.resolve_repo_dir( |
|
113
|
|
|
template='fake-repo-tmpl', |
|
114
|
|
|
checkout=None, |
|
115
|
|
|
cookiecutters_dir=user_config_data['cookiecutters_dir'], |
|
116
|
|
|
no_input=True |
|
117
|
|
|
) |
|
118
|
|
|
|
|
119
|
|
|
assert os.path.isdir(project_dir) |
|
120
|
|
|
assert project_dir == cloned_template |
|
121
|
|
|
|