| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 704c4c7 commit 640c5f4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,10 +4,14 @@ | |||
| 4 | 4 | from tkinter import ttk | |
| 5 | 5 | from test.support import requires, gc_collect | |
| 6 | 6 | from test.test_tkinter.support import setUpModule # noqa: F401 | |
| 7 | - from test.test_tkinter.support import AbstractTkTest, AbstractDefaultRootTest | ||
| 7 | + from test.test_tkinter.support import (AbstractTkTest, AbstractDefaultRootTest, | ||
| 8 | + get_tk_patchlevel, widget_eq) | ||
| 8 | 9 | ||
| 9 | 10 | requires('gui') | |
| 10 | 11 | ||
| 12 | + from test.test_ttk import test_widgets | ||
| 13 | + | ||
| 14 | + | ||
| 11 | 15 | class LabeledScaleTest(AbstractTkTest, unittest.TestCase): | |
| 12 | 16 | ||
| 13 | 17 | def tearDown(self): | |
@@ -193,7 +197,7 @@ def test_resize(self): | |||
| 193 | 197 | x.destroy() | |
| 194 | 198 | ||
| 195 | 199 | ||
| 196 | - class OptionMenuTest(AbstractTkTest, unittest.TestCase): | ||
| 200 | + class OptionMenuTest(test_widgets.MenubuttonTest, unittest.TestCase): | ||
| 197 | 201 | ||
| 198 | 202 | def setUp(self): | |
| 199 | 203 | super().setUp() | |
@@ -203,6 +207,47 @@ def tearDown(self): | |||
| 203 | 207 | del self.textvar | |
| 204 | 208 | super().tearDown() | |
| 205 | 209 | ||
| 210 | + def create(self, default='b', values=('a', 'b', 'c'), **kwargs): | ||
| 211 | + return ttk.OptionMenu(self.root, self.textvar, default, *values, **kwargs) | ||
| 212 | + | ||
| 213 | + def test_bad_kwarg(self): | ||
| 214 | + with self.assertRaisesRegex(tkinter.TclError, r"^unknown option -image$"): | ||
| 215 | + ttk.OptionMenu(self.root, self.textvar, 'b', image='') | ||
| 216 | + | ||
| 217 | + def test_configure_class(self): | ||
| 218 | + # Unlike a plain Menubutton, OptionMenu does not accept a class at | ||
| 219 | + # construction, so only the read-only nature of the option is tested. | ||
| 220 | + widget = self.create() | ||
| 221 | + self.assertEqual(widget['class'], '') | ||
| 222 | + errmsg = 'attempt to change read-only option' | ||
| 223 | + if get_tk_patchlevel(self.root) < (8, 6, 0, 'beta', 3): | ||
| 224 | + errmsg = 'Attempt to change read-only option' | ||
| 225 | + self.checkInvalidParam(widget, 'class', 'Foo', errmsg=errmsg) | ||
| 226 | + | ||
| 227 | + def test_configure_style(self): | ||
| 228 | + # Like Menubutton, but OptionMenu does not accept a class at | ||
| 229 | + # construction, so the custom-class part of the standard test is omitted. | ||
| 230 | + widget = self.create() | ||
| 231 | + self.assertEqual(widget['style'], '') | ||
| 232 | + self.checkInvalidParam(widget, 'style', 'Foo', | ||
| 233 | + errmsg='Layout Foo not found') | ||
| 234 | + style = ttk.Style(self.root) | ||
| 235 | + style.configure('Custom.TMenubutton') | ||
| 236 | + self.checkParam(widget, 'style', 'Custom.TMenubutton') | ||
| 237 | + | ||
| 238 | + def test_configure_menu(self): | ||
| 239 | + # OptionMenu manages its own menu; ['menu'] returns that Menu widget. | ||
| 240 | + widget = self.create() | ||
| 241 | + self.assertIsInstance(widget['menu'], tkinter.Menu) | ||
| 242 | + self.checkParam(widget, 'menu', widget['menu'], eq=widget_eq) | ||
| 243 | + | ||
| 244 | + def test_configure_text(self): | ||
| 245 | + # The displayed text is governed by the textvariable. | ||
| 246 | + widget = self.create() | ||
| 247 | + self.textvar.set('a') | ||
| 248 | + self.assertEqual(widget['text'], 'a') | ||
| 249 | + self.textvar.set('c') | ||
| 250 | + self.assertEqual(widget['text'], 'c') | ||
| 206 | 251 | ||
| 207 | 252 | def test_widget_destroy(self): | |
| 208 | 253 | var = tkinter.StringVar(self.root) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -768,6 +768,7 @@ def cb_test(): | |||
| 768 | 768 | self.assertEqual(str(cbtn['variable']), str(cbtn2['variable'])) | |
| 769 | 769 | ||
| 770 | 770 | ||
| 771 | + @add_standard_options(StandardTtkOptionsTests) | ||
| 771 | 772 | class MenubuttonTest(AbstractLabelTest, unittest.TestCase): | |
| 772 | 773 | OPTIONS = ( | |
| 773 | 774 | 'class', 'compound', 'cursor', 'direction', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments