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

bears.tests.linters.IndentBearTest.test_valid()   A

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 5
rs 9.4286
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