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