Completed
Push — master ( 2513d4...5ebdf1 )
by
unknown
01:04
created

fin_remove_additional_dirs()   B

Complexity

Conditions 5

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
dl 0
loc 9
rs 8.5454
1
# -*- coding: utf-8 -*-
2
3
"""
4
test_cookiecutter_local_no_input
5
--------------------------------
6
7
Tests formerly known from a unittest residing in test_main.py named
8
TestCookiecutterLocalNoInput.test_cookiecutter
9
TestCookiecutterLocalNoInput.test_cookiecutter_no_slash
10
TestCookiecutterLocalNoInput.test_cookiecutter_no_input_extra_context
11
TestCookiecutterLocalNoInput.test_cookiecutter_templated_context
12
"""
13
14
import os
15
import textwrap
16
import pytest
17
18
from cookiecutter import main, utils
19
20
21
@pytest.fixture(scope='function')
22
def remove_additional_dirs(request):
23
    """
24
    Remove special directories which are created during the tests.
25
    """
26
    def fin_remove_additional_dirs():
27
        if os.path.isdir('fake-project'):
28
            utils.rmtree('fake-project')
29
        if os.path.isdir('fake-project-extra'):
30
            utils.rmtree('fake-project-extra')
31
        if os.path.isdir('fake-project-templated'):
32
            utils.rmtree('fake-project-templated')
33
        if os.path.isdir('fake-project-dict'):
34
            utils.rmtree('fake-project-dict')
35
    request.addfinalizer(fin_remove_additional_dirs)
36
37
38
@pytest.fixture(params=['tests/fake-repo-pre/', 'tests/fake-repo-pre'])
39
def bake(request):
40
    """
41
    Run cookiecutter with the given input_dir path.
42
    """
43
    main.cookiecutter(request.param, no_input=True)
44
45
46
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs', 'bake')
47
def test_cookiecutter():
48
    assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}')
49
    assert not os.path.isdir('tests/fake-repo-pre/fake-project')
50
    assert os.path.isdir('fake-project')
51
    assert os.path.isfile('fake-project/README.rst')
52
    assert not os.path.exists('fake-project/json/')
53
54
55
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
56
def test_cookiecutter_no_input_extra_context():
57
    """
58
    `Call cookiecutter()` with `no_input=True` and `extra_context
59
    """
60
    main.cookiecutter(
61
        'tests/fake-repo-pre',
62
        no_input=True,
63
        extra_context={'repo_name': 'fake-project-extra'}
64
    )
65
    assert os.path.isdir('fake-project-extra')
66
67
68
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
69
def test_cookiecutter_templated_context():
70
    """
71
    `Call cookiecutter()` with `no_input=True` and templates in the
72
    cookiecutter.json file
73
    """
74
    main.cookiecutter(
75
        'tests/fake-repo-tmpl',
76
        no_input=True
77
    )
78
    assert os.path.isdir('fake-project-templated')
79
80
81
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
82
def test_cookiecutter_no_input_return_project_dir():
83
    """Call `cookiecutter()` with `no_input=True`."""
84
    project_dir = main.cookiecutter('tests/fake-repo-pre', no_input=True)
85
    assert project_dir == os.path.abspath('fake-project')
86
87
88
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
89
def test_cookiecutter_dict_values_in_context():
90
    project_dir = main.cookiecutter('tests/fake-repo-dict', no_input=True)
91
    assert project_dir == os.path.abspath('fake-project-dict')
92
93
    with open(os.path.join(project_dir, 'README.md')) as fh:
94
        contents = fh.read()
95
96
    assert contents == textwrap.dedent("""
97
        # README
98
99
100
        <dl>
101
          <dt>Format name:</dt>
102
          <dd>Bitmap</dd>
103
104
          <dt>Extension:</dt>
105
          <dd>bmp</dd>
106
107
          <dt>Applications:</dt>
108
          <dd>
109
              <ul>
110
              <li>Paint</li>
111
              <li>GIMP</li>
112
              </ul>
113
          </dd>
114
        </dl>
115
116
        <dl>
117
          <dt>Format name:</dt>
118
          <dd>Portable Network Graphic</dd>
119
120
          <dt>Extension:</dt>
121
          <dd>png</dd>
122
123
          <dt>Applications:</dt>
124
          <dd>
125
              <ul>
126
              <li>GIMP</li>
127
              </ul>
128
          </dd>
129
        </dl>
130
131
    """).lstrip()
132