Completed
Pull Request — master (#1147)
by Lasse
02:19
created

test_line_length()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 4
rs 10
1
import os
2
import subprocess
3
import sys
4
from queue import Queue
5
6
sys.path.insert(0, ".")
7
import unittest
8
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
9
from bears.c_languages.CPPLintBear import CPPLintBear
10
from coalib.settings.Section import Section
11
from coalib.settings.Setting import Setting
12
13
14
class CPPLintBearTest(LocalBearTestHelper):
15
    def setUp(self):
16
        self.section = Section("test section")
17
        self.uut = CPPLintBear(self.section, Queue())
18
        self.test_file = os.path.join(os.path.dirname(__file__),
19
                                      "test_files",
20
                                      "cpplint_bear_test.cpp")
21
22
    def test_run(self):
23
        # Should yield missing copyright line
24
        self.assertLinesInvalid(self.uut, [], self.test_file)
25
26
        # Let's ignore legal issues
27
        self.section.append(Setting("cpplint_ignore", "legal"))
28
        self.assertLinesValid(self.uut, [], self.test_file)
29
30
    def test_line_length(self):
31
        self.section.append(Setting("cpplint_ignore", "legal"))
32
        self.section.append(Setting("max_line_length", "13"))
33
        self.assertLinesInvalid(self.uut, [], self.test_file)
34
35
36
def skip_test():
37
    try:
38
        subprocess.Popen(['cpplint', '--help'],
39
                         stdout=subprocess.PIPE,
40
                         stderr=subprocess.PIPE)
41
        return False
42
    except OSError:
43
        return "cpplint is not installed."
44
45
46
if __name__ == '__main__':
47
    unittest.main(verbosity=2)
48