Passed
Push — master ( c15633...7f6804 )
by Andrey
01:00
created

test_determine_repo_dir_finds_subdirectories.py (1 issue)

1
"""Tests around locally cached cookiecutter template repositories."""
2
import os
3
4
import pytest
5
6
from cookiecutter import exceptions, repository
7
8
9
@pytest.fixture
10
def template():
11
    """Fixture. Return simple string as template name."""
12
    return 'cookiecutter-pytest-plugin'
13
14
15
@pytest.fixture
16
def cloned_cookiecutter_path(user_config_data, template):
17
    """Fixture. Prepare folder structure for tests in this file."""
18
    cookiecutters_dir = user_config_data['cookiecutters_dir']
19
20
    cloned_template_path = os.path.join(cookiecutters_dir, template)
21
    if not os.path.exists(cloned_template_path):
22
        os.mkdir(cloned_template_path)  # might exist from other tests.
23
24
    subdir_template_path = os.path.join(cloned_template_path, 'my-dir')
25
    if not os.path.exists(subdir_template_path):
26
        os.mkdir(subdir_template_path)
27
    open(os.path.join(subdir_template_path, 'cookiecutter.json'), 'w')
28
29
    return subdir_template_path
30
31
32 View Code Duplication
def test_should_find_existing_cookiecutter(
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
33
    template, user_config_data, cloned_cookiecutter_path
34
):
35
    """Find `cookiecutter.json` in sub folder created by `cloned_cookiecutter_path`."""
36
    project_dir, cleanup = repository.determine_repo_dir(
37
        template=template,
38
        abbreviations={},
39
        clone_to_dir=user_config_data['cookiecutters_dir'],
40
        checkout=None,
41
        no_input=True,
42
        directory='my-dir',
43
    )
44
45
    assert cloned_cookiecutter_path == project_dir
46
    assert not cleanup
47
48
49
def test_local_repo_typo(template, user_config_data, cloned_cookiecutter_path):
50
    """Wrong pointing to `cookiecutter.json` sub-directory should raise."""
51
    with pytest.raises(exceptions.RepositoryNotFound) as err:
52
        repository.determine_repo_dir(
53
            template=template,
54
            abbreviations={},
55
            clone_to_dir=user_config_data['cookiecutters_dir'],
56
            checkout=None,
57
            no_input=True,
58
            directory='wrong-dir',
59
        )
60
61
    wrong_full_cookiecutter_path = os.path.join(
62
        os.path.dirname(cloned_cookiecutter_path), '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'), wrong_full_cookiecutter_path]
70
            ),
71
        )
72
    )
73