|
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
|
|
|
|