test_generate_copy_without_render_extensions()   F
last analyzed

Complexity

Conditions 15

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 15
dl 0
loc 44
rs 2.7451
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like test_generate_copy_without_render_extensions() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
# -*- coding: utf-8 -*-
2
3
"""
4
test_generate_copy_without_render
5
---------------------------------
6
"""
7
8
from __future__ import unicode_literals
9
import os
10
import pytest
11
12
from cookiecutter import generate
13
from cookiecutter import utils
14
15
16
@pytest.fixture(scope='function')
17
def remove_test_dir(request):
18
    """
19
    Remove the folder that is created by the test.
20
    """
21
    def fin_remove_test_dir():
22
        if os.path.exists('test_copy_without_render'):
23
            utils.rmtree('test_copy_without_render')
24
    request.addfinalizer(fin_remove_test_dir)
25
26
27
@pytest.mark.usefixtures('clean_system', 'remove_test_dir')
28
def test_generate_copy_without_render_extensions():
29
    generate.generate_files(
30
        context={
31
            'cookiecutter': {
32
                'repo_name': 'test_copy_without_render',
33
                'render_test': 'I have been rendered!',
34
                '_copy_without_render': [
35
                    '*not-rendered',
36
                    'rendered/not_rendered.yml',
37
                    '*.txt',
38
                ]}
39
        },
40
        repo_dir='tests/test-generate-copy-without-render'
41
    )
42
43
    dir_contents = os.listdir('test_copy_without_render')
44
45
    assert '{{cookiecutter.repo_name}}-not-rendered' in dir_contents
46
    assert 'test_copy_without_render-rendered' in dir_contents
47
48
    with open('test_copy_without_render/README.txt') as f:
49
        assert '{{cookiecutter.render_test}}' in f.read()
50
51
    with open('test_copy_without_render/README.rst') as f:
52
        assert 'I have been rendered!' in f.read()
53
54
    with open('test_copy_without_render/'
55
              'test_copy_without_render-rendered/'
56
              'README.txt') as f:
57
        assert '{{cookiecutter.render_test}}' in f.read()
58
59
    with open('test_copy_without_render/'
60
              'test_copy_without_render-rendered/'
61
              'README.rst') as f:
62
        assert 'I have been rendered' in f.read()
63
64
    with open('test_copy_without_render/'
65
              '{{cookiecutter.repo_name}}-not-rendered/'
66
              'README.rst') as f:
67
        assert '{{cookiecutter.render_test}}' in f.read()
68
69
    with open('test_copy_without_render/rendered/not_rendered.yml') as f:
70
        assert '{{cookiecutter.render_test}}' in f.read()
71