Commit 4f0e1674 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),

PanedWindow.paneconfigure(), and Menu.entryconfigure().
parent f19771f8
import unittest import unittest
import Tkinter import Tkinter
from Tkinter import TclError
import os import os
import sys import sys
from test.test_support import requires, run_unittest from test.test_support import requires, run_unittest
...@@ -727,6 +728,61 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase): ...@@ -727,6 +728,61 @@ class ListboxTest(AbstractWidgetTest, unittest.TestCase):
widget = self.create() widget = self.create()
self.checkEnumParam(widget, 'state', 'disabled', 'normal') 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) @add_standard_options(PixelSizeTests, StandardOptionsTests)
class ScaleTest(AbstractWidgetTest, unittest.TestCase): class ScaleTest(AbstractWidgetTest, unittest.TestCase):
OPTIONS = ( OPTIONS = (
...@@ -884,6 +940,98 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase): ...@@ -884,6 +940,98 @@ class PanedWindowTest(AbstractWidgetTest, unittest.TestCase):
self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i', self.checkPixelsParam(widget, 'width', 402, 403.4, 404.6, -402, 0, '5i',
conv=noconv) 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) @add_standard_options(StandardOptionsTests)
class MenuTest(AbstractWidgetTest, unittest.TestCase): class MenuTest(AbstractWidgetTest, unittest.TestCase):
...@@ -920,6 +1068,39 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase): ...@@ -920,6 +1068,39 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
self.checkEnumParam(widget, 'type', self.checkEnumParam(widget, 'type',
'normal', 'tearoff', 'menubar') '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) @add_standard_options(PixelSizeTests, StandardOptionsTests)
class MessageTest(AbstractWidgetTest, unittest.TestCase): class MessageTest(AbstractWidgetTest, unittest.TestCase):
......
...@@ -21,6 +21,9 @@ Library ...@@ -21,6 +21,9 @@ Library
Tests Tests
----- -----
- Issue #21522: Added Tkinter tests for Listbox.itemconfigure(),
PanedWindow.paneconfigure(), and Menu.entryconfigure().
- Issue #20635: Added tests for Tk geometry managers. - Issue #20635: Added tests for Tk geometry managers.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment