1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
import pytest |
3
|
|
|
|
4
|
|
|
from cookiecutter.config import BUILTIN_ABBREVIATIONS |
5
|
|
|
from cookiecutter.repository import ( |
6
|
|
|
is_zip_file, is_repo_url, expand_abbreviations |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
@pytest.fixture(params=[ |
11
|
|
|
'/path/to/zipfile.zip', |
12
|
|
|
'https://example.com/path/to/zipfile.zip', |
13
|
|
|
'http://example.com/path/to/zipfile.zip', |
14
|
|
|
]) |
15
|
|
|
def zipfile(request): |
16
|
|
|
return request.param |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def test_is_zip_file(zipfile): |
20
|
|
|
"""Verify is_repo_url works.""" |
21
|
|
|
assert is_zip_file(zipfile) is True |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
@pytest.fixture(params=[ |
25
|
|
|
'gitolite@server:team/repo', |
26
|
|
|
'[email protected]:audreyr/cookiecutter.git', |
27
|
|
|
'https://github.com/audreyr/cookiecutter.git', |
28
|
|
|
'git+https://private.com/gitrepo', |
29
|
|
|
'hg+https://private.com/mercurialrepo', |
30
|
|
|
'https://bitbucket.org/pokoli/cookiecutter.hg', |
31
|
|
|
]) |
32
|
|
|
def remote_repo_url(request): |
33
|
|
|
return request.param |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
def test_is_repo_url_for_remote_urls(remote_repo_url): |
37
|
|
|
"""Verify is_repo_url works.""" |
38
|
|
|
assert is_repo_url(remote_repo_url) is True |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
@pytest.fixture(params=[ |
42
|
|
|
'/audreyr/cookiecutter.git', |
43
|
|
|
'/home/audreyr/cookiecutter', |
44
|
|
|
( |
45
|
|
|
'c:\\users\\appveyor\\appdata\\local\\temp\\1\\pytest-0\\' |
46
|
|
|
'test_default_output_dir0\\template' |
47
|
|
|
), |
48
|
|
|
]) |
49
|
|
|
def local_repo_url(request): |
50
|
|
|
return request.param |
51
|
|
|
|
52
|
|
|
|
53
|
|
|
def test_is_repo_url_for_local_urls(local_repo_url): |
54
|
|
|
"""Verify is_repo_url works.""" |
55
|
|
|
assert is_repo_url(local_repo_url) is False |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
def test_expand_abbreviations(): |
59
|
|
|
template = 'gh:audreyr/cookiecutter-pypackage' |
60
|
|
|
|
61
|
|
|
# This is not a valid repo url just yet! |
62
|
|
|
# First `repository.expand_abbreviations` needs to translate it |
63
|
|
|
assert is_repo_url(template) is False |
64
|
|
|
|
65
|
|
|
expanded_template = expand_abbreviations(template, BUILTIN_ABBREVIATIONS) |
66
|
|
|
assert is_repo_url(expanded_template) is True |
67
|
|
|
|