Completed
Pull Request — master (#1147)
by Lasse
02:15 queued 28s
created

bears.tests.c_languages.IndentBearTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %
Metric Value
dl 0
loc 34
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_invalid() 0 4 1
A setUp() 0 5 1
A test_valid() 0 6 1
A test_tab_width() 0 7 1
A test_tabs() 0 7 1
1
import subprocess
2
import sys
3
import unittest
4
from queue import Queue
5
6
sys.path.insert(0, ".")
7
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
8
from bears.c_languages.IndentBear import IndentBear
9
from coalib.settings.Section import Section
10
from coalib.settings.Setting import Setting
11
12
13
class IndentBearTest(LocalBearTestHelper):
14
    def setUp(self):
15
        self.section = Section('name')
16
        self.section.append(Setting("use_spaces", "true"))
17
        self.section.append(Setting("max_line_length", "80"))
18
        self.uut = IndentBear(self.section, Queue())
19
20
    def test_valid(self):
21
        self.assertLinesValid(self.uut, ["int\n",
22
                                         "main ()\n",
23
                                         "{\n",
24
                                         "    return 0;\n",
25
                                         "}\n"])
26
27
    def test_tab_width(self):
28
        self.section.append(Setting("tab_width", "2"))
29
        self.assertLinesValid(self.uut, ["int\n",
30
                                         "main ()\n",
31
                                         "{\n",
32
                                         "  return 0;\n",
33
                                         "}\n"])
34
35
    def test_tabs(self):
36
        self.section.append(Setting("use_spaces", "nope"))
37
        self.assertLinesValid(self.uut, ["int\n",
38
                                         "main ()\n",
39
                                         "{\n",
40
                                         "\treturn 0;\n",
41
                                         "}\n"])
42
43
    def test_invalid(self):
44
        self.assertLinesInvalid(self.uut, ["int main() {\n",
45
                                           "  return 0;\n",
46
                                           "}\n"])
47
48
49
def skip_test():
50
    try:
51
        subprocess.Popen([IndentBear.BINARY, '--version'],
52
                         stdout=subprocess.PIPE,
53
                         stderr=subprocess.PIPE)
54
        return False
55
    except OSError:
56
        return "indent is not installed."
57
58
59
if __name__ == '__main__':
60
    unittest.main(verbosity=2)
61