1import unittest 2import Tkinter as tkinter 3from Tkinter import TclError 4import os 5import sys 6from test.test_support import requires, run_unittest 7 8from test_ttk.support import (tcl_version, requires_tcl, get_tk_patchlevel, 9 widget_eq) 10from widget_tests import ( 11 add_standard_options, noconv, noconv_meth, int_round, pixels_round, 12 AbstractWidgetTest, StandardOptionsTests, 13 IntegerSizeTests, PixelSizeTests, 14 setUpModule) 15 16requires('gui') 17 18 19class AbstractToplevelTest(AbstractWidgetTest, PixelSizeTests): 20 _conv_pad_pixels = noconv_meth 21 22 def test_class(self): 23 widget = self.create() 24 self.assertEqual(widget['class'], 25 widget.__class__.__name__.title()) 26 self.checkInvalidParam(widget, 'class', 'Foo', 27 errmsg="can't modify -class option after widget is created") 28 widget2 = self.create(class_='Foo') 29 self.assertEqual(widget2['class'], 'Foo') 30 31 def test_colormap(self): 32 widget = self.create() 33 self.assertEqual(widget['colormap'], '') 34 self.checkInvalidParam(widget, 'colormap', 'new', 35 errmsg="can't modify -colormap option after widget is created") 36 widget2 = self.create(colormap='new') 37 self.assertEqual(widget2['colormap'], 'new') 38 39 def test_container(self): 40 widget = self.create() 41 self.assertEqual(widget['container'], 0 if self.wantobjects else '0') 42 self.checkInvalidParam(widget, 'container', 1, 43 errmsg="can't modify -container option after widget is created") 44 widget2 = self.create(container=True) 45 self.assertEqual(widget2['container'], 1 if self.wantobjects else '1') 46 47 def test_visual(self): 48 widget = self.create() 49 self.assertEqual(widget['visual'], '') 50 self.checkInvalidParam(widget, 'visual', 'default', 51 errmsg="can't modify -visual option after widget is created") 52 widget2 = self.create(visual='default') 53 self.assertEqual(widget2['visual'], 'default') 54 55 56@add_standard_options(StandardOptionsTests) 57class ToplevelTest(AbstractToplevelTest, unittest.TestCase): 58 OPTIONS = ( 59 'background', 'borderwidth', 60 'class', 'colormap', 'container', 'cursor', 'height', 61 'highlightbackground', 'highlightcolor', 'highlightthickness', 62 'menu', 'padx', 'pady', 'relief', 'screen', 63 'takefocus', 'use', 'visual', 'width', 64 ) 65 66 def create(self, **kwargs): 67 return tkinter.Toplevel(self.root, **kwargs) 68 69 def test_menu(self): 70 widget = self.create() 71 menu = tkinter.Menu(self.root) 72 self.checkParam(widget, 'menu', menu, eq=widget_eq) 73 self.checkParam(widget, 'menu', '') 74 75 def test_screen(self): 76 widget = self.create() 77 self.assertEqual(widget['screen'], '') 78 try: 79 display = os.environ['DISPLAY'] 80 except KeyError: 81 self.skipTest('No $DISPLAY set.') 82 self.checkInvalidParam(widget, 'screen', display, 83 errmsg="can't modify -screen option after widget is created") 84 widget2 = self.create(screen=display) 85 self.assertEqual(widget2['screen'], display) 86 87 def test_use(self): 88 widget = self.create() 89 self.assertEqual(widget['use'], '') 90 parent = self.create(container=True) 91 # hex() adds the 'L' suffix for longs 92 wid = '%#x' % parent.winfo_id() 93 widget2 = self.create(use=wid) 94 self.assertEqual(widget2['use'], wid) 95 96 97@add_standard_options(StandardOptionsTests) 98class FrameTest(AbstractToplevelTest, unittest.TestCase): 99 OPTIONS = ( 100 'background', 'borderwidth', 101 'class', 'colormap', 'container', 'cursor', 'height', 102 'highlightbackground', 'highlightcolor', 'highlightthickness', 103 'padx', 'pady', 'relief', 'takefocus', 'visual', 'width', 104 ) 105 106 def create(self, **kwargs): 107 return tkinter.Frame(self.root, **kwargs) 108 109 110@add_standard_options(StandardOptionsTests) 111class LabelFrameTest(AbstractToplevelTest, unittest.TestCase): 112 OPTIONS = ( 113 'background', 'borderwidth', 114 'class', 'colormap', 'container', 'cursor', 115 'font', 'foreground', 'height', 116 'highlightbackground', 'highlightcolor', 'highlightthickness', 117 'labelanchor', 'labelwidget', 'padx', 'pady', 'relief', 118 'takefocus', 'text', 'visual', 'width', 119 ) 120 121 def create(self, **kwargs): 122 return tkinter.LabelFrame(self.root, **kwargs) 123 124 def test_labelanchor(self): 125 widget = self.create() 126 self.checkEnumParam(widget, 'labelanchor', 127 'e', 'en', 'es', 'n', 'ne', 'nw', 128 's', 'se', 'sw', 'w', 'wn', 'ws') 129 self.checkInvalidParam(widget, 'labelanchor', 'center') 130 131 def test_labelwidget(self): 132 widget = self.create() 133 label = tkinter.Label(self.root, text='Mupp', name='foo') 134 self.checkParam(widget, 'labelwidget', label, expected='.foo') 135 label.destroy() 136 137 138class AbstractLabelTest(AbstractWidgetTest, IntegerSizeTests): 139 _conv_pixels = noconv_meth 140 141 def test_highlightthickness(self): 142 widget = self.create() 143 self.checkPixelsParam(widget, 'highlightthickness', 144 0, 1.3, 2.6, 6, -2, '10p') 145 146 147@add_standard_options(StandardOptionsTests) 148class LabelTest(AbstractLabelTest, unittest.TestCase): 149 OPTIONS = ( 150 'activebackground', 'activeforeground', 'anchor', 151 'background', 'bitmap', 'borderwidth', 'compound', 'cursor', 152 'disabledforeground', 'font', 'foreground', 'height', 153 'highlightbackground', 'highlightcolor', 'highlightthickness', 154 'image', 'justify', 'padx', 'pady', 'relief', 'state', 155 'takefocus', 'text', 'textvariable', 156 'underline', 'width', 'wraplength', 157 ) 158 159 def create(self, **kwargs): 160 return tkinter.Label(self.root, **kwargs) 161 162 163@add_standard_options(StandardOptionsTests) 164class ButtonTest(AbstractLabelTest, unittest.TestCase): 165 OPTIONS = ( 166 'activebackground', 'activeforeground', 'anchor', 167 'background', 'bitmap', 'borderwidth', 168 'command', 'compound', 'cursor', 'default', 169 'disabledforeground', 'font', 'foreground', 'height', 170 'highlightbackground', 'highlightcolor', 'highlightthickness', 171 'image', 'justify', 'overrelief', 'padx', 'pady', 'relief', 172 'repeatdelay', 'repeatinterval', 173 'state', 'takefocus', 'text', 'textvariable', 174 'underline', 'width', 'wraplength') 175 176 def create(self, **kwargs): 177 return tkinter.Button(self.root, **kwargs) 178 179 def test_default(self): 180 widget = self.create() 181 self.checkEnumParam(widget, 'default', 'active', 'disabled', 'normal') 182 183 184@add_standard_options(StandardOptionsTests) 185class CheckbuttonTest(AbstractLabelTest, unittest.TestCase): 186 OPTIONS = ( 187 'activebackground', 'activeforeground', 'anchor', 188 'background', 'bitmap', 'borderwidth', 189 'command', 'compound', 'cursor', 190 'disabledforeground', 'font', 'foreground', 'height', 191 'highlightbackground', 'highlightcolor', 'highlightthickness', 192 'image', 'indicatoron', 'justify', 193 'offrelief', 'offvalue', 'onvalue', 'overrelief', 194 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state', 195 'takefocus', 'text', 'textvariable', 196 'tristateimage', 'tristatevalue', 197 'underline', 'variable', 'width', 'wraplength', 198 ) 199 200 def create(self, **kwargs): 201 return tkinter.Checkbutton(self.root, **kwargs) 202 203 204 def test_offvalue(self): 205 widget = self.create() 206 self.checkParams(widget, 'offvalue', 1, 2.3, '', 'any string') 207 208 def test_onvalue(self): 209 widget = self.create() 210 self.checkParams(widget, 'onvalue', 1, 2.3, '', 'any string') 211 212 213@add_standard_options(StandardOptionsTests) 214class RadiobuttonTest(AbstractLabelTest, unittest.TestCase): 215 OPTIONS = ( 216 'activebackground', 'activeforeground', 'anchor', 217 'background', 'bitmap', 'borderwidth', 218 'command', 'compound', 'cursor', 219 'disabledforeground', 'font', 'foreground', 'height', 220 'highlightbackground', 'highlightcolor', 'highlightthickness', 221 'image', 'indicatoron', 'justify', 'offrelief', 'overrelief', 222 'padx', 'pady', 'relief', 'selectcolor', 'selectimage', 'state', 223 'takefocus', 'text', 'textvariable', 224 'tristateimage', 'tristatevalue', 225 'underline', 'value', 'variable', 'width', 'wraplength', 226 ) 227 228 def create(self, **kwargs): 229 return tkinter.Radiobutton(self.root, **kwargs) 230 231 def test_value(self): 232 widget = self.create() 233 self.checkParams(widget, 'value', 1, 2.3, '', 'any string') 234 235 236@add_standard_options(StandardOptionsTests) 237class MenubuttonTest(AbstractLabelTest, unittest.TestCase): 238 OPTIONS = ( 239 'activebackground', 'activeforeground', 'anchor', 240 'background', 'bitmap', 'borderwidth', 241 'compound', 'cursor', 'direction', 242 'disabledforeground', 'font', 'foreground', 'height', 243 'highlightbackground', 'highlightcolor', 'highlightthickness', 244 'image', 'indicatoron', 'justify', 'menu', 245 'padx', 'pady', 'relief', 'state', 246 'takefocus', 'text', 'textvariable', 247 'underline', 'width', 'wraplength', 248 ) 249 _conv_pixels = staticmethod(pixels_round) 250 251 def create(self, **kwargs): 252 return tkinter.Menubutton(self.root, **kwargs) 253 254 def test_direction(self): 255 widget = self.create() 256 self.checkEnumParam(widget, 'direction', 257 'above', 'below', 'flush', 'left', 'right') 258 259 def test_height(self): 260 widget = self.create() 261 self.checkIntegerParam(widget, 'height', 100, -100, 0, conv=str) 262 263 test_highlightthickness = StandardOptionsTests.test_highlightthickness.im_func 264 265 @unittest.skipIf(sys.platform == 'darwin', 266 'crashes with Cocoa Tk (issue19733)') 267 def test_image(self): 268 widget = self.create() 269 image = tkinter.PhotoImage(master=self.root, name='image1') 270 self.checkParam(widget, 'image', image, conv=str) 271 errmsg = 'image "spam" doesn\'t exist' 272 with self.assertRaises(tkinter.TclError) as cm: 273 widget['image'] = 'spam' 274 if errmsg is not None: 275 self.assertEqual(str(cm.exception), errmsg) 276 with self.assertRaises(tkinter.TclError) as cm: 277 widget.configure({'image': 'spam'}) 278 if errmsg is not None: 279 self.assertEqual(str(cm.exception), errmsg) 280 281 def test_menu(self): 282 widget = self.create() 283 menu = tkinter.Menu(widget, name='menu') 284 self.checkParam(widget, 'menu', menu, eq=widget_eq) 285 menu.destroy() 286 287 def test_padx(self): 288 widget = self.create() 289 self.checkPixelsParam(widget, 'padx', 3, 4.4, 5.6, '12m') 290 self.checkParam(widget, 'padx', -2, expected=0) 291 292 def test_pady(self): 293 widget = self.create() 294 self.checkPixelsParam(widget, 'pady', 3, 4.4, 5.6, '12m') 295 self.checkParam(widget, 'pady', -2, expected=0) 296 297 def test_width(self): 298 widget = self.create() 299 self.checkIntegerParam(widget, 'width', 402, -402, 0, conv=str) 300 301 302class OptionMenuTest(MenubuttonTest, unittest.TestCase): 303 304 def create(self, default='b', values=('a', 'b', 'c'), **kwargs): 305 return tkinter.OptionMenu(self.root, None, default, *values, **kwargs) 306 307 308@add_standard_options(IntegerSizeTests, StandardOptionsTests) 309class EntryTest(AbstractWidgetTest, unittest.TestCase): 310 OPTIONS = ( 311 'background', 'borderwidth', 'cursor', 312 'disabledbackground', 'disabledforeground', 313 'exportselection', 'font', 'foreground', 314 'highlightbackground', 'highlightcolor', 'highlightthickness', 315 'insertbackground', 'insertborderwidth', 316 'insertofftime', 'insertontime', 'insertwidth', 317 'invalidcommand', 'justify', 'readonlybackground', 'relief', 318 'selectbackground', 'selectborderwidth', 'selectforeground', 319 'show', 'state', 'takefocus', 'textvariable', 320 'validate', 'validatecommand', 'width', 'xscrollcommand', 321 ) 322 323 def create(self, **kwargs): 324 return tkinter.Entry(self.root, **kwargs) 325 326 def test_disabledbackground(self): 327 widget = self.create() 328 self.checkColorParam(widget, 'disabledbackground') 329 330 def test_insertborderwidth(self): 331 widget = self.create(insertwidth=100) 332 self.checkPixelsParam(widget, 'insertborderwidth', 333 0, 1.3, 2.6, 6, -2, '10p') 334 # insertborderwidth is bounded above by a half of insertwidth. 335 self.checkParam(widget, 'insertborderwidth', 60, expected=100//2) 336 337 def test_insertwidth(self): 338 widget = self.create() 339 self.checkPixelsParam(widget, 'insertwidth', 1.3, 3.6, '10p') 340 self.checkParam(widget, 'insertwidth', 0.1, expected=2) 341 self.checkParam(widget, 'insertwidth', -2, expected=2) 342 if pixels_round(0.9) <= 0: 343 self.checkParam(widget, 'insertwidth', 0.9, expected=2) 344 else: 345 self.checkParam(widget, 'insertwidth', 0.9, expected=1) 346 347 def test_invalidcommand(self): 348 widget = self.create() 349 self.checkCommandParam(widget, 'invalidcommand') 350 self.checkCommandParam(widget, 'invcmd') 351 352 def test_readonlybackground(self): 353 widget = self.create() 354 self.checkColorParam(widget, 'readonlybackground') 355 356 def test_show(self): 357 widget = self.create() 358 self.checkParam(widget, 'show', '*') 359 self.checkParam(widget, 'show', '') 360 self.checkParam(widget, 'show', ' ') 361 362 def test_state(self): 363 widget = self.create() 364 self.checkEnumParam(widget, 'state', 365 'disabled', 'normal', 'readonly') 366 367 def test_validate(self): 368 widget = self.create() 369 self.checkEnumParam(widget, 'validate', 370 'all', 'key', 'focus', 'focusin', 'focusout', 'none') 371 372 def test_validatecommand(self): 373 widget = self.create() 374 self.checkCommandParam(widget, 'validatecommand') 375 self.checkCommandParam(widget, 'vcmd') 376 377 378@add_standard_options(StandardOptionsTests) 379class SpinboxTest(EntryTest, unittest.TestCase): 380 OPTIONS = ( 381 'activebackground', 'background', 'borderwidth', 382 'buttonbackground', 'buttoncursor', 'buttondownrelief', 'buttonuprelief', 383 'command', 'cursor', 'disabledbackground', 'disabledforeground', 384 'exportselection', 'font', 'foreground', 'format', 'from', 385 'highlightbackground', 'highlightcolor', 'highlightthickness', 386 'increment', 387 'insertbackground', 'insertborderwidth', 388 'insertofftime', 'insertontime', 'insertwidth', 389 'invalidcommand', 'justify', 'relief', 'readonlybackground', 390 'repeatdelay', 'repeatinterval', 391 'selectbackground', 'selectborderwidth', 'selectforeground', 392 'state', 'takefocus', 'textvariable', 'to', 393 'validate', 'validatecommand', 'values', 394 'width', 'wrap', 'xscrollcommand', 395 ) 396 397 def create(self, **kwargs): 398 return tkinter.Spinbox(self.root, **kwargs) 399 400 test_show = None 401 402 def test_buttonbackground(self): 403 widget = self.create() 404 self.checkColorParam(widget, 'buttonbackground') 405 406 def test_buttoncursor(self): 407 widget = self.create() 408 self.checkCursorParam(widget, 'buttoncursor') 409 410 def test_buttondownrelief(self): 411 widget = self.create() 412 self.checkReliefParam(widget, 'buttondownrelief') 413 414 def test_buttonuprelief(self): 415 widget = self.create() 416 self.checkReliefParam(widget, 'buttonuprelief') 417 418 def test_format(self): 419 widget = self.create() 420 self.checkParam(widget, 'format', '%2f') 421 self.checkParam(widget, 'format', '%2.2f') 422 self.checkParam(widget, 'format', '%.2f') 423 self.checkParam(widget, 'format', '%2.f') 424 self.checkInvalidParam(widget, 'format', '%2e-1f') 425 self.checkInvalidParam(widget, 'format', '2.2') 426 self.checkInvalidParam(widget, 'format', '%2.-2f') 427 self.checkParam(widget, 'format', '%-2.02f') 428 self.checkParam(widget, 'format', '% 2.02f') 429 self.checkParam(widget, 'format', '% -2.200f') 430 self.checkParam(widget, 'format', '%09.200f') 431 self.checkInvalidParam(widget, 'format', '%d') 432 433 def test_from(self): 434 widget = self.create() 435 self.checkParam(widget, 'to', 100.0) 436 self.checkFloatParam(widget, 'from', -10, 10.2, 11.7) 437 self.checkInvalidParam(widget, 'from', 200, 438 errmsg='-to value must be greater than -from value') 439 440 def test_increment(self): 441 widget = self.create() 442 self.checkFloatParam(widget, 'increment', -1, 1, 10.2, 12.8, 0) 443 444 def test_to(self): 445 widget = self.create() 446 self.checkParam(widget, 'from', -100.0) 447 self.checkFloatParam(widget, 'to', -10, 10.2, 11.7) 448 self.checkInvalidParam(widget, 'to', -200, 449 errmsg='-to value must be greater than -from value') 450 451 def test_values(self): 452 # XXX 453 widget = self.create() 454 self.assertEqual(widget['values'], '') 455 self.checkParam(widget, 'values', 'mon tue wed thur') 456 self.checkParam(widget, 'values', ('mon', 'tue', 'wed', 'thur'), 457 expected='mon tue wed thur') 458 self.checkParam(widget, 'values', (42, 3.14, '', 'any string'), 459 expected='42 3.14 {} {any string}') 460 self.checkParam(widget, 'values', '') 461 462 def test_wrap(self): 463 widget = self.create() 464 self.checkBooleanParam(widget, 'wrap') 465 466 def test_bbox(self): 467 widget = self.create() 468 self.assertIsBoundingBox(widget.bbox(0)) 469 self.assertRaises(tkinter.TclError, widget.bbox, 'noindex') 470 self.assertRaises(tkinter.TclError, widget.bbox, None) 471 self.assertRaises(TypeError, widget.bbox) 472 self.assertRaises(TypeError, widget.bbox, 0, 1) 473 474 475@add_standard_options(StandardOptionsTests) 476class TextTest(AbstractWidgetTest, unittest.TestCase): 477 OPTIONS = ( 478 'autoseparators', 'background', 'blockcursor', 'borderwidth', 479 'cursor', 'endline', 'exportselection', 480 'font', 'foreground', 'height', 481 'highlightbackground', 'highlightcolor', 'highlightthickness', 482 'inactiveselectbackground', 'insertbackground', 'insertborderwidth', 483 'insertofftime', 'insertontime', 'insertunfocussed', 'insertwidth', 484 'maxundo', 'padx', 'pady', 'relief', 485 'selectbackground', 'selectborderwidth', 'selectforeground', 486 'setgrid', 'spacing1', 'spacing2', 'spacing3', 'startline', 'state', 487 'tabs', 'tabstyle', 'takefocus', 'undo', 'width', 'wrap', 488 'xscrollcommand', 'yscrollcommand', 489 ) 490 if tcl_version < (8, 5): 491 _stringify = True 492 493 def create(self, **kwargs): 494 return tkinter.Text(self.root, **kwargs) 495 496 def test_autoseparators(self): 497 widget = self.create() 498 self.checkBooleanParam(widget, 'autoseparators') 499 500 @requires_tcl(8, 5) 501 def test_blockcursor(self): 502 widget = self.create() 503 self.checkBooleanParam(widget, 'blockcursor') 504 505 @requires_tcl(8, 5) 506 def test_endline(self): 507 widget = self.create() 508 text = '\n'.join('Line %d' for i in range(100)) 509 widget.insert('end', text) 510 self.checkParam(widget, 'endline', 200, expected='') 511 self.checkParam(widget, 'endline', -10, expected='') 512 self.checkInvalidParam(widget, 'endline', 'spam', 513 errmsg='expected integer but got "spam"') 514 self.checkParam(widget, 'endline', 50) 515 self.checkParam(widget, 'startline', 15) 516 self.checkInvalidParam(widget, 'endline', 10, 517 errmsg='-startline must be less than or equal to -endline') 518 519 def test_height(self): 520 widget = self.create() 521 self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, '3c') 522 self.checkParam(widget, 'height', -100, expected=1) 523 self.checkParam(widget, 'height', 0, expected=1) 524 525 def test_maxundo(self): 526 widget = self.create() 527 self.checkIntegerParam(widget, 'maxundo', 0, 5, -1) 528 529 @requires_tcl(8, 5) 530 def test_inactiveselectbackground(self): 531 widget = self.create() 532 self.checkColorParam(widget, 'inactiveselectbackground') 533 534 @requires_tcl(8, 6) 535 def test_insertunfocussed(self): 536 widget = self.create() 537 self.checkEnumParam(widget, 'insertunfocussed', 538 'hollow', 'none', 'solid') 539 540 def test_selectborderwidth(self): 541 widget = self.create() 542 self.checkPixelsParam(widget, 'selectborderwidth', 543 1.3, 2.6, -2, '10p', conv=noconv, 544 keep_orig=tcl_version >= (8, 5)) 545 546 def test_spacing1(self): 547 widget = self.create() 548 self.checkPixelsParam(widget, 'spacing1', 20, 21.4, 22.6, '0.5c') 549 self.checkParam(widget, 'spacing1', -5, expected=0) 550 551 def test_spacing2(self): 552 widget = self.create() 553 self.checkPixelsParam(widget, 'spacing2', 5, 6.4, 7.6, '0.1c') 554 self.checkParam(widget, 'spacing2', -1, expected=0) 555 556 def test_spacing3(self): 557 widget = self.create() 558 self.checkPixelsParam(widget, 'spacing3', 20, 21.4, 22.6, '0.5c') 559 self.checkParam(widget, 'spacing3', -10, expected=0) 560 561 @requires_tcl(8, 5) 562 def test_startline(self): 563 widget = self.create() 564 text = '\n'.join('Line %d' for i in range(100)) 565 widget.insert('end', text) 566 self.checkParam(widget, 'startline', 200, expected='') 567 self.checkParam(widget, 'startline', -10, expected='') 568 self.checkInvalidParam(widget, 'startline', 'spam', 569 errmsg='expected integer but got "spam"') 570 self.checkParam(widget, 'startline', 10) 571 self.checkParam(widget, 'endline', 50) 572 self.checkInvalidParam(widget, 'startline', 70, 573 errmsg='-startline must be less than or equal to -endline') 574 575 def test_state(self): 576 widget = self.create() 577 if tcl_version < (8, 5): 578 self.checkParams(widget, 'state', 'disabled', 'normal') 579 else: 580 self.checkEnumParam(widget, 'state', 'disabled', 'normal') 581 582 def test_tabs(self): 583 widget = self.create() 584 if get_tk_patchlevel() < (8, 5, 11): 585 self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i'), 586 expected=('10.2', '20.7', '1i', '2i')) 587 else: 588 self.checkParam(widget, 'tabs', (10.2, 20.7, '1i', '2i')) 589 self.checkParam(widget, 'tabs', '10.2 20.7 1i 2i', 590 expected=('10.2', '20.7', '1i', '2i')) 591 self.checkParam(widget, 'tabs', '2c left 4c 6c center', 592 expected=('2c', 'left', '4c', '6c', 'center')) 593 self.checkInvalidParam(widget, 'tabs', 'spam', 594 errmsg='bad screen distance "spam"', 595 keep_orig=tcl_version >= (8, 5)) 596 597 @requires_tcl(8, 5) 598 def test_tabstyle(self): 599 widget = self.create() 600 self.checkEnumParam(widget, 'tabstyle', 'tabular', 'wordprocessor') 601 602 def test_undo(self): 603 widget = self.create() 604 self.checkBooleanParam(widget, 'undo') 605 606 def test_width(self): 607 widget = self.create() 608 self.checkIntegerParam(widget, 'width', 402) 609 self.checkParam(widget, 'width', -402, expected=1) 610 self.checkParam(widget, 'width', 0, expected=1) 611 612 def test_wrap(self): 613 widget = self.create() 614 if tcl_version < (8, 5): 615 self.checkParams(widget, 'wrap', 'char', 'none', 'word') 616 else: 617 self.checkEnumParam(widget, 'wrap', 'char', 'none', 'word') 618 619 def test_bbox(self): 620 widget = self.create() 621 self.assertIsBoundingBox(widget.bbox('1.1')) 622 self.assertIsNone(widget.bbox('end')) 623 self.assertRaises(tkinter.TclError, widget.bbox, 'noindex') 624 self.assertRaises(tkinter.TclError, widget.bbox, None) 625 self.assertRaises(tkinter.TclError, widget.bbox) 626 self.assertRaises(tkinter.TclError, widget.bbox, '1.1', 'end') 627 628 629@add_standard_options(PixelSizeTests, StandardOptionsTests) 630class CanvasTest(AbstractWidgetTest, unittest.TestCase): 631 OPTIONS = ( 632 'background', 'borderwidth', 633 'closeenough', 'confine', 'cursor', 'height', 634 'highlightbackground', 'highlightcolor', 'highlightthickness', 635 'insertbackground', 'insertborderwidth', 636 'insertofftime', 'insertontime', 'insertwidth', 637 'offset', 'relief', 'scrollregion', 638 'selectbackground', 'selectborderwidth', 'selectforeground', 639 'state', 'takefocus', 640 'xscrollcommand', 'xscrollincrement', 641 'yscrollcommand', 'yscrollincrement', 'width', 642 ) 643 644 _conv_pixels = staticmethod(int_round) 645 _stringify = True 646 647 def create(self, **kwargs): 648 return tkinter.Canvas(self.root, **kwargs) 649 650 def test_closeenough(self): 651 widget = self.create() 652 self.checkFloatParam(widget, 'closeenough', 24, 2.4, 3.6, -3, 653 conv=float) 654 655 def test_confine(self): 656 widget = self.create() 657 self.checkBooleanParam(widget, 'confine') 658 659 def test_offset(self): 660 widget = self.create() 661 self.assertEqual(widget['offset'], '0,0') 662 self.checkParams(widget, 'offset', 663 'n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'center') 664 self.checkParam(widget, 'offset', '10,20') 665 self.checkParam(widget, 'offset', '#5,6') 666 self.checkInvalidParam(widget, 'offset', 'spam') 667 668 def test_scrollregion(self): 669 widget = self.create() 670 self.checkParam(widget, 'scrollregion', '0 0 200 150') 671 self.checkParam(widget, 'scrollregion', (0, 0, 200, 150), 672 expected='0 0 200 150') 673 self.checkParam(widget, 'scrollregion', '') 674 self.checkInvalidParam(widget, 'scrollregion', 'spam', 675 errmsg='bad scrollRegion "spam"') 676 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 'spam')) 677 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200)) 678 self.checkInvalidParam(widget, 'scrollregion', (0, 0, 200, 150, 0)) 679 680 def test_state(self): 681 widget = self.create() 682 self.checkEnumParam(widget, 'state', 'disabled', 'normal', 683 errmsg='bad state value "{}": must be normal or disabled') 684 685 def test_xscrollincrement(self): 686 widget = self.create() 687 self.checkPixelsParam(widget, 'xscrollincrement', 688 40, 0, 41.2, 43.6, -40, '0.5i') 689 690 def test_yscrollincrement(self): 691 widget = self.create() 692 self.checkPixelsParam(widget, 'yscrollincrement', 693 10, 0, 11.2, 13.6, -10, '0.1i') 694 695 696@add_standard_options(IntegerSizeTests, StandardOptionsTests) 697class ListboxTest(AbstractWidgetTest, unittest.TestCase): 698 OPTIONS = ( 699 'activestyle', 'background', 'borderwidth', 'cursor', 700 'disabledforeground', 'exportselection', 701 'font', 'foreground', 'height', 702 'highlightbackground', 'highlightcolor', 'highlightthickness', 703 'justify', 'listvariable', 'relief', 704 'selectbackground', 'selectborderwidth', 'selectforeground', 705 'selectmode', 'setgrid', 'state', 706 'takefocus', 'width', 'xscrollcommand', 'yscrollcommand', 707 ) 708 709 def create(self, **kwargs): 710 return tkinter.Listbox(self.root, **kwargs) 711 712 def test_activestyle(self): 713 widget = self.create() 714 self.checkEnumParam(widget, 'activestyle', 715 'dotbox', 'none', 'underline') 716 717 test_justify = requires_tcl(8, 6, 5)(StandardOptionsTests.test_justify.im_func) 718 719 def test_listvariable(self): 720 widget = self.create() 721 var = tkinter.DoubleVar(self.root) 722 self.checkVariableParam(widget, 'listvariable', var) 723 724 def test_selectmode(self): 725 widget = self.create() 726 self.checkParam(widget, 'selectmode', 'single') 727 self.checkParam(widget, 'selectmode', 'browse') 728 self.checkParam(widget, 'selectmode', 'multiple') 729 self.checkParam(widget, 'selectmode', 'extended') 730 731 def test_state(self): 732 widget = self.create() 733 self.checkEnumParam(widget, 'state', 'disabled', 'normal') 734 735 def test_itemconfigure(self): 736 widget = self.create() 737 with self.assertRaisesRegexp(TclError, 'item number "0" out of range'): 738 widget.itemconfigure(0) 739 colors = 'red orange yellow green blue white violet'.split() 740 widget.insert('end', *colors) 741 for i, color in enumerate(colors): 742 widget.itemconfigure(i, background=color) 743 with self.assertRaises(TypeError): 744 widget.itemconfigure() 745 with self.assertRaisesRegexp(TclError, 'bad listbox index "red"'): 746 widget.itemconfigure('red') 747 self.assertEqual(widget.itemconfigure(0, 'background'), 748 ('background', 'background', 'Background', '', 'red')) 749 self.assertEqual(widget.itemconfigure('end', 'background'), 750 ('background', 'background', 'Background', '', 'violet')) 751 self.assertEqual(widget.itemconfigure('@0,0', 'background'), 752 ('background', 'background', 'Background', '', 'red')) 753 754 d = widget.itemconfigure(0) 755 self.assertIsInstance(d, dict) 756 for k, v in d.items(): 757 self.assertIn(len(v), (2, 5)) 758 if len(v) == 5: 759 self.assertEqual(v, widget.itemconfigure(0, k)) 760 self.assertEqual(v[4], widget.itemcget(0, k)) 761 762 def check_itemconfigure(self, name, value): 763 widget = self.create() 764 widget.insert('end', 'a', 'b', 'c', 'd') 765 widget.itemconfigure(0, **{name: value}) 766 self.assertEqual(widget.itemconfigure(0, name)[4], value) 767 self.assertEqual(widget.itemcget(0, name), value) 768 with self.assertRaisesRegexp(TclError, 'unknown color name "spam"'): 769 widget.itemconfigure(0, **{name: 'spam'}) 770 771 def test_itemconfigure_background(self): 772 self.check_itemconfigure('background', '#ff0000') 773 774 def test_itemconfigure_bg(self): 775 self.check_itemconfigure('bg', '#ff0000') 776 777 def test_itemconfigure_fg(self): 778 self.check_itemconfigure('fg', '#110022') 779 780 def test_itemconfigure_foreground(self): 781 self.check_itemconfigure('foreground', '#110022') 782 783 def test_itemconfigure_selectbackground(self): 784 self.check_itemconfigure('selectbackground', '#110022') 785 786 def test_itemconfigure_selectforeground(self): 787 self.check_itemconfigure('selectforeground', '#654321') 788 789 def test_box(self): 790 lb = self.create() 791 lb.insert(0, *('el%d' % i for i in range(8))) 792 lb.pack() 793 self.assertIsBoundingBox(lb.bbox(0)) 794 self.assertIsNone(lb.bbox(-1)) 795 self.assertIsNone(lb.bbox(10)) 796 self.assertRaises(TclError, lb.bbox, 'noindex') 797 self.assertRaises(TclError, lb.bbox, None) 798 self.assertRaises(TypeError, lb.bbox) 799 self.assertRaises(TypeError, lb.bbox, 0, 1) 800 801 def test_curselection(self): 802 lb = self.create() 803 lb.insert(0, *('el%d' % i for i in range(8))) 804 lb.selection_clear(0, tkinter.END) 805 lb.selection_set(2, 4) 806 lb.selection_set(6) 807 self.assertEqual(lb.curselection(), (2, 3, 4, 6)) 808 self.assertRaises(TypeError, lb.curselection, 0) 809 810 def test_get(self): 811 lb = self.create() 812 lb.insert(0, *('el%d' % i for i in range(8))) 813 self.assertEqual(lb.get(0), 'el0') 814 self.assertEqual(lb.get(3), 'el3') 815 self.assertEqual(lb.get('end'), 'el7') 816 self.assertEqual(lb.get(8), '') 817 self.assertEqual(lb.get(-1), '') 818 self.assertEqual(lb.get(3, 5), ('el3', 'el4', 'el5')) 819 self.assertEqual(lb.get(5, 'end'), ('el5', 'el6', 'el7')) 820 self.assertEqual(lb.get(5, 0), ()) 821 self.assertEqual(lb.get(0, 0), ('el0',)) 822 self.assertRaises(TclError, lb.get, 'noindex') 823 self.assertRaises(TclError, lb.get, None) 824 self.assertRaises(TypeError, lb.get) 825 self.assertRaises(TclError, lb.get, 'end', 'noindex') 826 self.assertRaises(TypeError, lb.get, 1, 2, 3) 827 self.assertRaises(TclError, lb.get, 2.4) 828 829 830@add_standard_options(PixelSizeTests, StandardOptionsTests) 831class ScaleTest(AbstractWidgetTest, unittest.TestCase): 832 OPTIONS = ( 833 'activebackground', 'background', 'bigincrement', 'borderwidth', 834 'command', 'cursor', 'digits', 'font', 'foreground', 'from', 835 'highlightbackground', 'highlightcolor', 'highlightthickness', 836 'label', 'length', 'orient', 'relief', 837 'repeatdelay', 'repeatinterval', 838 'resolution', 'showvalue', 'sliderlength', 'sliderrelief', 'state', 839 'takefocus', 'tickinterval', 'to', 'troughcolor', 'variable', 'width', 840 ) 841 default_orient = 'vertical' 842 843 def create(self, **kwargs): 844 return tkinter.Scale(self.root, **kwargs) 845 846 def test_bigincrement(self): 847 widget = self.create() 848 self.checkFloatParam(widget, 'bigincrement', 12.4, 23.6, -5) 849 850 def test_digits(self): 851 widget = self.create() 852 self.checkIntegerParam(widget, 'digits', 5, 0) 853 854 def test_from(self): 855 widget = self.create() 856 self.checkFloatParam(widget, 'from', 100, 14.9, 15.1, conv=round) 857 858 def test_label(self): 859 widget = self.create() 860 self.checkParam(widget, 'label', 'any string') 861 self.checkParam(widget, 'label', '') 862 863 def test_length(self): 864 widget = self.create() 865 self.checkPixelsParam(widget, 'length', 130, 131.2, 135.6, '5i') 866 867 def test_resolution(self): 868 widget = self.create() 869 self.checkFloatParam(widget, 'resolution', 4.2, 0, 6.7, -2) 870 871 def test_showvalue(self): 872 widget = self.create() 873 self.checkBooleanParam(widget, 'showvalue') 874 875 def test_sliderlength(self): 876 widget = self.create() 877 self.checkPixelsParam(widget, 'sliderlength', 878 10, 11.2, 15.6, -3, '3m') 879 880 def test_sliderrelief(self): 881 widget = self.create() 882 self.checkReliefParam(widget, 'sliderrelief') 883 884 def test_tickinterval(self): 885 widget = self.create() 886 self.checkFloatParam(widget, 'tickinterval', 1, 4.3, 7.6, 0, 887 conv=round) 888 self.checkParam(widget, 'tickinterval', -2, expected=2, 889 conv=round) 890 891 def test_to(self): 892 widget = self.create() 893 self.checkFloatParam(widget, 'to', 300, 14.9, 15.1, -10, 894 conv=round) 895 896 897@add_standard_options(PixelSizeTests, StandardOptionsTests) 898class ScrollbarTest(AbstractWidgetTest, unittest.TestCase): 899 OPTIONS = ( 900 'activebackground', 'activerelief', 901 'background', 'borderwidth', 902 'command', 'cursor', 'elementborderwidth', 903 'highlightbackground', 'highlightcolor', 'highlightthickness', 904 'jump', 'orient', 'relief', 905 'repeatdelay', 'repeatinterval', 906 'takefocus', 'troughcolor', 'width', 907 ) 908 _conv_pixels = staticmethod(int_round) 909 _stringify = True 910 default_orient = 'vertical' 911 912 def create(self, **kwargs): 913 return tkinter.Scrollbar(self.root, **kwargs) 914 915 def test_activerelief(self): 916 widget = self.create() 917 self.checkReliefParam(widget, 'activerelief') 918 919 def test_elementborderwidth(self): 920 widget = self.create() 921 self.checkPixelsParam(widget, 'elementborderwidth', 4.3, 5.6, -2, '1m') 922 923 def test_orient(self): 924 widget = self.create() 925 self.checkEnumParam(widget, 'orient', 'vertical', 'horizontal', 926 errmsg='bad orientation "{}": must be vertical or horizontal') 927 928 def test_activate(self): 929 sb = self.create() 930 for e in ('arrow1', 'slider', 'arrow2'): 931 sb.activate(e) 932 sb.activate('') 933 self.assertRaises(TypeError, sb.activate) 934 self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2') 935 936 def test_set(self): 937 sb = self.create() 938 sb.set(0.2, 0.4) 939 self.assertEqual(sb.get(), (0.2, 0.4)) 940 self.assertRaises(TclError, sb.set, 'abc', 'def') 941 self.assertRaises(TclError, sb.set, 0.6, 'def') 942 self.assertRaises(TclError, sb.set, 0.6, None) 943 self.assertRaises(TclError, sb.set, 0.6) 944 self.assertRaises(TclError, sb.set, 0.6, 0.7, 0.8) 945 946 947@add_standard_options(StandardOptionsTests) 948class PanedWindowTest(AbstractWidgetTest, unittest.TestCase): 949 OPTIONS = ( 950 'background', 'borderwidth', 'cursor', 951 'handlepad', 'handlesize', 'height', 952 'opaqueresize', 'orient', 953 'proxybackground', 'proxyborderwidth', 'proxyrelief', 954 'relief', 955 'sashcursor', 'sashpad', 'sashrelief', 'sashwidth', 956 'showhandle', 'width', 957 ) 958 default_orient = 'horizontal' 959 960 def create(self, **kwargs): 961 return tkinter.PanedWindow(self.root, **kwargs) 962 963 def test_handlepad(self): 964 widget = self.create() 965 self.checkPixelsParam(widget, 'handlepad', 5, 6.4, 7.6, -3, '1m') 966 967 def test_handlesize(self): 968 widget = self.create() 969 self.checkPixelsParam(widget, 'handlesize', 8, 9.4, 10.6, -3, '2m', 970 conv=noconv) 971 972 def test_height(self): 973 widget = self.create() 974 self.checkPixelsParam(widget, 'height', 100, 101.2, 102.6, -100, 0, '1i', 975 conv=noconv) 976 977 def test_opaqueresize(self): 978 widget = self.create() 979 self.checkBooleanParam(widget, 'opaqueresize') 980 981 @requires_tcl(8, 6, 5) 982 def test_proxybackground(self): 983 widget = self.create() 984 self.checkColorParam(widget, 'proxybackground') 985 986 @requires_tcl(8, 6, 5) 987 def test_proxyborderwidth(self): 988 widget = self.create() 989 self.checkPixelsParam(widget, 'proxyborderwidth', 990 0, 1.3, 2.9, 6, -2, '10p', 991 conv=noconv) 992 993 @requires_tcl(8, 6, 5) 994 def test_proxyrelief(self): 995 widget = self.create() 996 self.checkReliefParam(widget, 'proxyrelief') 997 998 def test_sashcursor(self): 999 widget = self.create() 1000 self.checkCursorParam(widget, 'sashcursor') 1001 1002 def test_sashpad(self): 1003 widget = self.create() 1004 self.checkPixelsParam(widget, 'sashpad', 8, 1.3, 2.6, -2, '2m') 1005 1006 def test_sashrelief(self): 1007 widget = self.create() 1008 self.checkReliefParam(widget, 'sashrelief') 1009 1010 def test_sashwidth(self): 1011 widget = self.create() 1012 self.checkPixelsParam(widget, 'sashwidth', 10, 11.1, 15.6, -3, '1m', 1013 conv=noconv) 1014 1015 def test_showhandle(self): 1016 widget = self.create() 1017 self.checkBooleanParam(widget, 'showhandle') 1018 1019 def test_width(self): 1020 widget = self.create() 1021 self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i', 1022 conv=noconv) 1023 1024 def create2(self): 1025 p = self.create() 1026 b = tkinter.Button(p) 1027 c = tkinter.Button(p) 1028 p.add(b) 1029 p.add(c) 1030 return p, b, c 1031 1032 def test_paneconfigure(self): 1033 p, b, c = self.create2() 1034 self.assertRaises(TypeError, p.paneconfigure) 1035 d = p.paneconfigure(b) 1036 self.assertIsInstance(d, dict) 1037 for k, v in d.items(): 1038 self.assertEqual(len(v), 5) 1039 self.assertEqual(v, p.paneconfigure(b, k)) 1040 self.assertEqual(v[4], p.panecget(b, k)) 1041 1042 def check_paneconfigure(self, p, b, name, value, expected, stringify=False): 1043 conv = lambda x: x 1044 if not self.wantobjects or stringify: 1045 expected = str(expected) 1046 if self.wantobjects and stringify: 1047 conv = str 1048 p.paneconfigure(b, **{name: value}) 1049 self.assertEqual(conv(p.paneconfigure(b, name)[4]), expected) 1050 self.assertEqual(conv(p.panecget(b, name)), expected) 1051 1052 def check_paneconfigure_bad(self, p, b, name, msg): 1053 with self.assertRaisesRegexp(TclError, msg): 1054 p.paneconfigure(b, **{name: 'badValue'}) 1055 1056 def test_paneconfigure_after(self): 1057 p, b, c = self.create2() 1058 self.check_paneconfigure(p, b, 'after', c, str(c)) 1059 self.check_paneconfigure_bad(p, b, 'after', 1060 'bad window path name "badValue"') 1061 1062 def test_paneconfigure_before(self): 1063 p, b, c = self.create2() 1064 self.check_paneconfigure(p, b, 'before', c, str(c)) 1065 self.check_paneconfigure_bad(p, b, 'before', 1066 'bad window path name "badValue"') 1067 1068 def test_paneconfigure_height(self): 1069 p, b, c = self.create2() 1070 self.check_paneconfigure(p, b, 'height', 10, 10, 1071 stringify=get_tk_patchlevel() < (8, 5, 11)) 1072 self.check_paneconfigure_bad(p, b, 'height', 1073 'bad screen distance "badValue"') 1074 1075 @requires_tcl(8, 5) 1076 def test_paneconfigure_hide(self): 1077 p, b, c = self.create2() 1078 self.check_paneconfigure(p, b, 'hide', False, 0) 1079 self.check_paneconfigure_bad(p, b, 'hide', 1080 'expected boolean value but got "badValue"') 1081 1082 def test_paneconfigure_minsize(self): 1083 p, b, c = self.create2() 1084 self.check_paneconfigure(p, b, 'minsize', 10, 10) 1085 self.check_paneconfigure_bad(p, b, 'minsize', 1086 'bad screen distance "badValue"') 1087 1088 def test_paneconfigure_padx(self): 1089 p, b, c = self.create2() 1090 self.check_paneconfigure(p, b, 'padx', 1.3, 1) 1091 self.check_paneconfigure_bad(p, b, 'padx', 1092 'bad screen distance "badValue"') 1093 1094 def test_paneconfigure_pady(self): 1095 p, b, c = self.create2() 1096 self.check_paneconfigure(p, b, 'pady', 1.3, 1) 1097 self.check_paneconfigure_bad(p, b, 'pady', 1098 'bad screen distance "badValue"') 1099 1100 def test_paneconfigure_sticky(self): 1101 p, b, c = self.create2() 1102 self.check_paneconfigure(p, b, 'sticky', 'nsew', 'nesw') 1103 self.check_paneconfigure_bad(p, b, 'sticky', 1104 'bad stickyness value "badValue": must ' 1105 'be a string containing zero or more of ' 1106 'n, e, s, and w') 1107 1108 @requires_tcl(8, 5) 1109 def test_paneconfigure_stretch(self): 1110 p, b, c = self.create2() 1111 self.check_paneconfigure(p, b, 'stretch', 'alw', 'always') 1112 self.check_paneconfigure_bad(p, b, 'stretch', 1113 'bad stretch "badValue": must be ' 1114 'always, first, last, middle, or never') 1115 1116 def test_paneconfigure_width(self): 1117 p, b, c = self.create2() 1118 self.check_paneconfigure(p, b, 'width', 10, 10, 1119 stringify=get_tk_patchlevel() < (8, 5, 11)) 1120 self.check_paneconfigure_bad(p, b, 'width', 1121 'bad screen distance "badValue"') 1122 1123 1124@add_standard_options(StandardOptionsTests) 1125class MenuTest(AbstractWidgetTest, unittest.TestCase): 1126 OPTIONS = ( 1127 'activebackground', 'activeborderwidth', 'activeforeground', 1128 'background', 'borderwidth', 'cursor', 1129 'disabledforeground', 'font', 'foreground', 1130 'postcommand', 'relief', 'selectcolor', 'takefocus', 1131 'tearoff', 'tearoffcommand', 'title', 'type', 1132 ) 1133 _conv_pixels = noconv_meth 1134 1135 def create(self, **kwargs): 1136 return tkinter.Menu(self.root, **kwargs) 1137 1138 def test_postcommand(self): 1139 widget = self.create() 1140 self.checkCommandParam(widget, 'postcommand') 1141 1142 def test_tearoff(self): 1143 widget = self.create() 1144 self.checkBooleanParam(widget, 'tearoff') 1145 1146 def test_tearoffcommand(self): 1147 widget = self.create() 1148 self.checkCommandParam(widget, 'tearoffcommand') 1149 1150 def test_title(self): 1151 widget = self.create() 1152 self.checkParam(widget, 'title', 'any string') 1153 1154 def test_type(self): 1155 widget = self.create() 1156 self.checkEnumParam(widget, 'type', 1157 'normal', 'tearoff', 'menubar') 1158 1159 def test_entryconfigure(self): 1160 m1 = self.create() 1161 m1.add_command(label='test') 1162 self.assertRaises(TypeError, m1.entryconfigure) 1163 with self.assertRaisesRegexp(TclError, 'bad menu entry index "foo"'): 1164 m1.entryconfigure('foo') 1165 d = m1.entryconfigure(1) 1166 self.assertIsInstance(d, dict) 1167 for k, v in d.items(): 1168 self.assertIsInstance(k, str) 1169 self.assertIsInstance(v, tuple) 1170 self.assertEqual(len(v), 5) 1171 self.assertEqual(v[0], k) 1172 self.assertEqual(m1.entrycget(1, k), v[4]) 1173 m1.destroy() 1174 1175 def test_entryconfigure_label(self): 1176 m1 = self.create() 1177 m1.add_command(label='test') 1178 self.assertEqual(m1.entrycget(1, 'label'), 'test') 1179 m1.entryconfigure(1, label='changed') 1180 self.assertEqual(m1.entrycget(1, 'label'), 'changed') 1181 1182 def test_entryconfigure_variable(self): 1183 m1 = self.create() 1184 v1 = tkinter.BooleanVar(self.root) 1185 v2 = tkinter.BooleanVar(self.root) 1186 m1.add_checkbutton(variable=v1, onvalue=True, offvalue=False, 1187 label='Nonsense') 1188 self.assertEqual(str(m1.entrycget(1, 'variable')), str(v1)) 1189 m1.entryconfigure(1, variable=v2) 1190 self.assertEqual(str(m1.entrycget(1, 'variable')), str(v2)) 1191 1192 1193@add_standard_options(PixelSizeTests, StandardOptionsTests) 1194class MessageTest(AbstractWidgetTest, unittest.TestCase): 1195 OPTIONS = ( 1196 'anchor', 'aspect', 'background', 'borderwidth', 1197 'cursor', 'font', 'foreground', 1198 'highlightbackground', 'highlightcolor', 'highlightthickness', 1199 'justify', 'padx', 'pady', 'relief', 1200 'takefocus', 'text', 'textvariable', 'width', 1201 ) 1202 _conv_pad_pixels = noconv_meth 1203 1204 def create(self, **kwargs): 1205 return tkinter.Message(self.root, **kwargs) 1206 1207 def test_aspect(self): 1208 widget = self.create() 1209 self.checkIntegerParam(widget, 'aspect', 250, 0, -300) 1210 1211 1212tests_gui = [ 1213 ButtonTest, CanvasTest, CheckbuttonTest, EntryTest, 1214 FrameTest, LabelFrameTest,LabelTest, ListboxTest, 1215 MenubuttonTest, MenuTest, MessageTest, OptionMenuTest, 1216 PanedWindowTest, RadiobuttonTest, ScaleTest, ScrollbarTest, 1217 SpinboxTest, TextTest, ToplevelTest, 1218] 1219 1220if __name__ == '__main__': 1221 run_unittest(*tests_gui) 1222