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

bears.tests.python.PEP8BearTest   A

Complexity

Total Complexity 5

Size/Duplication

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A test_line_length() 0 4 1
A test_invalid() 0 3 1
A test_valid() 0 3 1
A test_disable_warnings() 0 9 1
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_disable_warnings(self):
28
        test_code = ['def func():\n',
29
                     '    pass\n',
30
                     'def func2():\n',
31
                     '    pass\n']
32
        self.assertLinesInvalid(self.uut, test_code)
33
34
        self.section.append(Setting('pep_ignore', 'E302'))
35
        self.assertLinesValid(self.uut, test_code)
36
37
    def test_invalid(self):
38
        self.assertLinesInvalid(self.uut, [""])
39
        self.assertLinesInvalid(self.uut, ["a=1+1"])
40
41
42
if __name__ == '__main__':
43
    unittest.main(verbosity=2)
44