Completed
Push — master ( 14c8ac...ce45ac )
by Michael
7s
created

test_generate_copy_without_render_extensions()   F

Complexity

Conditions 15

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 15
dl 0
loc 44
rs 2.7451

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