test_is_repo_url   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 40
dl 0
loc 76
rs 10
c 0
b 0
f 0

7 Functions

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