Completed
Push — update-cookiecutter-command ( e74ec6...6578ae )
by Michael
01:07
created

tests.remove_additional_dirs()   A

Complexity

Conditions 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 11
rs 9.2

1 Method

Rating   Name   Duplication   Size   Complexity  
A tests.fin_remove_additional_dirs() 0 5 3
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
"""
5
test_cookiecutter_local_with_input
6
----------------------------------
7
8
Tests formerly known from a unittest residing in test_main.py named
9
TestCookiecutterLocalWithInput.test_cookiecutter_local_with_input
10
TestCookiecutterLocalWithInput.test_cookiecutter_input_extra_context
11
"""
12
13
import os
14
import pytest
15
16
from cookiecutter import main, utils
17
18
19
@pytest.fixture(scope='function')
20
def remove_additional_dirs(request):
21
    """
22
    Remove special directories which are created during the tests.
23
    """
24
    def fin_remove_additional_dirs():
25
        if os.path.isdir('fake-project'):
26
            utils.rmtree('fake-project')
27
        if os.path.isdir('fake-project-input-extra'):
28
            utils.rmtree('fake-project-input-extra')
29
    request.addfinalizer(fin_remove_additional_dirs)
30
31
32
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
33
def test_cookiecutter_local_with_input(monkeypatch):
34
    monkeypatch.setattr(
35
        'cookiecutter.prompt.read_user_variable',
36
        lambda var, default: default
37
    )
38
    main.cookiecutter('tests/fake-repo-pre/', no_input=False)
39
    assert os.path.isdir('tests/fake-repo-pre/{{cookiecutter.repo_name}}')
40
    assert not os.path.isdir('tests/fake-repo-pre/fake-project')
41
    assert os.path.isdir('fake-project')
42
    assert os.path.isfile('fake-project/README.rst')
43
    assert not os.path.exists('fake-project/json/')
44
45
46
@pytest.mark.usefixtures('clean_system', 'remove_additional_dirs')
47
def test_cookiecutter_input_extra_context(monkeypatch):
48
    """
49
    `Call cookiecutter()` with `no_input=False` and `extra_context`
50
    """
51
    monkeypatch.setattr(
52
        'cookiecutter.prompt.read_user_variable',
53
        lambda var, default: default
54
    )
55
    main.cookiecutter(
56
        'tests/fake-repo-pre',
57
        no_input=False,
58
        extra_context={'repo_name': 'fake-project-input-extra'}
59
    )
60
    assert os.path.isdir('fake-project-input-extra')
61