Issues (31)

test_determine_repository_should_use_local_repo.py (2 issues)

1
"""Tests around using locally cached cookiecutter template repositories."""
2
3
from pathlib import Path
4
5
import pytest
6
7
from cookiecutter import repository, exceptions
8
9
10
def test_finds_local_repo(tmp_path):
11
    """A valid local repository should be returned."""
12
    project_dir, cleanup = repository.determine_repo_dir(
13
        'tests/fake-repo',
14
        abbreviations={},
15
        clone_to_dir=str(tmp_path),
16
        checkout=None,
17
        no_input=True,
18
    )
19
20
    assert 'tests/fake-repo' == project_dir
21
    assert not cleanup
22
23
24 View Code Duplication
def test_local_repo_with_no_context_raises(tmp_path):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
25
    """A local repository without a cookiecutter.json should raise a \
26
    `RepositoryNotFound` exception."""
27
    template_path = str(Path('tests', 'fake-repo-bad'))
28
    with pytest.raises(exceptions.RepositoryNotFound) as err:
29
        repository.determine_repo_dir(
30
            template_path,
31
            abbreviations={},
32
            clone_to_dir=str(tmp_path),
33
            checkout=None,
34
            no_input=True,
35
        )
36
37
    assert str(err.value) == (
38
        'A valid repository for "{}" could not be found in the following '
39
        'locations:\n{}'.format(
40
            template_path,
41
            '\n'.join(
42
                [template_path, str(tmp_path.joinpath('tests', 'fake-repo-bad'))]
43
            ),
44
        )
45
    )
46
47
48 View Code Duplication
def test_local_repo_typo(tmp_path):
0 ignored issues
show
This code seems to be duplicated in your project.
Loading history...
49
    """An unknown local repository should raise a `RepositoryNotFound` \
50
    exception."""
51
    template_path = str(Path('tests', 'unknown-repo'))
52
    with pytest.raises(exceptions.RepositoryNotFound) as err:
53
        repository.determine_repo_dir(
54
            template_path,
55
            abbreviations={},
56
            clone_to_dir=str(tmp_path),
57
            checkout=None,
58
            no_input=True,
59
        )
60
61
    assert str(err.value) == (
62
        'A valid repository for "{}" could not be found in the following '
63
        'locations:\n{}'.format(
64
            template_path,
65
            '\n'.join([template_path, str(tmp_path.joinpath('tests', 'unknown-repo'))]),
66
        )
67
    )
68