Completed
Pull Request — master (#1147)
by Lasse
01:47
created

test_indent_level()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 8
rs 9.4286
1
import sys
2
import unittest
3
from queue import Queue
4
5
sys.path.insert(0, ".")
6
from bears.tests.LocalBearTestHelper import LocalBearTestHelper
7
from bears.python.PEP8Bear import PEP8Bear
8
from coalib.settings.Section import Section
9
from coalib.settings.Setting import Setting
10
11
12
class PEP8BearTest(LocalBearTestHelper):
13
    def setUp(self):
14
        self.section = Section('name')
15
        self.section.append(Setting('max_line_length', '80'))
16
        self.uut = PEP8Bear(self.section, Queue())
17
18
    def test_valid(self):
19
        self.assertLinesValid(self.uut, ["import sys"])
20
        self.assertLinesValid(self.uut, ["a = 1 + 1"])
21
22
    def test_line_length(self):
23
        self.assertLinesValid(self.uut, ["a = 1 + 1 + 1 + 1 + 1 + 1 + 1"])
24
        self.section.append(Setting('max_line_length', '10'))
25
        self.assertLinesInvalid(self.uut, ["a = 1 + 1 + 1 + 1 + 1 + 1 + 1"])
26
27
    def test_indent_level(self):
28
        test_code = ['def func():\n',
29
                     '    pass\n']
30
        self.assertLinesValid(self.uut, test_code)
31
32
        self.section.append(Setting('tab_width', '2'))
33
        self.assertLinesInvalid(self.uut, test_code)
34
        self.assertLinesValid(self.uut, ['def func():\n', '  pass\n'])
35
36
    def test_disable_warnings(self):
37
        test_code = ['def func():\n',
38
                     '    pass\n',
39
                     'def func2():\n',
40
                     '    pass\n']
41
        self.assertLinesInvalid(self.uut, test_code)
42
43
        self.section.append(Setting('pep_ignore', 'E302'))
44
        self.assertLinesValid(self.uut, test_code)
45
46
    def test_invalid(self):
47
        self.assertLinesInvalid(self.uut, [""])
48
        self.assertLinesInvalid(self.uut, ["a=1+1"])
49
50
51
if __name__ == '__main__':
52
    unittest.main(verbosity=2)
53