forked from cookiecutter/cookiecutter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_identify_repo.py
70 lines (63 loc) · 2.51 KB
/
test_identify_repo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""Collection of tests around repository type identification."""
import pytest
from cookiecutter import exceptions, vcs
@pytest.mark.parametrize(
'repo_url, exp_repo_type, exp_repo_url',
[
(
'git+https://github.com/pytest-dev/cookiecutter-pytest-plugin.git',
'git',
'https://github.com/pytest-dev/cookiecutter-pytest-plugin.git',
),
(
'hg+https://bitbucket.org/foo/bar.hg',
'hg',
'https://bitbucket.org/foo/bar.hg',
),
(
'https://github.com/pytest-dev/cookiecutter-pytest-plugin.git',
'git',
'https://github.com/pytest-dev/cookiecutter-pytest-plugin.git',
),
('https://bitbucket.org/foo/bar.hg', 'hg', 'https://bitbucket.org/foo/bar.hg'),
(
'https://github.com/audreyfeldroy/cookiecutter-pypackage.git',
'git',
'https://github.com/audreyfeldroy/cookiecutter-pypackage.git',
),
(
'https://github.com/audreyfeldroy/cookiecutter-pypackage',
'git',
'https://github.com/audreyfeldroy/cookiecutter-pypackage',
),
(
'git@gitorious.org:cookiecutter-gitorious/cookiecutter-gitorious.git',
'git',
'git@gitorious.org:cookiecutter-gitorious/cookiecutter-gitorious.git',
),
(
'https://audreyr@bitbucket.org/audreyr/cookiecutter-bitbucket',
'hg',
'https://audreyr@bitbucket.org/audreyr/cookiecutter-bitbucket',
),
],
)
def test_identify_known_repo(repo_url, exp_repo_type, exp_repo_url):
"""Verify different correct repositories url syntax is correctly transformed."""
assert vcs.identify_repo(repo_url) == (exp_repo_type, exp_repo_url)
@pytest.fixture(
params=[
'foo+git', # uses explicit identifier with 'git' in the wrong place
'foo+hg', # uses explicit identifier with 'hg' in the wrong place
'foo+bar', # uses explicit identifier with neither 'git' nor 'hg'
'foobar', # no identifier but neither 'git' nor 'bitbucket' in url
'http://norepotypespecified.com',
]
)
def unknown_repo_type_url(request):
"""Fixture. Return wrong formatted repository url."""
return request.param
def test_identify_raise_on_unknown_repo(unknown_repo_type_url):
"""Verify different incorrect repositories url syntax trigger error raising."""
with pytest.raises(exceptions.UnknownRepoType):
vcs.identify_repo(unknown_repo_type_url)