|
1
|
|
|
"""This module is for testing the completion compilers.""" |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
import sys |
|
5
|
|
|
|
|
6
|
|
|
from unittest import TestCase |
|
7
|
|
|
|
|
8
|
|
|
COMPLETION_COMPILER = sys.modules["Rainmeter.completion.compiler"] |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestCompletionCompilerKeys(TestCase): |
|
12
|
|
|
"""Test for the completion key compiler using unittest.""" |
|
13
|
|
|
|
|
14
|
|
|
def test_empty_same_size(self): |
|
15
|
|
|
""".""" |
|
16
|
|
|
options = list() |
|
17
|
|
|
|
|
18
|
|
|
compiled_key = COMPLETION_COMPILER.compile_keys(options) |
|
19
|
|
|
|
|
20
|
|
|
self.assertEqual(len(options), len(compiled_key)) |
|
21
|
|
|
|
|
22
|
|
|
def test_title_hint(self): |
|
23
|
|
|
""".""" |
|
24
|
|
|
options = [ |
|
25
|
|
|
{ |
|
26
|
|
|
"title": "test", |
|
27
|
|
|
"hint": "hint" |
|
28
|
|
|
} |
|
29
|
|
|
] |
|
30
|
|
|
|
|
31
|
|
|
actual = COMPLETION_COMPILER.compile_keys(options) |
|
32
|
|
|
|
|
33
|
|
|
expected = [ |
|
34
|
|
|
("test", "test\thint", "test", False) |
|
35
|
|
|
] |
|
36
|
|
|
|
|
37
|
|
|
self.assertEqual(actual, expected) |
|
38
|
|
|
|
|
39
|
|
|
def test_multiple_title_hint(self): |
|
40
|
|
|
""".""" |
|
41
|
|
|
options = [ |
|
42
|
|
|
{ |
|
43
|
|
|
"title": "test", |
|
44
|
|
|
"hint": "hint" |
|
45
|
|
|
}, |
|
46
|
|
|
{ |
|
47
|
|
|
"title": "second_title", |
|
48
|
|
|
"hint": "second_hint" |
|
49
|
|
|
} |
|
50
|
|
|
] |
|
51
|
|
|
|
|
52
|
|
|
actual = COMPLETION_COMPILER.compile_keys(options) |
|
53
|
|
|
|
|
54
|
|
|
expected = [ |
|
55
|
|
|
("test", "test\thint", "test", False), |
|
56
|
|
|
("second_title", "second_title\tsecond_hint", "second_title", False), |
|
57
|
|
|
] |
|
58
|
|
|
|
|
59
|
|
|
self.assertEqual(actual, expected) |
|
60
|
|
|
|
|
61
|
|
|
def test_title_hint_value(self): |
|
62
|
|
|
""".""" |
|
63
|
|
|
options = [ |
|
64
|
|
|
{ |
|
65
|
|
|
"title": "test", |
|
66
|
|
|
"hint": "hint", |
|
67
|
|
|
"value": "value" |
|
68
|
|
|
} |
|
69
|
|
|
] |
|
70
|
|
|
|
|
71
|
|
|
actual = COMPLETION_COMPILER.compile_keys(options) |
|
72
|
|
|
|
|
73
|
|
|
expected = [ |
|
74
|
|
|
("test", "test\thint", "value", False) |
|
75
|
|
|
] |
|
76
|
|
|
|
|
77
|
|
|
self.assertEqual(actual, expected) |
|
78
|
|
|
|
|
79
|
|
|
def test_title_hint_value_unique(self): |
|
80
|
|
|
""".""" |
|
81
|
|
|
options = [ |
|
82
|
|
|
{ |
|
83
|
|
|
"title": "test", |
|
84
|
|
|
"hint": "hint", |
|
85
|
|
|
"value": "value", |
|
86
|
|
|
"unique": True |
|
87
|
|
|
} |
|
88
|
|
|
] |
|
89
|
|
|
|
|
90
|
|
|
actual = COMPLETION_COMPILER.compile_keys(options) |
|
91
|
|
|
|
|
92
|
|
|
expected = [ |
|
93
|
|
|
("test", "test\thint", "value", True) |
|
94
|
|
|
] |
|
95
|
|
|
|
|
96
|
|
|
self.assertEqual(actual, expected) |
|
97
|
|
|
|
|
98
|
|
|
def test_title_hint_unique(self): |
|
99
|
|
|
""".""" |
|
100
|
|
|
options = [ |
|
101
|
|
|
{ |
|
102
|
|
|
"title": "title", |
|
103
|
|
|
"hint": "hint", |
|
104
|
|
|
"unique": True |
|
105
|
|
|
} |
|
106
|
|
|
] |
|
107
|
|
|
|
|
108
|
|
|
actual = COMPLETION_COMPILER.compile_keys(options) |
|
109
|
|
|
|
|
110
|
|
|
expected = [ |
|
111
|
|
|
("title", "title\thint", "title", True) |
|
112
|
|
|
] |
|
113
|
|
|
|
|
114
|
|
|
self.assertEqual(actual, expected) |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
class TestCompletionCompilerValues(TestCase): |
|
118
|
|
|
""".""" |
|
119
|
|
|
|
|
120
|
|
|
def test_empty(self): |
|
121
|
|
|
""".""" |
|
122
|
|
|
options = list() |
|
123
|
|
|
|
|
124
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
125
|
|
|
|
|
126
|
|
|
# empty dict evaluates to False -> not False = True |
|
127
|
|
|
self.assertTrue(not compiled_key_values) |
|
128
|
|
|
|
|
129
|
|
|
def test_title(self): |
|
130
|
|
|
""".""" |
|
131
|
|
|
options = [ |
|
132
|
|
|
{ |
|
133
|
|
|
"title": "title" |
|
134
|
|
|
} |
|
135
|
|
|
] |
|
136
|
|
|
|
|
137
|
|
|
expected = { |
|
138
|
|
|
"title": [] |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
142
|
|
|
|
|
143
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
144
|
|
|
|
|
145
|
|
|
def test_multiple_title(self): |
|
146
|
|
|
""".""" |
|
147
|
|
|
options = [ |
|
148
|
|
|
{ |
|
149
|
|
|
"title": "title" |
|
150
|
|
|
}, |
|
151
|
|
|
{ |
|
152
|
|
|
"title": "test" |
|
153
|
|
|
} |
|
154
|
|
|
] |
|
155
|
|
|
|
|
156
|
|
|
expected = { |
|
157
|
|
|
"title": [], |
|
158
|
|
|
"test": [] |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
162
|
|
|
|
|
163
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
164
|
|
|
|
|
165
|
|
|
def test_title_valuekey(self): |
|
166
|
|
|
""".""" |
|
167
|
|
|
options = [ |
|
168
|
|
|
{ |
|
169
|
|
|
"title": "title", |
|
170
|
|
|
"values": [ |
|
171
|
|
|
["key"] |
|
172
|
|
|
] |
|
173
|
|
|
} |
|
174
|
|
|
] |
|
175
|
|
|
|
|
176
|
|
|
expected = { |
|
177
|
|
|
"title": [("key\tDefault", "key")] |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
181
|
|
|
|
|
182
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
183
|
|
|
|
|
184
|
|
|
def test_title_multiple_valuekeys(self): |
|
185
|
|
|
""".""" |
|
186
|
|
|
options = [ |
|
187
|
|
|
{ |
|
188
|
|
|
"title": "title", |
|
189
|
|
|
"values": [ |
|
190
|
|
|
["key"], |
|
191
|
|
|
["key2"] |
|
192
|
|
|
] |
|
193
|
|
|
} |
|
194
|
|
|
] |
|
195
|
|
|
|
|
196
|
|
|
expected = { |
|
197
|
|
|
"title": [ |
|
198
|
|
|
("key\tDefault", "key"), |
|
199
|
|
|
("key2\tDefault", "key2") |
|
200
|
|
|
] |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
204
|
|
|
|
|
205
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
206
|
|
|
|
|
207
|
|
|
def test_title_key_hint(self): |
|
208
|
|
|
""".""" |
|
209
|
|
|
options = [ |
|
210
|
|
|
{ |
|
211
|
|
|
"title": "title", |
|
212
|
|
|
"values": [ |
|
213
|
|
|
["key", "hint"] |
|
214
|
|
|
] |
|
215
|
|
|
} |
|
216
|
|
|
] |
|
217
|
|
|
|
|
218
|
|
|
expected = { |
|
219
|
|
|
"title": [("key\thint", "key")] |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
223
|
|
|
|
|
224
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
225
|
|
|
|
|
226
|
|
|
def test_title_key_hint_value(self): |
|
227
|
|
|
""".""" |
|
228
|
|
|
options = [ |
|
229
|
|
|
{ |
|
230
|
|
|
"title": "title", |
|
231
|
|
|
"values": [ |
|
232
|
|
|
["key", "hint", "value"] |
|
233
|
|
|
] |
|
234
|
|
|
} |
|
235
|
|
|
] |
|
236
|
|
|
|
|
237
|
|
|
expected = { |
|
238
|
|
|
"title": [("key\thint", "value")] |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
242
|
|
|
|
|
243
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
244
|
|
|
|
|
245
|
|
|
def test_title_multi_key_hint_value(self): |
|
246
|
|
|
""".""" |
|
247
|
|
|
options = [ |
|
248
|
|
|
{ |
|
249
|
|
|
"title": "title", |
|
250
|
|
|
"values": [ |
|
251
|
|
|
["default_key"], |
|
252
|
|
|
["hint_key", "hint_hint"], |
|
253
|
|
|
["value_key", "value_hint", "value_content"] |
|
254
|
|
|
] |
|
255
|
|
|
} |
|
256
|
|
|
] |
|
257
|
|
|
|
|
258
|
|
|
expected = { |
|
259
|
|
|
"title": [ |
|
260
|
|
|
("default_key\tDefault", "default_key"), |
|
261
|
|
|
("hint_key\thint_hint", "hint_key"), |
|
262
|
|
|
("value_key\tvalue_hint", "value_content"), |
|
263
|
|
|
] |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
267
|
|
|
|
|
268
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
269
|
|
|
|
|
270
|
|
|
def test_all(self): |
|
271
|
|
|
""".""" |
|
272
|
|
|
options = [ |
|
273
|
|
|
{ |
|
274
|
|
|
"title": "title", |
|
275
|
|
|
"values": [ |
|
276
|
|
|
["default_key"], |
|
277
|
|
|
["hint_key", "hint_hint"], |
|
278
|
|
|
["value_key", "value_hint", "value_content"] |
|
279
|
|
|
] |
|
280
|
|
|
}, |
|
281
|
|
|
{ |
|
282
|
|
|
"title": "different_key", |
|
283
|
|
|
"values": [ |
|
284
|
|
|
["default_key"], |
|
285
|
|
|
["hint_key", "hint_hint"], |
|
286
|
|
|
["value_key", "value_hint", "value_content"] |
|
287
|
|
|
] |
|
288
|
|
|
} |
|
289
|
|
|
] |
|
290
|
|
|
|
|
291
|
|
|
expected = { |
|
292
|
|
|
"title": [ |
|
293
|
|
|
("default_key\tDefault", "default_key"), |
|
294
|
|
|
("hint_key\thint_hint", "hint_key"), |
|
295
|
|
|
("value_key\tvalue_hint", "value_content"), |
|
296
|
|
|
], |
|
297
|
|
|
"different_key": [ |
|
298
|
|
|
("default_key\tDefault", "default_key"), |
|
299
|
|
|
("hint_key\thint_hint", "hint_key"), |
|
300
|
|
|
("value_key\tvalue_hint", "value_content"), |
|
301
|
|
|
], |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
compiled_key_values = COMPLETION_COMPILER.compile_values(options) |
|
305
|
|
|
|
|
306
|
|
|
self.assertEqual(compiled_key_values, expected) |
|
307
|
|
|
|