summaryrefslogtreecommitdiffstats
path: root/Lib/lib-tk/test/test_tkinter/test_widgets.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-05-23 11:08:31 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-05-23 11:08:31 (GMT)
commit4f0e1674146f176446be067d988557d8a1a829d7 (patch)
tree930b6a3113b640545cce016656d0bff7c80ffd47 /Lib/lib-tk/test/test_tkinter/test_widgets.py
parentf19771f831d991beaa625723b9387d026b1329b3 (diff)
downloadcpython-4f0e1674146f176446be067d988557d8a1a829d7.zip
cpython-4f0e1674146f176446be067d988557d8a1a829d7.tar.gz
cpython-4f0e1674146f176446be067d988557d8a1a829d7.tar.bz2
Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),
PanedWindow.paneconfigure(), and Menu.entryconfigure().
Diffstat (limited to 'Lib/lib-tk/test/test_tkinter/test_widgets.py')
-rw-r--r--Lib/lib-tk/test/test_tkinter/test_widgets.py181
1 files changed, 181 insertions, 0 deletions
diff --git a/Lib/lib-tk/test/test_tkinter/test_widgets.py b/Lib/lib-tk/test/test_tkinter/test_widgets.py
index 4f1a63d..b67b5a0 100644
--- a/Lib/lib-tk/test/test_tkinter/test_widgets.py
+++ b/Lib/lib-tk/test/test_tkinter/test_widgets.py
@@ -1,5 +1,6 @@
import unittest
import Tkinter
+from Tkinter import TclError
import os
import sys
from test.test_support import requires, run_unittest
@@ -727,6 +728,61 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
widget = self.create()
self.checkEnumParam(widget, 'state', 'disabled', 'normal')
+ def test_itemconfigure(self):
+ widget = self.create()
+ with self.assertRaisesRegexp(TclError, 'item number "0" out of range'):
+ widget.itemconfigure(0)
+ colors = 'red orange yellow green blue white violet'.split()
+ widget.insert('end', *colors)
+ for i, color in enumerate(colors):
+ widget.itemconfigure(i, background=color)
+ with self.assertRaises(TypeError):
+ widget.itemconfigure()
+ with self.assertRaisesRegexp(TclError, 'bad listbox index "red"'):
+ widget.itemconfigure('red')
+ self.assertEqual(widget.itemconfigure(0, 'background'),
+ ('background', 'background', 'Background', '', 'red'))
+ self.assertEqual(widget.itemconfigure('end', 'background'),
+ ('background', 'background', 'Background', '', 'violet'))
+ self.assertEqual(widget.itemconfigure('@0,0', 'background'),
+ ('background', 'background', 'Background', '', 'red'))
+
+ d = widget.itemconfigure(0)
+ self.assertIsInstance(d, dict)
+ for k, v in d.items():
+ self.assertIn(len(v), (2, 5))
+ if len(v) == 5:
+ self.assertEqual(v, widget.itemconfigure(0, k))
+ self.assertEqual(v[4], widget.itemcget(0, k))
+
+ def check_itemconfigure(self, name, value):
+ widget = self.create()
+ widget.insert('end', 'a', 'b', 'c', 'd')
+ widget.itemconfigure(0, **{name: value})
+ self.assertEqual(widget.itemconfigure(0, name)[4], value)
+ self.assertEqual(widget.itemcget(0, name), value)
+ with self.assertRaisesRegexp(TclError, 'unknown color name "spam"'):
+ widget.itemconfigure(0, **{name: 'spam'})
+
+ def test_itemconfigure_background(self):
+ self.check_itemconfigure('background', '#ff0000')
+
+ def test_itemconfigure_bg(self):
+ self.check_itemconfigure('bg', '#ff0000')
+
+ def test_itemconfigure_fg(self):
+ self.check_itemconfigure('fg', '#110022')
+
+ def test_itemconfigure_foreground(self):
+ self.check_itemconfigure('foreground', '#110022')
+
+ def test_itemconfigure_selectbackground(self):
+ self.check_itemconfigure('selectbackground', '#110022')
+
+ def test_itemconfigure_selectforeground(self):
+ self.check_itemconfigure('selectforeground', '#654321')
+
+
@add_standard_options(PixelSizeTests, StandardOptionsTests)
class ScaleTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = (
@@ -884,6 +940,98 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i',
conv=noconv)
+ def create2(self):
+ p = self.create()
+ b = Tkinter.Button(p)
+ c = Tkinter.Button(p)
+ p.add(b)
+ p.add(c)
+ return p, b, c
+
+ def test_paneconfigure(self):
+ p, b, c = self.create2()
+ self.assertRaises(TypeError, p.paneconfigure)
+ d = p.paneconfigure(b)
+ self.assertIsInstance(d, dict)
+ for k, v in d.items():
+ self.assertEqual(len(v), 5)
+ self.assertEqual(v, p.paneconfigure(b, k))
+ self.assertEqual(v[4], p.panecget(b, k))
+
+ def check_paneconfigure(self, p, b, name, value, expected):
+ if not self.wantobjects:
+ expected = str(expected)
+ p.paneconfigure(b, **{name: value})
+ self.assertEqual(p.paneconfigure(b, name)[4], expected)
+ self.assertEqual(p.panecget(b, name), expected)
+
+ def check_paneconfigure_bad(self, p, b, name, msg):
+ with self.assertRaisesRegexp(TclError, msg):
+ p.paneconfigure(b, **{name: 'badValue'})
+
+ def test_paneconfigure_after(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'after', c, str(c))
+ self.check_paneconfigure_bad(p, b, 'after',
+ 'bad window path name "badValue"')
+
+ def test_paneconfigure_before(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'before', c, str(c))
+ self.check_paneconfigure_bad(p, b, 'before',
+ 'bad window path name "badValue"')
+
+ def test_paneconfigure_height(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'height', 10, 10)
+ self.check_paneconfigure_bad(p, b, 'height',
+ 'bad screen distance "badValue"')
+
+ def test_paneconfigure_hide(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'hide', False, 0)
+ self.check_paneconfigure_bad(p, b, 'hide',
+ 'expected boolean value but got "badValue"')
+
+ def test_paneconfigure_minsize(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'minsize', 10, 10)
+ self.check_paneconfigure_bad(p, b, 'minsize',
+ 'bad screen distance "badValue"')
+
+ def test_paneconfigure_padx(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'padx', 1.3, 1)
+ self.check_paneconfigure_bad(p, b, 'padx',
+ 'bad screen distance "badValue"')
+
+ def test_paneconfigure_pady(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'pady', 1.3, 1)
+ self.check_paneconfigure_bad(p, b, 'pady',
+ 'bad screen distance "badValue"')
+
+ def test_paneconfigure_sticky(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'sticky', 'nsew', 'nesw')
+ self.check_paneconfigure_bad(p, b, 'sticky',
+ 'bad stickyness value "badValue": must '
+ 'be a string containing zero or more of '
+ 'n, e, s, and w')
+
+ def test_paneconfigure_stretch(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'stretch', 'alw', 'always')
+ self.check_paneconfigure_bad(p, b, 'stretch',
+ 'bad stretch "badValue": must be '
+ 'always, first, last, middle, or never')
+
+ def test_paneconfigure_width(self):
+ p, b, c = self.create2()
+ self.check_paneconfigure(p, b, 'width', 10, 10)
+ self.check_paneconfigure_bad(p, b, 'width',
+ 'bad screen distance "badValue"')
+
@add_standard_options(StandardOptionsTests)
class MenuTest(AbstractWidgetTest, unittest.TestCase):
@@ -920,6 +1068,39 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
self.checkEnumParam(widget, 'type',
'normal', 'tearoff', 'menubar')
+ def test_entryconfigure(self):
+ m1 = self.create()
+ m1.add_command(label='test')
+ self.assertRaises(TypeError, m1.entryconfigure)
+ with self.assertRaisesRegexp(TclError, 'bad menu entry index "foo"'):
+ m1.entryconfigure('foo')
+ d = m1.entryconfigure(1)
+ self.assertIsInstance(d, dict)
+ for k, v in d.items():
+ self.assertIsInstance(k, str)
+ self.assertIsInstance(v, tuple)
+ self.assertEqual(len(v), 5)
+ self.assertEqual(v[0], k)
+ self.assertEqual(m1.entrycget(1, k), v[4])
+ m1.destroy()
+
+ def test_entryconfigure_label(self):
+ m1 = self.create()
+ m1.add_command(label='test')
+ self.assertEqual(m1.entrycget(1, 'label'), 'test')
+ m1.entryconfigure(1, label='changed')
+ self.assertEqual(m1.entrycget(1, 'label'), 'changed')
+
+ def test_entryconfigure_variable(self):
+ m1 = self.create()
+ v1 = Tkinter.BooleanVar(self.root)
+ v2 = Tkinter.BooleanVar(self.root)
+ m1.add_checkbutton(variable=v1, onvalue=True, offvalue=False,
+ label='Nonsense')
+ self.assertEqual(str(m1.entrycget(1, 'variable')), str(v1))
+ m1.entryconfigure(1, variable=v2)
+ self.assertEqual(str(m1.entrycget(1, 'variable')), str(v2))
+
@add_standard_options(PixelSizeTests, StandardOptionsTests)
class MessageTest(AbstractWidgetTest, unittest.TestCase):