File: ComboBox_test.py

package info (click to toggle)
python-pmw 0.8.5-6
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,820 kB
  • ctags: 3,468
  • sloc: python: 14,898; makefile: 37; sh: 17
file content (180 lines) | stat: -rw-r--r-- 5,492 bytes parent folder | download
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
# Based on iwidgets2.2.0/tests/combobox.test code. 


import Tkinter
import Test
import Pmw

Test.initialise()

if Tkinter.TkVersion >= 8.3:
  expected1 = 'TclError: bad relief "bogus": must be '
  expected2 = 'TclError: bad state "bogus": must be disabled or normal'
else:
  expected1 = 'TclError: bad relief type "bogus": must be '
  expected2 = 'TclError: bad state value "bogus": must be normal or disabled'

c = Pmw.ComboBox

kw_1a = {
  'labelpos' : 'w',
  'label_text' : 'Label:',
  'autoclear': 1,
  'listheight': 250,
  'scrolledlist_items': ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'),
}

kw_1b = {
  'dropdown': 0,
  'entry_state': 'disabled',
  'selectioncommand' : Test.callback1,
  'scrolledlist_items': ('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'),
  'listheight' : 200,
  'label_text' : 'DropDown:',
  'labelpos' : 'w',
  'listbox_cursor' : 'hand1',
  'unique' : 1
}

tests_1 = (
  (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}),
  (Test.num_options, (), 10),
  ('entry_width', 20),
  ('entry_textvariable', Test.stringvar),
  ('label_text', 'ComboBox:'),
  ('label_image', Test.flagup),
  ('label_image', ''),
  ('entry_borderwidth', 10),
  ('entry_borderwidth', 2),
  ('hull_background', 'steelblue'),
  ('entry_foreground', 'white'),
  ('hull_background', 'grey85'),
  ('entry_foreground', 'Black'),
  ('entry_textvariable', ''),
  ('entry_state', 'disabled'),
  ('entry_state', 'normal'),
  ('label_font', Test.font['variable']),
  ('entry_font', Test.font['large']),
  ('entry_font', Test.font['variable']),
  (c.invoke, ()),
  ('hull_cursor', ''),
  ('entry_relief', 'raised'),
  ('entry_relief', 'groove'),
  ('entry_relief', 'flat'),
  ('entry_relief', 'sunken'),
  ('entry_exportselection', 1),
  ('entry_exportselection', 0),
  ('entryfield_invalidcommand', Test.bell),
  ('listbox_cursor', 'hand1'),
  ('listbox_cursor', 'hand2'),
  ('entry_selectbackground', '#b2dfee'),
  ('listbox_selectbackground', 'steelblue'),
  ('entry_selectborderwidth', 1),
  ('entry_selectforeground', 'Black'),
  ('entry_background', 'white'),
  ('entryfield_validate', 'alphabetic'),
  (c.setentry, '1234', 0),
  (c.get, (), 'this is some text'),
  ('entryfield_validate', None),
  ('scrolledlist_hscrollmode', 'dynamic'),
  ('scrolledlist_hscrollmode', 'dynamic'),
  ('scrolledlist_vscrollmode', 'dynamic'),
  ('scrolledlist_vscrollmode', 'dynamic'),
  ('entry_borderwidth', 'bogus', 'TclError: bad screen distance "bogus"'),
  ('entry_cursor', 'bogus', 'TclError: bad cursor spec "bogus"'),
  ('entry_exportselection', 'bogus',
    'TclError: expected boolean value but got "bogus"'),
  ('scrolledlist_hscrollmode', 'bogus',
    'ValueError: bad hscrollmode option "bogus": should be static, dynamic, ' +
	'or none'),
  ('listbox_cursor', 'bogus', 'TclError: bad cursor spec "bogus"'),
  ('entry_relief', 'bogus', expected1 + Test.reliefs),
  ('entry_selectborderwidth', 'bogus', 'TclError: bad screen distance "bogus"'),
  ('entry_state', 'bogus', expected2),
  ('entryfield_validate', 'bogus',
    "ValueError: bad validate value \"bogus\":  must be a function or one of " +
	"the standard validators ('alphabetic', 'alphanumeric', 'date', " +
	"'hexadecimal', 'integer', 'numeric', 'real', 'time') or extra " +
	"validators ()"),
  ('scrolledlist_vscrollmode', 'bogus',
    'ValueError: bad vscrollmode option "bogus": should be static, dynamic, ' +
	'or none'),
  ('entry_width', 'bogus', 'TclError: expected integer but got "bogus"'),
  (c.interior, (), Tkinter.Frame),
  (c.setentry, 'This is some text', 1),
  (c.get, (), 'This is some text'),
  (c.get, 2, 'C'),
  (c.get, (2, 4), ('C', 'D', 'E')),
  ('listbox_exportselection', 0),
  (c.selectitem, 3),
  (c.getcurselection, (), ('D',)),
  (c.get, (), 'D'),
  (c.selectitem, 'H'),
  (c.getcurselection, (), ('H',)),
  (c.get, (), 'H'),
  (c.setentry, '', 1),
  (c.size, (), 10),
  (c.get, (), ''),
  (c.delete, (0, 'end')),
  (c.insert, (0, 'Test1', 'Test2', 'Test3', 'Test4')),
  (c.insert, ('end', 'More Test')),
  (c.size, (), 5),
  (c.delete, (1),),
  (c.delete, (0, 2)),
  (c.size, (), 1),
  (c.get, 0, 'More Test'),
  (c.setentry, '', 1),
  (c.get, (), ''),
  (c.selectitem, 'More Test'),
  (c.curselection, (), ('0',)),
  (c.delete, (0, 'end')),
  (c.size, (), 0),
  (c.getcurselection, (), ()),
  (c.insert, ('end', 'Test1', 'Test2', 'Really Long String Test')),
  (c.size, (), 3),
  (c.get, 0, 'Test1'),
  (c.get, 2, 'Really Long String Test'),
  (c.insert, (0, 'Test3', 'Test4', 'Really Long String Test')),
  (c.size, (), 6),
  (c.insert, (1, 'Test5', 'Test6', 'Really Long String Test')),
  (c.size, (), 9),
  (c.insert, (5, 'Test7', 'Test8', 'Really Long String Test')),
  (c.size, (), 12),
  (c.see, 0),
  (c.see, 11),
  (c.get, 'end', 'Really Long String Test'),
  (c.selectitem, 5),
  (c.curselection, (), ('5',)),
  (c.clear, ()),
  (c.get, (), ''),
  (c.size, (), 0),
)

kw_2 = {
  'fliparrow': 1,
  'history': 1,
  'buttonaspect': 0.5,
  'arrowbutton_relief': 'groove',
  'selectioncommand' : Test.callback,
  'hull_background' : 'red',
  'scrolledlist_items' : (123, 456, 789, 101112),
  'listheight' : 50,
  'label_text' : 'Numeric Simple:',
  'labelpos' : 'w',
  'entryfield_validate' : 'numeric',
  'unique' : 0,
}
tests_2 = (
  (c.pack, (), {'padx' : 10, 'pady' : 10, 'fill' : 'both', 'expand' : 1}),
)

alltests = (
  (tests_1, kw_1a),
  (tests_1, kw_1b),
  (tests_2, kw_2),
)

testData = ((c, alltests),)

if __name__ == '__main__':
    Test.runTests(testData)