forked from rawpython/remi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_widget.py
executable file
·379 lines (308 loc) · 11.9 KB
/
test_widget.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#!/usr/bin/env python
import unittest
import remi.gui as gui
try:
from html_validator import SimpleParser, assertValidHTML
except ValueError:
from .html_validator import SimpleParser, assertValidHTML
# tests start here
class TestTag(unittest.TestCase):
def test_init(self):
widget = gui.Tag()
assertValidHTML(widget.repr())
class TestWidget(unittest.TestCase):
def test_init(self):
widget = gui.Widget()
assertValidHTML(widget.repr())
class TestHTML(unittest.TestCase):
def test_init(self):
widget = gui.HTML()
assertValidHTML(widget.repr())
class TestHEAD(unittest.TestCase):
def test_init(self):
widget = gui.HEAD(title="my remi app")
self.assertIn('my remi app', widget.repr())
assertValidHTML(widget.repr())
class TestBODY(unittest.TestCase):
def test_init(self):
widget = gui.BODY()
assertValidHTML(widget.repr())
class TestGridBox(unittest.TestCase):
def test_init(self):
w = gui.GridBox()
l = gui.Label('box_label')
w.append(l)
self.assertIn('box_label',w.repr())
assertValidHTML(w.repr())
class TestHBox(unittest.TestCase):
def test_init(self):
w = gui.HBox()
l = gui.Label('hbox_label')
w.append(l)
self.assertIn('hbox_label',w.repr())
assertValidHTML(w.repr())
class TestVBox(unittest.TestCase):
def test_init(self):
w = gui.VBox()
l = gui.Label('vbox_label')
w.append(l)
self.assertIn('vbox_label',w.repr())
assertValidHTML(w.repr())
class TestTabBox(unittest.TestCase):
def test_init(self):
w = gui.TabBox()
l = gui.Label('testTabBox_label')
w.add_tab(l, key='testtabbox', callback=None)
self.assertIn('testTabBox_label',w.repr())
assertValidHTML(w.repr())
class TestButton(unittest.TestCase):
'''
Unit testing for Button class. Testing for instantiation and
exceptions.
'''
def test_init(self):
widget = gui.Button('test button')
self.assertIn('test button', widget.repr())
assertValidHTML(widget.repr())
invalid_types = [{}, [], 123, (4, 5)]
for each_type in invalid_types:
with self.assertRaises(Exception) as error:
gui.Button(each_type)
class TestTextInput(unittest.TestCase):
def test_init(self):
widget = gui.TextInput(single_line=True, hint='test text input')
self.assertIn('test text input', widget.repr())
assertValidHTML(widget.repr())
widget = gui.TextInput(single_line=False, hint='test text input')
self.assertIn('test text input', widget.repr())
assertValidHTML(widget.repr())
class TestLabel(unittest.TestCase):
'''
Unit testing for Label class. This tests the instantiation of
the class. It also test to see if there are any exceptions too.
'''
def test_init(self):
widget = gui.Label('testing title')
self.assertIn('testing title', widget.repr())
assertValidHTML(widget.repr())
invalid_types = [{}, [], 123, (4, 5)]
for each_type in invalid_types:
with self.assertRaises(Exception) as error:
gui.Label(each_type)
class TestProgress(unittest.TestCase):
def test_init(self):
widget = gui.Progress(_max=12,value=1)
h = SimpleParser()
h.feed(widget.repr())
(tag, attrs) = h.elements[0]
self.assertEquals(int(attrs['max']),12)
self.assertEquals(int(attrs['value']),1)
class TestGenericDialog(unittest.TestCase):
'''
Unit testing for TestGenericDialog class. Tests the functions widgetithin
the GenericDialog class.
'''
def test_init(self):
widget = gui.GenericDialog(title='testing title',
message='testing message')
self.assertIn('testing title', widget.repr())
self.assertIn('testing message', widget.repr())
assertValidHTML(widget.repr())
class TestInputDialog(unittest.TestCase):
def test_init(self):
widget = gui.InputDialog(title='testing title',
message='testing message')
self.assertIn('testing title', widget.repr())
self.assertIn('testing message', widget.repr())
assertValidHTML(widget.repr())
class TestListView(unittest.TestCase):
def test_init(self):
widget = gui.ListView()
assertValidHTML(widget.repr())
class TestListItem(unittest.TestCase):
def test_init(self):
widget = gui.ListItem('test list item')
self.assertIn('test list item',widget.repr())
assertValidHTML(widget.repr())
class TestDropDown(unittest.TestCase):
def test_init(self):
widget = gui.DropDown()
widget.append('test drop down')
self.assertIn('test drop down', widget.repr())
assertValidHTML(widget.repr())
class TestDropDownItem(unittest.TestCase):
def test_init(self):
widget = gui.DropDownItem('test drop down item')
self.assertIn('test drop down item', widget.repr())
assertValidHTML(widget.repr())
class TestImage(unittest.TestCase):
def test_init(self):
widget = gui.Image('http://placekitten.com/200/200')
assertValidHTML(widget.repr())
class TestTable(unittest.TestCase):
def test_init(self):
widget = gui.Table()
assertValidHTML(widget.repr())
class TestTableWidget(unittest.TestCase):
def test_init(self):
widget = gui.TableWidget(2, 3, use_title=True, editable=False)
assertValidHTML(widget.repr())
class TestTableRow(unittest.TestCase):
def test_init(self):
widget = gui.TableRow()
assertValidHTML(widget.repr())
class TestTableEditableItem(unittest.TestCase):
def test_init(self):
widget = gui.TableEditableItem()
assertValidHTML(widget.repr())
class TestTableItem(unittest.TestCase):
def test_init(self):
widget = gui.TableItem()
assertValidHTML(widget.repr())
class TestTableTitle(unittest.TestCase):
def test_init(self):
widget = gui.TableTitle()
assertValidHTML(widget.repr())
class TestInput(unittest.TestCase):
def test_init(self):
widget = gui.Input()
assertValidHTML(widget.repr())
class TestCheckBoxLabel(unittest.TestCase):
def test_init(self):
widget = gui.CheckBoxLabel()
assertValidHTML(widget.repr())
class TestCheckBox(unittest.TestCase):
def test_init(self):
widget = gui.CheckBox()
assertValidHTML(widget.repr())
class TestSpinBox(unittest.TestCase):
def test_init(self):
widget = gui.SpinBox()
assertValidHTML(widget.repr())
class TestSlider(unittest.TestCase):
def test_init(self):
widget = gui.Slider()
assertValidHTML(widget.repr())
class TestColorPicker(unittest.TestCase):
def test_init(self):
widget = gui.ColorPicker()
assertValidHTML(widget.repr())
class TestDate(unittest.TestCase):
def test_init(self):
widget = gui.Date()
assertValidHTML(widget.repr())
class TestGenericObject(unittest.TestCase):
def test_init(self):
widget = gui.GenericObject(filename='shockwave.swf')
assertValidHTML(widget.repr())
h = SimpleParser()
h.feed(widget.repr())
(tag, attrs) = h.elements[0]
self.assertEquals(attrs['data'], 'shockwave.swf')
class TestFileFolderNavigator(unittest.TestCase):
def test_init(self):
widget = gui.FileFolderNavigator(multiple_selection=True,
selection_folder='/',
allow_file_selection=True,
allow_folder_selection=True)
assertValidHTML(widget.repr())
class TestFileFolderItem(unittest.TestCase):
def test_init(self):
widget = gui.FileFolderItem('full path', 'test file folder item')
assertValidHTML(widget.repr())
class TestFileSelectionDialog(unittest.TestCase):
def test_init(self):
widget = gui.FileSelectionDialog()
assertValidHTML(widget.repr())
class TestMenuBar(unittest.TestCase):
def test_init(self):
widget = gui.MenuBar()
assertValidHTML(widget.repr())
class TestMenu(unittest.TestCase):
def test_init(self):
widget = gui.Menu()
assertValidHTML(widget.repr())
class TestMenuItem(unittest.TestCase):
def test_init(self):
widget = gui.MenuItem('test menu item')
widget.append(gui.MenuItem('2nd menu item'))
self.assertIn('test menu item', widget.repr())
self.assertIn('2nd menu item', widget.repr())
assertValidHTML(widget.repr())
class TestTreeView(unittest.TestCase):
def test_init(self):
widget = gui.TreeView()
assertValidHTML(widget.repr())
class TestTreeItem(unittest.TestCase):
def test_init(self):
widget = gui.TreeItem('test tree item')
widget.append(gui.TreeItem('2nd tree item'))
self.assertIn('test tree item', widget.repr())
self.assertIn('2nd tree item', widget.repr())
assertValidHTML(widget.repr())
class TestFileUploader(unittest.TestCase):
def test_init(self):
widget = gui.FileUploader()
assertValidHTML(widget.repr())
class TestFileDownloader(unittest.TestCase):
def test_init(self):
widget = gui.FileDownloader(text='click here',
filename='food.txt')
assertValidHTML(widget.repr())
class TestLink(unittest.TestCase):
def test_init(self):
widget = gui.Link(url='http://google.com',
text='google')
assertValidHTML(widget.repr())
self.assertIn('google', widget.repr())
class TestVideoPlayer(unittest.TestCase):
def test_init(self):
widget = gui.VideoPlayer('http://example.com/video.mp4')
assertValidHTML(widget.repr())
class TestSvg(unittest.TestCase):
def test_init(self):
widget = gui.Svg(width=10, height=10)
assertValidHTML(widget.repr())
class TestSvgSubcontainer(unittest.TestCase):
def test_init(self):
widget = gui.SvgSubcontainer(0, 0, 100, 100)
assertValidHTML(widget.repr())
class TestSvgGroup(unittest.TestCase):
def test_init(self):
widget = gui.SvgGroup()
assertValidHTML(widget.repr())
class TestSvgRectangle(unittest.TestCase):
def test_init(self):
widget = gui.SvgRectangle(10, 10, 10, 10)
assertValidHTML(widget.repr())
class TestSvgImage(unittest.TestCase):
def test_init(self):
widget = gui.SvgImage(filename='food.png',
x=10, y=10, w=10, h=10)
assertValidHTML(widget.repr())
class TestSvgCircle(unittest.TestCase):
def test_init(self):
widget = gui.SvgCircle(10, 10, 10)
assertValidHTML(widget.repr())
class TestSvgLine(unittest.TestCase):
def test_init(self):
widget = gui.SvgLine(10, 10, 20, 20)
assertValidHTML(widget.repr())
class TestSvgPolyline(unittest.TestCase):
def test_init(self):
widget = gui.SvgPolyline()
assertValidHTML(widget.repr())
class TestSvgPolygon(unittest.TestCase):
def test_init(self):
widget = gui.SvgPolygon()
assertValidHTML(widget.repr())
class TestSvgText(unittest.TestCase):
def test_init(self):
widget = gui.SvgText(x=10, y=10, text='hello world')
assertValidHTML(widget.repr())
class TestSvgPath(unittest.TestCase):
def test_init(self):
widget = gui.SvgPath(path_value='M 10 10 L 20 20 Z')
assertValidHTML(widget.repr())
if __name__ == '__main__':
unittest.main()