Passed
Push — master ( a7bde6...b29ecb )
by
unknown
01:08
created

test_should_find_existing_cookiecutter()   A

Complexity

Conditions 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 11
dl 14
loc 14
rs 9.85
c 0
b 0
f 0
cc 1
nop 3
1
# -*- coding: utf-8 -*-
2
import io
3
import os
4
import pytest
5
6
from cookiecutter import repository, exceptions
7
8
9
@pytest.fixture
10
def template():
11
    return 'cookiecutter-pytest-plugin'
12
13
14
@pytest.fixture
15
def cloned_cookiecutter_path(user_config_data, template):
16
    cookiecutters_dir = user_config_data['cookiecutters_dir']
17
18
    cloned_template_path = os.path.join(cookiecutters_dir, template)
19
    if not os.path.exists(cloned_template_path):
20
        os.mkdir(cloned_template_path)  # might exist from other tests.
21
22
    subdir_template_path = os.path.join(cloned_template_path, 'my-dir')
23
    if not os.path.exists(subdir_template_path):
24
        os.mkdir(subdir_template_path)
25
    io.open(os.path.join(subdir_template_path, 'cookiecutter.json'), 'w')
26
27
    return subdir_template_path
28
29
30 View Code Duplication
def test_should_find_existing_cookiecutter(
0 ignored issues
show
Duplication introduced by RomHartmann
This code seems to be duplicated in your project.
Loading history...
31
        template, user_config_data, cloned_cookiecutter_path):
32
33
    project_dir, cleanup = repository.determine_repo_dir(
34
        template,
35
        abbreviations={},
36
        clone_to_dir=user_config_data['cookiecutters_dir'],
37
        checkout=None,
38
        no_input=True,
39
        directory='my-dir',
40
    )
41
42
    assert cloned_cookiecutter_path == project_dir
43
    assert not cleanup
44
45
46
def test_local_repo_typo(template, user_config_data, cloned_cookiecutter_path):
47
    """An unknown local repository should raise a `RepositoryNotFound`
48
    exception.
49
    """
50
    with pytest.raises(exceptions.RepositoryNotFound) as err:
51
        repository.determine_repo_dir(
52
            template,
53
            abbreviations={},
54
            clone_to_dir=user_config_data['cookiecutters_dir'],
55
            checkout=None,
56
            no_input=True,
57
            directory='wrong-dir',
58
        )
59
60
    wrong_full_cookiecutter_path = os.path.join(
61
        os.path.dirname(cloned_cookiecutter_path),
62
        'wrong-dir'
63
    )
64
    assert str(err.value) == (
65
        'A valid repository for "{}" could not be found in the following '
66
        'locations:\n{}'.format(
67
            template,
68
            '\n'.join([
69
                os.path.join(template, 'wrong-dir'),
70
                wrong_full_cookiecutter_path
71
            ]),
72
        )
73
    )
74