Completed
Push — break-up-hooks-tests ( 90c82a )
by Michael
01:19
created

test_find_hook_ignores_backup_files()   A

Complexity

Conditions 3

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 4
rs 10
1
# -*- coding: utf-8 -*-
2
3
import pytest
4
import textwrap
5
6
from cookiecutter import hooks
7
8
9
@pytest.yield_fixture
10
def dir_with_hooks(tmpdir):
11
    """Yield a directory that contains hook backup files."""
12
13
    hooks_dir = tmpdir.mkdir('hooks')
14
15
    pre_hook_content = textwrap.dedent(
16
        u"""
17
        #!/usr/bin/env python
18
        # -*- coding: utf-8 -*-
19
        print('pre_gen_project.py~')
20
        """
21
    )
22
    pre_gen_hook_file = hooks_dir / 'pre_gen_project.py~'
23
    pre_gen_hook_file.write_text(pre_hook_content, encoding='utf8')
24
25
    post_hook_content = textwrap.dedent(
26
        u"""
27
        #!/usr/bin/env python
28
        # -*- coding: utf-8 -*-
29
        print('post_gen_project.py~')
30
        """
31
    )
32
33
    post_gen_hook_file = hooks_dir / 'post_gen_project.py~'
34
    post_gen_hook_file.write_text(post_hook_content, encoding='utf8')
35
36
    # Make sure to yield the parent directory as `find_hooks()`
37
    # looks into `hooks/` in the current working directory
38
    yield str(tmpdir)
39
40
    pre_gen_hook_file.remove()
41
    post_gen_hook_file.remove()
42
43
44
def test_find_hook_ignores_backup_files(monkeypatch, dir_with_hooks):
45
    monkeypatch.chdir(dir_with_hooks)
46
    assert hooks.find_hook('pre_gen_project') is None
47
    assert hooks.find_hook('post_gen_project') is None
48