1 | n/a | # Common tests for test_tkinter/test_widgets.py and test_ttk/test_widgets.py |
---|
2 | n/a | |
---|
3 | n/a | import unittest |
---|
4 | n/a | import sys |
---|
5 | n/a | import tkinter |
---|
6 | n/a | from tkinter.ttk import Scale |
---|
7 | n/a | from tkinter.test.support import (AbstractTkTest, tcl_version, requires_tcl, |
---|
8 | n/a | get_tk_patchlevel, pixels_conv, tcl_obj_eq) |
---|
9 | n/a | import test.support |
---|
10 | n/a | |
---|
11 | n/a | |
---|
12 | n/a | noconv = False |
---|
13 | n/a | if get_tk_patchlevel() < (8, 5, 11): |
---|
14 | n/a | noconv = str |
---|
15 | n/a | |
---|
16 | n/a | pixels_round = round |
---|
17 | n/a | if get_tk_patchlevel()[:3] == (8, 5, 11): |
---|
18 | n/a | # Issue #19085: Workaround a bug in Tk |
---|
19 | n/a | # http://core.tcl.tk/tk/info/3497848 |
---|
20 | n/a | pixels_round = int |
---|
21 | n/a | |
---|
22 | n/a | |
---|
23 | n/a | _sentinel = object() |
---|
24 | n/a | |
---|
25 | n/a | class AbstractWidgetTest(AbstractTkTest): |
---|
26 | n/a | _conv_pixels = staticmethod(pixels_round) |
---|
27 | n/a | _conv_pad_pixels = None |
---|
28 | n/a | _stringify = False |
---|
29 | n/a | |
---|
30 | n/a | @property |
---|
31 | n/a | def scaling(self): |
---|
32 | n/a | try: |
---|
33 | n/a | return self._scaling |
---|
34 | n/a | except AttributeError: |
---|
35 | n/a | self._scaling = float(self.root.call('tk', 'scaling')) |
---|
36 | n/a | return self._scaling |
---|
37 | n/a | |
---|
38 | n/a | def _str(self, value): |
---|
39 | n/a | if not self._stringify and self.wantobjects and tcl_version >= (8, 6): |
---|
40 | n/a | return value |
---|
41 | n/a | if isinstance(value, tuple): |
---|
42 | n/a | return ' '.join(map(self._str, value)) |
---|
43 | n/a | return str(value) |
---|
44 | n/a | |
---|
45 | n/a | def assertEqual2(self, actual, expected, msg=None, eq=object.__eq__): |
---|
46 | n/a | if eq(actual, expected): |
---|
47 | n/a | return |
---|
48 | n/a | self.assertEqual(actual, expected, msg) |
---|
49 | n/a | |
---|
50 | n/a | def checkParam(self, widget, name, value, *, expected=_sentinel, |
---|
51 | n/a | conv=False, eq=None): |
---|
52 | n/a | widget[name] = value |
---|
53 | n/a | if expected is _sentinel: |
---|
54 | n/a | expected = value |
---|
55 | n/a | if conv: |
---|
56 | n/a | expected = conv(expected) |
---|
57 | n/a | if self._stringify or not self.wantobjects: |
---|
58 | n/a | if isinstance(expected, tuple): |
---|
59 | n/a | expected = tkinter._join(expected) |
---|
60 | n/a | else: |
---|
61 | n/a | expected = str(expected) |
---|
62 | n/a | if eq is None: |
---|
63 | n/a | eq = tcl_obj_eq |
---|
64 | n/a | self.assertEqual2(widget[name], expected, eq=eq) |
---|
65 | n/a | self.assertEqual2(widget.cget(name), expected, eq=eq) |
---|
66 | n/a | # XXX |
---|
67 | n/a | if not isinstance(widget, Scale): |
---|
68 | n/a | t = widget.configure(name) |
---|
69 | n/a | self.assertEqual(len(t), 5) |
---|
70 | n/a | self.assertEqual2(t[4], expected, eq=eq) |
---|
71 | n/a | |
---|
72 | n/a | def checkInvalidParam(self, widget, name, value, errmsg=None, *, |
---|
73 | n/a | keep_orig=True): |
---|
74 | n/a | orig = widget[name] |
---|
75 | n/a | if errmsg is not None: |
---|
76 | n/a | errmsg = errmsg.format(value) |
---|
77 | n/a | with self.assertRaises(tkinter.TclError) as cm: |
---|
78 | n/a | widget[name] = value |
---|
79 | n/a | if errmsg is not None: |
---|
80 | n/a | self.assertEqual(str(cm.exception), errmsg) |
---|
81 | n/a | if keep_orig: |
---|
82 | n/a | self.assertEqual(widget[name], orig) |
---|
83 | n/a | else: |
---|
84 | n/a | widget[name] = orig |
---|
85 | n/a | with self.assertRaises(tkinter.TclError) as cm: |
---|
86 | n/a | widget.configure({name: value}) |
---|
87 | n/a | if errmsg is not None: |
---|
88 | n/a | self.assertEqual(str(cm.exception), errmsg) |
---|
89 | n/a | if keep_orig: |
---|
90 | n/a | self.assertEqual(widget[name], orig) |
---|
91 | n/a | else: |
---|
92 | n/a | widget[name] = orig |
---|
93 | n/a | |
---|
94 | n/a | def checkParams(self, widget, name, *values, **kwargs): |
---|
95 | n/a | for value in values: |
---|
96 | n/a | self.checkParam(widget, name, value, **kwargs) |
---|
97 | n/a | |
---|
98 | n/a | def checkIntegerParam(self, widget, name, *values, **kwargs): |
---|
99 | n/a | self.checkParams(widget, name, *values, **kwargs) |
---|
100 | n/a | self.checkInvalidParam(widget, name, '', |
---|
101 | n/a | errmsg='expected integer but got ""') |
---|
102 | n/a | self.checkInvalidParam(widget, name, '10p', |
---|
103 | n/a | errmsg='expected integer but got "10p"') |
---|
104 | n/a | self.checkInvalidParam(widget, name, 3.2, |
---|
105 | n/a | errmsg='expected integer but got "3.2"') |
---|
106 | n/a | |
---|
107 | n/a | def checkFloatParam(self, widget, name, *values, conv=float, **kwargs): |
---|
108 | n/a | for value in values: |
---|
109 | n/a | self.checkParam(widget, name, value, conv=conv, **kwargs) |
---|
110 | n/a | self.checkInvalidParam(widget, name, '', |
---|
111 | n/a | errmsg='expected floating-point number but got ""') |
---|
112 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
113 | n/a | errmsg='expected floating-point number but got "spam"') |
---|
114 | n/a | |
---|
115 | n/a | def checkBooleanParam(self, widget, name): |
---|
116 | n/a | for value in (False, 0, 'false', 'no', 'off'): |
---|
117 | n/a | self.checkParam(widget, name, value, expected=0) |
---|
118 | n/a | for value in (True, 1, 'true', 'yes', 'on'): |
---|
119 | n/a | self.checkParam(widget, name, value, expected=1) |
---|
120 | n/a | self.checkInvalidParam(widget, name, '', |
---|
121 | n/a | errmsg='expected boolean value but got ""') |
---|
122 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
123 | n/a | errmsg='expected boolean value but got "spam"') |
---|
124 | n/a | |
---|
125 | n/a | def checkColorParam(self, widget, name, *, allow_empty=None, **kwargs): |
---|
126 | n/a | self.checkParams(widget, name, |
---|
127 | n/a | '#ff0000', '#00ff00', '#0000ff', '#123456', |
---|
128 | n/a | 'red', 'green', 'blue', 'white', 'black', 'grey', |
---|
129 | n/a | **kwargs) |
---|
130 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
131 | n/a | errmsg='unknown color name "spam"') |
---|
132 | n/a | |
---|
133 | n/a | def checkCursorParam(self, widget, name, **kwargs): |
---|
134 | n/a | self.checkParams(widget, name, 'arrow', 'watch', 'cross', '',**kwargs) |
---|
135 | n/a | if tcl_version >= (8, 5): |
---|
136 | n/a | self.checkParam(widget, name, 'none') |
---|
137 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
138 | n/a | errmsg='bad cursor spec "spam"') |
---|
139 | n/a | |
---|
140 | n/a | def checkCommandParam(self, widget, name): |
---|
141 | n/a | def command(*args): |
---|
142 | n/a | pass |
---|
143 | n/a | widget[name] = command |
---|
144 | n/a | self.assertTrue(widget[name]) |
---|
145 | n/a | self.checkParams(widget, name, '') |
---|
146 | n/a | |
---|
147 | n/a | def checkEnumParam(self, widget, name, *values, errmsg=None, **kwargs): |
---|
148 | n/a | self.checkParams(widget, name, *values, **kwargs) |
---|
149 | n/a | if errmsg is None: |
---|
150 | n/a | errmsg2 = ' %s "{}": must be %s%s or %s' % ( |
---|
151 | n/a | name, |
---|
152 | n/a | ', '.join(values[:-1]), |
---|
153 | n/a | ',' if len(values) > 2 else '', |
---|
154 | n/a | values[-1]) |
---|
155 | n/a | self.checkInvalidParam(widget, name, '', |
---|
156 | n/a | errmsg='ambiguous' + errmsg2) |
---|
157 | n/a | errmsg = 'bad' + errmsg2 |
---|
158 | n/a | self.checkInvalidParam(widget, name, 'spam', errmsg=errmsg) |
---|
159 | n/a | |
---|
160 | n/a | def checkPixelsParam(self, widget, name, *values, |
---|
161 | n/a | conv=None, keep_orig=True, **kwargs): |
---|
162 | n/a | if conv is None: |
---|
163 | n/a | conv = self._conv_pixels |
---|
164 | n/a | for value in values: |
---|
165 | n/a | expected = _sentinel |
---|
166 | n/a | conv1 = conv |
---|
167 | n/a | if isinstance(value, str): |
---|
168 | n/a | if conv1 and conv1 is not str: |
---|
169 | n/a | expected = pixels_conv(value) * self.scaling |
---|
170 | n/a | conv1 = round |
---|
171 | n/a | self.checkParam(widget, name, value, expected=expected, |
---|
172 | n/a | conv=conv1, **kwargs) |
---|
173 | n/a | self.checkInvalidParam(widget, name, '6x', |
---|
174 | n/a | errmsg='bad screen distance "6x"', keep_orig=keep_orig) |
---|
175 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
176 | n/a | errmsg='bad screen distance "spam"', keep_orig=keep_orig) |
---|
177 | n/a | |
---|
178 | n/a | def checkReliefParam(self, widget, name): |
---|
179 | n/a | self.checkParams(widget, name, |
---|
180 | n/a | 'flat', 'groove', 'raised', 'ridge', 'solid', 'sunken') |
---|
181 | n/a | errmsg='bad relief "spam": must be '\ |
---|
182 | n/a | 'flat, groove, raised, ridge, solid, or sunken' |
---|
183 | n/a | if tcl_version < (8, 6): |
---|
184 | n/a | errmsg = None |
---|
185 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
186 | n/a | errmsg=errmsg) |
---|
187 | n/a | |
---|
188 | n/a | def checkImageParam(self, widget, name): |
---|
189 | n/a | image = tkinter.PhotoImage(master=self.root, name='image1') |
---|
190 | n/a | self.checkParam(widget, name, image, conv=str) |
---|
191 | n/a | self.checkInvalidParam(widget, name, 'spam', |
---|
192 | n/a | errmsg='image "spam" doesn\'t exist') |
---|
193 | n/a | widget[name] = '' |
---|
194 | n/a | |
---|
195 | n/a | def checkVariableParam(self, widget, name, var): |
---|
196 | n/a | self.checkParam(widget, name, var, conv=str) |
---|
197 | n/a | |
---|
198 | n/a | def assertIsBoundingBox(self, bbox): |
---|
199 | n/a | self.assertIsNotNone(bbox) |
---|
200 | n/a | self.assertIsInstance(bbox, tuple) |
---|
201 | n/a | if len(bbox) != 4: |
---|
202 | n/a | self.fail('Invalid bounding box: %r' % (bbox,)) |
---|
203 | n/a | for item in bbox: |
---|
204 | n/a | if not isinstance(item, int): |
---|
205 | n/a | self.fail('Invalid bounding box: %r' % (bbox,)) |
---|
206 | n/a | break |
---|
207 | n/a | |
---|
208 | n/a | |
---|
209 | n/a | def test_keys(self): |
---|
210 | n/a | widget = self.create() |
---|
211 | n/a | keys = widget.keys() |
---|
212 | n/a | # XXX |
---|
213 | n/a | if not isinstance(widget, Scale): |
---|
214 | n/a | self.assertEqual(sorted(keys), sorted(widget.configure())) |
---|
215 | n/a | for k in keys: |
---|
216 | n/a | widget[k] |
---|
217 | n/a | # Test if OPTIONS contains all keys |
---|
218 | n/a | if test.support.verbose: |
---|
219 | n/a | aliases = { |
---|
220 | n/a | 'bd': 'borderwidth', |
---|
221 | n/a | 'bg': 'background', |
---|
222 | n/a | 'fg': 'foreground', |
---|
223 | n/a | 'invcmd': 'invalidcommand', |
---|
224 | n/a | 'vcmd': 'validatecommand', |
---|
225 | n/a | } |
---|
226 | n/a | keys = set(keys) |
---|
227 | n/a | expected = set(self.OPTIONS) |
---|
228 | n/a | for k in sorted(keys - expected): |
---|
229 | n/a | if not (k in aliases and |
---|
230 | n/a | aliases[k] in keys and |
---|
231 | n/a | aliases[k] in expected): |
---|
232 | n/a | print('%s.OPTIONS doesn\'t contain "%s"' % |
---|
233 | n/a | (self.__class__.__name__, k)) |
---|
234 | n/a | |
---|
235 | n/a | |
---|
236 | n/a | class StandardOptionsTests: |
---|
237 | n/a | STANDARD_OPTIONS = ( |
---|
238 | n/a | 'activebackground', 'activeborderwidth', 'activeforeground', 'anchor', |
---|
239 | n/a | 'background', 'bitmap', 'borderwidth', 'compound', 'cursor', |
---|
240 | n/a | 'disabledforeground', 'exportselection', 'font', 'foreground', |
---|
241 | n/a | 'highlightbackground', 'highlightcolor', 'highlightthickness', |
---|
242 | n/a | 'image', 'insertbackground', 'insertborderwidth', |
---|
243 | n/a | 'insertofftime', 'insertontime', 'insertwidth', |
---|
244 | n/a | 'jump', 'justify', 'orient', 'padx', 'pady', 'relief', |
---|
245 | n/a | 'repeatdelay', 'repeatinterval', |
---|
246 | n/a | 'selectbackground', 'selectborderwidth', 'selectforeground', |
---|
247 | n/a | 'setgrid', 'takefocus', 'text', 'textvariable', 'troughcolor', |
---|
248 | n/a | 'underline', 'wraplength', 'xscrollcommand', 'yscrollcommand', |
---|
249 | n/a | ) |
---|
250 | n/a | |
---|
251 | n/a | def test_activebackground(self): |
---|
252 | n/a | widget = self.create() |
---|
253 | n/a | self.checkColorParam(widget, 'activebackground') |
---|
254 | n/a | |
---|
255 | n/a | def test_activeborderwidth(self): |
---|
256 | n/a | widget = self.create() |
---|
257 | n/a | self.checkPixelsParam(widget, 'activeborderwidth', |
---|
258 | n/a | 0, 1.3, 2.9, 6, -2, '10p') |
---|
259 | n/a | |
---|
260 | n/a | def test_activeforeground(self): |
---|
261 | n/a | widget = self.create() |
---|
262 | n/a | self.checkColorParam(widget, 'activeforeground') |
---|
263 | n/a | |
---|
264 | n/a | def test_anchor(self): |
---|
265 | n/a | widget = self.create() |
---|
266 | n/a | self.checkEnumParam(widget, 'anchor', |
---|
267 | n/a | 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center') |
---|
268 | n/a | |
---|
269 | n/a | def test_background(self): |
---|
270 | n/a | widget = self.create() |
---|
271 | n/a | self.checkColorParam(widget, 'background') |
---|
272 | n/a | if 'bg' in self.OPTIONS: |
---|
273 | n/a | self.checkColorParam(widget, 'bg') |
---|
274 | n/a | |
---|
275 | n/a | def test_bitmap(self): |
---|
276 | n/a | widget = self.create() |
---|
277 | n/a | self.checkParam(widget, 'bitmap', 'questhead') |
---|
278 | n/a | self.checkParam(widget, 'bitmap', 'gray50') |
---|
279 | n/a | filename = test.support.findfile('python.xbm', subdir='imghdrdata') |
---|
280 | n/a | self.checkParam(widget, 'bitmap', '@' + filename) |
---|
281 | n/a | # Cocoa Tk widgets don't detect invalid -bitmap values |
---|
282 | n/a | # See https://core.tcl.tk/tk/info/31cd33dbf0 |
---|
283 | n/a | if not ('aqua' in self.root.tk.call('tk', 'windowingsystem') and |
---|
284 | n/a | 'AppKit' in self.root.winfo_server()): |
---|
285 | n/a | self.checkInvalidParam(widget, 'bitmap', 'spam', |
---|
286 | n/a | errmsg='bitmap "spam" not defined') |
---|
287 | n/a | |
---|
288 | n/a | def test_borderwidth(self): |
---|
289 | n/a | widget = self.create() |
---|
290 | n/a | self.checkPixelsParam(widget, 'borderwidth', |
---|
291 | n/a | 0, 1.3, 2.6, 6, -2, '10p') |
---|
292 | n/a | if 'bd' in self.OPTIONS: |
---|
293 | n/a | self.checkPixelsParam(widget, 'bd', 0, 1.3, 2.6, 6, -2, '10p') |
---|
294 | n/a | |
---|
295 | n/a | def test_compound(self): |
---|
296 | n/a | widget = self.create() |
---|
297 | n/a | self.checkEnumParam(widget, 'compound', |
---|
298 | n/a | 'bottom', 'center', 'left', 'none', 'right', 'top') |
---|
299 | n/a | |
---|
300 | n/a | def test_cursor(self): |
---|
301 | n/a | widget = self.create() |
---|
302 | n/a | self.checkCursorParam(widget, 'cursor') |
---|
303 | n/a | |
---|
304 | n/a | def test_disabledforeground(self): |
---|
305 | n/a | widget = self.create() |
---|
306 | n/a | self.checkColorParam(widget, 'disabledforeground') |
---|
307 | n/a | |
---|
308 | n/a | def test_exportselection(self): |
---|
309 | n/a | widget = self.create() |
---|
310 | n/a | self.checkBooleanParam(widget, 'exportselection') |
---|
311 | n/a | |
---|
312 | n/a | def test_font(self): |
---|
313 | n/a | widget = self.create() |
---|
314 | n/a | self.checkParam(widget, 'font', |
---|
315 | n/a | '-Adobe-Helvetica-Medium-R-Normal--*-120-*-*-*-*-*-*') |
---|
316 | n/a | self.checkInvalidParam(widget, 'font', '', |
---|
317 | n/a | errmsg='font "" doesn\'t exist') |
---|
318 | n/a | |
---|
319 | n/a | def test_foreground(self): |
---|
320 | n/a | widget = self.create() |
---|
321 | n/a | self.checkColorParam(widget, 'foreground') |
---|
322 | n/a | if 'fg' in self.OPTIONS: |
---|
323 | n/a | self.checkColorParam(widget, 'fg') |
---|
324 | n/a | |
---|
325 | n/a | def test_highlightbackground(self): |
---|
326 | n/a | widget = self.create() |
---|
327 | n/a | self.checkColorParam(widget, 'highlightbackground') |
---|
328 | n/a | |
---|
329 | n/a | def test_highlightcolor(self): |
---|
330 | n/a | widget = self.create() |
---|
331 | n/a | self.checkColorParam(widget, 'highlightcolor') |
---|
332 | n/a | |
---|
333 | n/a | def test_highlightthickness(self): |
---|
334 | n/a | widget = self.create() |
---|
335 | n/a | self.checkPixelsParam(widget, 'highlightthickness', |
---|
336 | n/a | 0, 1.3, 2.6, 6, '10p') |
---|
337 | n/a | self.checkParam(widget, 'highlightthickness', -2, expected=0, |
---|
338 | n/a | conv=self._conv_pixels) |
---|
339 | n/a | |
---|
340 | n/a | @unittest.skipIf(sys.platform == 'darwin', |
---|
341 | n/a | 'crashes with Cocoa Tk (issue19733)') |
---|
342 | n/a | def test_image(self): |
---|
343 | n/a | widget = self.create() |
---|
344 | n/a | self.checkImageParam(widget, 'image') |
---|
345 | n/a | |
---|
346 | n/a | def test_insertbackground(self): |
---|
347 | n/a | widget = self.create() |
---|
348 | n/a | self.checkColorParam(widget, 'insertbackground') |
---|
349 | n/a | |
---|
350 | n/a | def test_insertborderwidth(self): |
---|
351 | n/a | widget = self.create() |
---|
352 | n/a | self.checkPixelsParam(widget, 'insertborderwidth', |
---|
353 | n/a | 0, 1.3, 2.6, 6, -2, '10p') |
---|
354 | n/a | |
---|
355 | n/a | def test_insertofftime(self): |
---|
356 | n/a | widget = self.create() |
---|
357 | n/a | self.checkIntegerParam(widget, 'insertofftime', 100) |
---|
358 | n/a | |
---|
359 | n/a | def test_insertontime(self): |
---|
360 | n/a | widget = self.create() |
---|
361 | n/a | self.checkIntegerParam(widget, 'insertontime', 100) |
---|
362 | n/a | |
---|
363 | n/a | def test_insertwidth(self): |
---|
364 | n/a | widget = self.create() |
---|
365 | n/a | self.checkPixelsParam(widget, 'insertwidth', 1.3, 2.6, -2, '10p') |
---|
366 | n/a | |
---|
367 | n/a | def test_jump(self): |
---|
368 | n/a | widget = self.create() |
---|
369 | n/a | self.checkBooleanParam(widget, 'jump') |
---|
370 | n/a | |
---|
371 | n/a | def test_justify(self): |
---|
372 | n/a | widget = self.create() |
---|
373 | n/a | self.checkEnumParam(widget, 'justify', 'left', 'right', 'center', |
---|
374 | n/a | errmsg='bad justification "{}": must be ' |
---|
375 | n/a | 'left, right, or center') |
---|
376 | n/a | self.checkInvalidParam(widget, 'justify', '', |
---|
377 | n/a | errmsg='ambiguous justification "": must be ' |
---|
378 | n/a | 'left, right, or center') |
---|
379 | n/a | |
---|
380 | n/a | def test_orient(self): |
---|
381 | n/a | widget = self.create() |
---|
382 | n/a | self.assertEqual(str(widget['orient']), self.default_orient) |
---|
383 | n/a | self.checkEnumParam(widget, 'orient', 'horizontal', 'vertical') |
---|
384 | n/a | |
---|
385 | n/a | def test_padx(self): |
---|
386 | n/a | widget = self.create() |
---|
387 | n/a | self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, -2, '12m', |
---|
388 | n/a | conv=self._conv_pad_pixels) |
---|
389 | n/a | |
---|
390 | n/a | def test_pady(self): |
---|
391 | n/a | widget = self.create() |
---|
392 | n/a | self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, -2, '12m', |
---|
393 | n/a | conv=self._conv_pad_pixels) |
---|
394 | n/a | |
---|
395 | n/a | def test_relief(self): |
---|
396 | n/a | widget = self.create() |
---|
397 | n/a | self.checkReliefParam(widget, 'relief') |
---|
398 | n/a | |
---|
399 | n/a | def test_repeatdelay(self): |
---|
400 | n/a | widget = self.create() |
---|
401 | n/a | self.checkIntegerParam(widget, 'repeatdelay', -500, 500) |
---|
402 | n/a | |
---|
403 | n/a | def test_repeatinterval(self): |
---|
404 | n/a | widget = self.create() |
---|
405 | n/a | self.checkIntegerParam(widget, 'repeatinterval', -500, 500) |
---|
406 | n/a | |
---|
407 | n/a | def test_selectbackground(self): |
---|
408 | n/a | widget = self.create() |
---|
409 | n/a | self.checkColorParam(widget, 'selectbackground') |
---|
410 | n/a | |
---|
411 | n/a | def test_selectborderwidth(self): |
---|
412 | n/a | widget = self.create() |
---|
413 | n/a | self.checkPixelsParam(widget, 'selectborderwidth', 1.3, 2.6, -2, '10p') |
---|
414 | n/a | |
---|
415 | n/a | def test_selectforeground(self): |
---|
416 | n/a | widget = self.create() |
---|
417 | n/a | self.checkColorParam(widget, 'selectforeground') |
---|
418 | n/a | |
---|
419 | n/a | def test_setgrid(self): |
---|
420 | n/a | widget = self.create() |
---|
421 | n/a | self.checkBooleanParam(widget, 'setgrid') |
---|
422 | n/a | |
---|
423 | n/a | def test_state(self): |
---|
424 | n/a | widget = self.create() |
---|
425 | n/a | self.checkEnumParam(widget, 'state', 'active', 'disabled', 'normal') |
---|
426 | n/a | |
---|
427 | n/a | def test_takefocus(self): |
---|
428 | n/a | widget = self.create() |
---|
429 | n/a | self.checkParams(widget, 'takefocus', '0', '1', '') |
---|
430 | n/a | |
---|
431 | n/a | def test_text(self): |
---|
432 | n/a | widget = self.create() |
---|
433 | n/a | self.checkParams(widget, 'text', '', 'any string') |
---|
434 | n/a | |
---|
435 | n/a | def test_textvariable(self): |
---|
436 | n/a | widget = self.create() |
---|
437 | n/a | var = tkinter.StringVar(self.root) |
---|
438 | n/a | self.checkVariableParam(widget, 'textvariable', var) |
---|
439 | n/a | |
---|
440 | n/a | def test_troughcolor(self): |
---|
441 | n/a | widget = self.create() |
---|
442 | n/a | self.checkColorParam(widget, 'troughcolor') |
---|
443 | n/a | |
---|
444 | n/a | def test_underline(self): |
---|
445 | n/a | widget = self.create() |
---|
446 | n/a | self.checkIntegerParam(widget, 'underline', 0, 1, 10) |
---|
447 | n/a | |
---|
448 | n/a | def test_wraplength(self): |
---|
449 | n/a | widget = self.create() |
---|
450 | n/a | self.checkPixelsParam(widget, 'wraplength', 100) |
---|
451 | n/a | |
---|
452 | n/a | def test_xscrollcommand(self): |
---|
453 | n/a | widget = self.create() |
---|
454 | n/a | self.checkCommandParam(widget, 'xscrollcommand') |
---|
455 | n/a | |
---|
456 | n/a | def test_yscrollcommand(self): |
---|
457 | n/a | widget = self.create() |
---|
458 | n/a | self.checkCommandParam(widget, 'yscrollcommand') |
---|
459 | n/a | |
---|
460 | n/a | # non-standard but common options |
---|
461 | n/a | |
---|
462 | n/a | def test_command(self): |
---|
463 | n/a | widget = self.create() |
---|
464 | n/a | self.checkCommandParam(widget, 'command') |
---|
465 | n/a | |
---|
466 | n/a | def test_indicatoron(self): |
---|
467 | n/a | widget = self.create() |
---|
468 | n/a | self.checkBooleanParam(widget, 'indicatoron') |
---|
469 | n/a | |
---|
470 | n/a | def test_offrelief(self): |
---|
471 | n/a | widget = self.create() |
---|
472 | n/a | self.checkReliefParam(widget, 'offrelief') |
---|
473 | n/a | |
---|
474 | n/a | def test_overrelief(self): |
---|
475 | n/a | widget = self.create() |
---|
476 | n/a | self.checkReliefParam(widget, 'overrelief') |
---|
477 | n/a | |
---|
478 | n/a | def test_selectcolor(self): |
---|
479 | n/a | widget = self.create() |
---|
480 | n/a | self.checkColorParam(widget, 'selectcolor') |
---|
481 | n/a | |
---|
482 | n/a | def test_selectimage(self): |
---|
483 | n/a | widget = self.create() |
---|
484 | n/a | self.checkImageParam(widget, 'selectimage') |
---|
485 | n/a | |
---|
486 | n/a | @requires_tcl(8, 5) |
---|
487 | n/a | def test_tristateimage(self): |
---|
488 | n/a | widget = self.create() |
---|
489 | n/a | self.checkImageParam(widget, 'tristateimage') |
---|
490 | n/a | |
---|
491 | n/a | @requires_tcl(8, 5) |
---|
492 | n/a | def test_tristatevalue(self): |
---|
493 | n/a | widget = self.create() |
---|
494 | n/a | self.checkParam(widget, 'tristatevalue', 'unknowable') |
---|
495 | n/a | |
---|
496 | n/a | def test_variable(self): |
---|
497 | n/a | widget = self.create() |
---|
498 | n/a | var = tkinter.DoubleVar(self.root) |
---|
499 | n/a | self.checkVariableParam(widget, 'variable', var) |
---|
500 | n/a | |
---|
501 | n/a | |
---|
502 | n/a | class IntegerSizeTests: |
---|
503 | n/a | def test_height(self): |
---|
504 | n/a | widget = self.create() |
---|
505 | n/a | self.checkIntegerParam(widget, 'height', 100, -100, 0) |
---|
506 | n/a | |
---|
507 | n/a | def test_width(self): |
---|
508 | n/a | widget = self.create() |
---|
509 | n/a | self.checkIntegerParam(widget, 'width', 402, -402, 0) |
---|
510 | n/a | |
---|
511 | n/a | |
---|
512 | n/a | class PixelSizeTests: |
---|
513 | n/a | def test_height(self): |
---|
514 | n/a | widget = self.create() |
---|
515 | n/a | self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, -100, 0, '3c') |
---|
516 | n/a | |
---|
517 | n/a | def test_width(self): |
---|
518 | n/a | widget = self.create() |
---|
519 | n/a | self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i') |
---|
520 | n/a | |
---|
521 | n/a | |
---|
522 | n/a | def add_standard_options(*source_classes): |
---|
523 | n/a | # This decorator adds test_xxx methods from source classes for every xxx |
---|
524 | n/a | # option in the OPTIONS class attribute if they are not defined explicitly. |
---|
525 | n/a | def decorator(cls): |
---|
526 | n/a | for option in cls.OPTIONS: |
---|
527 | n/a | methodname = 'test_' + option |
---|
528 | n/a | if not hasattr(cls, methodname): |
---|
529 | n/a | for source_class in source_classes: |
---|
530 | n/a | if hasattr(source_class, methodname): |
---|
531 | n/a | setattr(cls, methodname, |
---|
532 | n/a | getattr(source_class, methodname)) |
---|
533 | n/a | break |
---|
534 | n/a | else: |
---|
535 | n/a | def test(self, option=option): |
---|
536 | n/a | widget = self.create() |
---|
537 | n/a | widget[option] |
---|
538 | n/a | raise AssertionError('Option "%s" is not tested in %s' % |
---|
539 | n/a | (option, cls.__name__)) |
---|
540 | n/a | test.__name__ = methodname |
---|
541 | n/a | setattr(cls, methodname, test) |
---|
542 | n/a | return cls |
---|
543 | n/a | return decorator |
---|
544 | n/a | |
---|
545 | n/a | def setUpModule(): |
---|
546 | n/a | if test.support.verbose: |
---|
547 | n/a | tcl = tkinter.Tcl() |
---|
548 | n/a | print('patchlevel =', tcl.call('info', 'patchlevel')) |
---|