Completed
Pull Request — master (#1073)
by Lasse
01:56
created

bears.tests.linters.IndentBearTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %
Metric Value
dl 0
loc 23
rs 10
wmc 4

4 Methods

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