Completed
Pull Request — master (#694)
by Eric
02:14
created

TestRealHooksAcceptance   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 37
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_renderable_hooks_can_be_run() 0 7 2
A _repo_id() 0 2 1
A test_run_real_hook_in_place() 0 5 1
A assert_real_hook_is_run_in_place() 0 11 3
A test_run_real_hook_in_place_shell() 0 6 2
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
"""
5
test_real_hooks_acceptance
6
--------------------------
7
8
Additional tests for `cookiecutter.hooks` module.
9
"""
10
11
import os
12
import sys
13
14
15
from .support import read_file, AbstractAcceptanceTest
16
17
18
class TestRealHooksAcceptance(AbstractAcceptanceTest):
19
20
    def _repo_id(self):
21
        return 'test-real-hooks-acceptance'
22
23
    def assert_real_hook_is_run_in_place(self, template):
24
        """
25
        assert that the real hook is run in place
26
        :param template: template id
27
        """
28
        template_dir = os.path.join(self.templates_path, template)
29
        file = os.path.join(self.project_dir, template)
30
        self.run(template)
31
        assert os.path.exists(file)
32
        content = read_file(file)
33
        assert template_dir == content.strip()
34
35
    def test_renderable_hooks_can_be_run(self):
36
        """
37
        regression test
38
        """
39
        template = 'renderable'
40
        self.run(template)
41
        assert os.path.exists(os.path.join(self.project_dir, template))
42
43
    def test_run_real_hook_in_place(self):
44
        """
45
        run a real hook in place: python file
46
        """
47
        self.assert_real_hook_is_run_in_place('inplace')
48
49
    def test_run_real_hook_in_place_shell(self):
50
        """
51
        run a real hook in place: bash or batch file depending on the OS
52
        """
53
        template = 'batch' if sys.platform.startswith('win') else 'bash'
54
        self.assert_real_hook_is_run_in_place(template)
55