-
Notifications
You must be signed in to change notification settings - Fork 581
/
Copy pathSpaceConsistencyBearTest.py
96 lines (80 loc) · 4.09 KB
/
SpaceConsistencyBearTest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from queue import Queue
from bears.general.SpaceConsistencyBear import (
SpaceConsistencyBear, SpacingHelper)
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
class SpaceConsistencyBearTest(LocalBearTestHelper):
def setUp(self):
self.section = Section('test section')
self.uut = SpaceConsistencyBear(self.section, Queue())
def test_needed_settings(self):
self.section.append(Setting('use_spaces', 'true'))
needed_settings = self.uut.get_non_optional_settings()
self.assertEqual(len(needed_settings),
1 + len(SpacingHelper.get_non_optional_settings()))
self.assertIn('use_spaces', needed_settings)
def test_defaults(self):
# use_spaces is no default, need to set it explicitly.
self.section.append(Setting('use_spaces', 'true'))
self.check_validity(self.uut, [' t'])
self.check_invalidity(self.uut, ['\tt'])
self.check_invalidity(self.uut, ['t \n'])
self.check_invalidity(self.uut, ['t'],
force_linebreaks=False)
def test_data_sets_spaces(self):
self.section.append(Setting('use_spaces', 'true'))
self.section.append(Setting('allow_trailing_whitespace', 'false'))
self.section.append(Setting('enforce_newline_at_EOF', 'false'))
self.check_validity(self.uut, [' t'])
self.check_invalidity(self.uut, ['t \n'])
self.check_invalidity(self.uut, ['\tt\n'])
def test_data_sets_tabs(self):
self.section.append(Setting('use_spaces', 'false'))
self.section.append(Setting('allow_trailing_whitespace', 'true'))
self.section.append(Setting('enforce_newline_at_EOF', 'false'))
self.section.append(Setting('allow_leading_blanklines', 'false'))
self.check_invalidity(self.uut, [' t'])
self.check_validity(self.uut, ['t \n'])
self.check_validity(self.uut, ['\tt\n'])
self.check_validity(self.uut, [])
def test_enforce_newline_at_eof(self):
self.section.append(Setting('use_spaces', 'true'))
self.section.append(Setting('allow_trailing_whitespace', 'true'))
self.section.append(Setting('enforce_newline_at_EOF', 'true'))
self.section.append(Setting('allow_leading_blanklines', 'true'))
self.check_validity(self.uut,
['hello world \n'],
force_linebreaks=False)
self.check_validity(self.uut,
['def somecode():\n',
[' \n',
'\n',
' \n',
'def somecode():\n',
" print('funny')\n",
" print('funny end.')\n"],
force_linebreaks=False)
self.check_invalidity(self.uut,
[' no hello world'],
force_linebreaks=False)
self.check_invalidity(self.uut,
['def unfunny_code():\n',
" print('funny')\n",
" print('the result is not funny...')"],
force_linebreaks=False)
def test_leading_blanklines(self):
self.section.append(Setting('use_spaces', 'true'))
self.section.append(Setting('allow_trailing_whitespace', 'false'))
self.section.append(Setting('enforce_newline_at_EOF', 'true'))
self.section.append(Setting('allow_leading_blanklines', 'false'))
self.check_invalidity(self.uut,
['\n',
' \n',
'def code():\n',
" print('Am I coding?')\n"],
force_linebreaks=False)
self.check_validity(self.uut,
['def code():\n',
" print('Am I coding?')\n"],
force_linebreaks=False)