1
|
|
|
"""This module is for testing the indent rainmeter module.""" |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
import sys |
5
|
|
|
|
6
|
|
|
from unittest import TestCase |
7
|
|
|
|
8
|
|
|
INDENT = sys.modules["Rainmeter.indentrainmeter"] |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def indention_depth_from_initial(line): |
12
|
|
|
return INDENT.calc_line_indention_depth(line, INDENT.IndentType.Initial, 0) |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
def indention_depth_from_fold(line): |
16
|
|
|
return INDENT.calc_line_indention_depth(line, INDENT.IndentType.FoldMarker, 1) |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def indention_depth_from_section(line): |
20
|
|
|
return INDENT.calc_line_indention_depth(line, INDENT.IndentType.Section, 1) |
21
|
|
|
|
22
|
|
|
|
23
|
|
View Code Duplication |
class TestCalcLineIndentionDepthFromInitial(TestCase): |
|
|
|
|
24
|
|
|
""".""" |
25
|
|
|
|
26
|
|
|
def test_with_empty_line(self): |
27
|
|
|
line = "" |
28
|
|
|
indention_depth = indention_depth_from_initial(line) |
29
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Initial, 0)) |
30
|
|
|
|
31
|
|
|
def test_with_comment(self): |
32
|
|
|
line = "; This is a comment" |
33
|
|
|
indention_depth = indention_depth_from_initial(line) |
34
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Initial, 0)) |
35
|
|
|
|
36
|
|
|
def test_with_fold_marker(self): |
37
|
|
|
line = ";; This is a fold marker" |
38
|
|
|
indention_depth = indention_depth_from_initial(line) |
39
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.FoldMarker, 1)) |
40
|
|
|
|
41
|
|
|
def test_with_section(self): |
42
|
|
|
line = "[Section]" |
43
|
|
|
indention_depth = indention_depth_from_initial(line) |
44
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Section, 1)) |
45
|
|
|
|
46
|
|
|
def test_with_key_value(self): |
47
|
|
|
line = "Key = Value" |
48
|
|
|
indention_depth = indention_depth_from_initial(line) |
49
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Initial, 0)) |
50
|
|
|
|
51
|
|
|
|
52
|
|
View Code Duplication |
class TestCalcLineIndentionDepthFromFoldMarker(TestCase): |
|
|
|
|
53
|
|
|
""".""" |
54
|
|
|
|
55
|
|
|
def test_with_empty_line(self): |
56
|
|
|
line = "" |
57
|
|
|
indention_depth = indention_depth_from_fold(line) |
58
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.FoldMarker, 1)) |
59
|
|
|
|
60
|
|
|
def test_with_comment(self): |
61
|
|
|
line = "; This is a comment" |
62
|
|
|
indention_depth = indention_depth_from_fold(line) |
63
|
|
|
self.assertEqual(indention_depth, (1, INDENT.IndentType.FoldMarker, 1)) |
64
|
|
|
|
65
|
|
|
def test_with_fold_marker(self): |
66
|
|
|
line = ";; This is a fold marker" |
67
|
|
|
indention_depth = indention_depth_from_fold(line) |
68
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.FoldMarker, 1)) |
69
|
|
|
|
70
|
|
|
def test_with_section(self): |
71
|
|
|
line = "[Section]" |
72
|
|
|
indention_depth = indention_depth_from_fold(line) |
73
|
|
|
self.assertEqual(indention_depth, (1, INDENT.IndentType.Section, 2)) |
74
|
|
|
|
75
|
|
|
def test_with_key_value(self): |
76
|
|
|
line = "Key = Value" |
77
|
|
|
indention_depth = indention_depth_from_fold(line) |
78
|
|
|
self.assertEqual(indention_depth, (1, INDENT.IndentType.FoldMarker, 1)) |
79
|
|
|
|
80
|
|
|
|
81
|
|
View Code Duplication |
class TestCalcLineIndentionDepthFromSection(TestCase): |
|
|
|
|
82
|
|
|
""".""" |
83
|
|
|
|
84
|
|
|
def test_with_empty_line(self): |
85
|
|
|
line = "" |
86
|
|
|
indention_depth = indention_depth_from_section(line) |
87
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Section, 1)) |
88
|
|
|
|
89
|
|
|
def test_with_comment(self): |
90
|
|
|
line = "; This is a comment" |
91
|
|
|
indention_depth = indention_depth_from_section(line) |
92
|
|
|
self.assertEqual(indention_depth, (1, INDENT.IndentType.Section, 1)) |
93
|
|
|
|
94
|
|
|
def test_with_fold_marker(self): |
95
|
|
|
line = ";; This is a fold marker" |
96
|
|
|
indention_depth = indention_depth_from_section(line) |
97
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.FoldMarker, 1)) |
98
|
|
|
|
99
|
|
|
def test_with_section(self): |
100
|
|
|
line = "[Section]" |
101
|
|
|
indention_depth = indention_depth_from_section(line) |
102
|
|
|
self.assertEqual(indention_depth, (0, INDENT.IndentType.Section, 1)) |
103
|
|
|
|
104
|
|
|
def test_with_key_value(self): |
105
|
|
|
line = "Key = Value" |
106
|
|
|
indention_depth = indention_depth_from_section(line) |
107
|
|
|
self.assertEqual(indention_depth, (1, INDENT.IndentType.Section, 1)) |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
class TestIndentWholeSection(TestCase): |
111
|
|
|
"""This is about testing a whole function test.""" |
112
|
|
|
|
113
|
|
|
def test_one_section(self): |
114
|
|
|
""".""" |
115
|
|
|
content = ''' |
116
|
|
|
[Rainmeter] |
117
|
|
|
Update=1000 |
118
|
|
|
DynamicWindowSize=1 |
119
|
|
|
DefaultUpdateDivider=1000 |
120
|
|
|
AccurateText=1 |
121
|
|
|
OnWakeAction=[!Refresh "(Config)"]''' |
122
|
|
|
|
123
|
|
|
result = ''' |
124
|
|
|
[Rainmeter] |
125
|
|
|
\tUpdate=1000 |
126
|
|
|
\tDynamicWindowSize=1 |
127
|
|
|
\tDefaultUpdateDivider=1000 |
128
|
|
|
\tAccurateText=1 |
129
|
|
|
\tOnWakeAction=[!Refresh "(Config)"]''' |
130
|
|
|
|
131
|
|
|
reference = INDENT.indent_text_by_tab_size(content) |
132
|
|
|
|
133
|
|
|
self.assertEqual(reference, result) |
134
|
|
|
|
135
|
|
|
def test_two_sections(self): |
136
|
|
|
""".""" |
137
|
|
|
content = ''' |
138
|
|
|
[Rainmeter] |
139
|
|
|
Update=1000 |
140
|
|
|
DynamicWindowSize=1 |
141
|
|
|
DefaultUpdateDivider=1000 |
142
|
|
|
AccurateText=1 |
143
|
|
|
OnWakeAction=[!Refresh "(Config)"] |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
[Metadata] |
147
|
|
|
Name=TestEnvironment |
148
|
|
|
Author=thatsIch |
149
|
|
|
Information=PlayGround for Metadata |
150
|
|
|
Version=0.0.1 |
151
|
|
|
License=MIT''' |
152
|
|
|
|
153
|
|
|
result = ''' |
154
|
|
|
[Rainmeter] |
155
|
|
|
\tUpdate=1000 |
156
|
|
|
\tDynamicWindowSize=1 |
157
|
|
|
\tDefaultUpdateDivider=1000 |
158
|
|
|
\tAccurateText=1 |
159
|
|
|
\tOnWakeAction=[!Refresh "(Config)"] |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
[Metadata] |
163
|
|
|
\tName=TestEnvironment |
164
|
|
|
\tAuthor=thatsIch |
165
|
|
|
\tInformation=PlayGround for Metadata |
166
|
|
|
\tVersion=0.0.1 |
167
|
|
|
\tLicense=MIT''' |
168
|
|
|
|
169
|
|
|
reference = INDENT.indent_text_by_tab_size(content) |
170
|
|
|
|
171
|
|
|
self.assertEqual(reference, result) |
172
|
|
|
|
173
|
|
|
def test_section_with_divider(self): |
174
|
|
|
""".""" |
175
|
|
|
content = ''' |
176
|
|
|
;;==================================================== |
177
|
|
|
;; Rainmeter Section |
178
|
|
|
;;==================================================== |
179
|
|
|
[Rainmeter] |
180
|
|
|
Update=1000 |
181
|
|
|
DynamicWindowSize=1 |
182
|
|
|
DefaultUpdateDivider=1000 |
183
|
|
|
AccurateText=1 |
184
|
|
|
OnWakeAction=[!Refresh "(Config)"]''' |
185
|
|
|
|
186
|
|
|
result = ''' |
187
|
|
|
;;==================================================== |
188
|
|
|
;; Rainmeter Section |
189
|
|
|
;;==================================================== |
190
|
|
|
\t[Rainmeter] |
191
|
|
|
\t\tUpdate=1000 |
192
|
|
|
\t\tDynamicWindowSize=1 |
193
|
|
|
\t\tDefaultUpdateDivider=1000 |
194
|
|
|
\t\tAccurateText=1 |
195
|
|
|
\t\tOnWakeAction=[!Refresh "(Config)"]''' |
196
|
|
|
|
197
|
|
|
reference = INDENT.indent_text_by_tab_size(content) |
198
|
|
|
|
199
|
|
|
self.assertEqual(reference, result) |
200
|
|
|
|
201
|
|
|
def test_divider_with_two_sections(self): |
202
|
|
|
""".""" |
203
|
|
|
content = ''' |
204
|
|
|
;;==================================================== |
205
|
|
|
;; Rainmeter Section |
206
|
|
|
;;==================================================== |
207
|
|
|
[Rainmeter] |
208
|
|
|
Update=1000 |
209
|
|
|
DynamicWindowSize=1 |
210
|
|
|
DefaultUpdateDivider=1000 |
211
|
|
|
AccurateText=1 |
212
|
|
|
OnWakeAction=[!Refresh "(Config)"] |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
[Metadata] |
216
|
|
|
Name=TestEnvironment |
217
|
|
|
Author=thatsIch |
218
|
|
|
Information=PlayGround for Metadata |
219
|
|
|
Version=0.0.1 |
220
|
|
|
License=MIT''' |
221
|
|
|
|
222
|
|
|
result = ''' |
223
|
|
|
;;==================================================== |
224
|
|
|
;; Rainmeter Section |
225
|
|
|
;;==================================================== |
226
|
|
|
\t[Rainmeter] |
227
|
|
|
\t\tUpdate=1000 |
228
|
|
|
\t\tDynamicWindowSize=1 |
229
|
|
|
\t\tDefaultUpdateDivider=1000 |
230
|
|
|
\t\tAccurateText=1 |
231
|
|
|
\t\tOnWakeAction=[!Refresh "(Config)"] |
232
|
|
|
|
233
|
|
|
|
234
|
|
|
\t[Metadata] |
235
|
|
|
\t\tName=TestEnvironment |
236
|
|
|
\t\tAuthor=thatsIch |
237
|
|
|
\t\tInformation=PlayGround for Metadata |
238
|
|
|
\t\tVersion=0.0.1 |
239
|
|
|
\t\tLicense=MIT''' |
240
|
|
|
|
241
|
|
|
reference = INDENT.indent_text_by_tab_size(content) |
242
|
|
|
|
243
|
|
|
self.assertEqual(reference, result) |
244
|
|
|
|