Skip to content

Commit 23793ac

Browse files
gh-151678: Add tests for tkinter Misc, Wm and geometry manager methods (GH-151732)
Cover previously-untested methods of the Misc, Wm, Pack, Place and Grid classes: * a new WinfoTest class for the winfo_* query methods (class, name, parent, children, toplevel, visual and screen information, atoms, pointer and screen coordinates, fpixels, containing, interps, viewable), including the pre-existing winfo_rgb and winfo_pathname; * in MiscTest: getint, getdouble, getvar, register, deletecommand, option_add/get/clear, nametowidget, the focus_*, grab_* and selection_own* methods, event_add/delete/info, and bell; * in WmTest: title, geometry, minsize/maxsize, resizable, aspect, grid, positionfrom/sizefrom, focusmodel, iconname, client/command, overrideredirect, state (with withdraw and deiconify), frame, group, protocol and transient; * the short-named aliases of the grid_*, pack_* and place_* geometry manager methods. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c4eb3ad commit 23793ac

2 files changed

Lines changed: 407 additions & 37 deletions

File tree

Lib/test/test_tkinter/test_geometry_managers.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,25 @@ def test_pack_slaves(self):
289289
b.pack_configure()
290290
self.assertEqual(pack.pack_slaves(), [a, b])
291291

292+
def test_pack_short_aliases(self):
293+
# slaves, content and propagate are aliases of the pack_* methods
294+
# (Misc precedes Pack, Place and Grid in the method resolution order).
295+
pack, a, b, c, d = self.create2()
296+
self.assertEqual(pack.slaves, pack.pack_slaves)
297+
self.assertEqual(pack.content, pack.pack_content)
298+
self.assertEqual(pack.propagate, pack.pack_propagate)
299+
300+
self.assertEqual(pack.slaves(), [])
301+
a.pack_configure()
302+
self.assertEqual(pack.slaves(), [a])
303+
self.assertEqual(pack.content(), [a])
304+
305+
pack.configure(width=300, height=200)
306+
pack.propagate(False)
307+
self.root.update()
308+
self.assertEqual(pack.winfo_reqwidth(), 300)
309+
self.assertEqual(pack.winfo_reqheight(), 200)
310+
292311

293312
class PlaceTest(AbstractWidgetTest, unittest.TestCase):
294313

@@ -503,6 +522,18 @@ def test_place_slaves(self):
503522
with self.assertRaises(TypeError):
504523
foo.place_slaves(0)
505524

525+
def test_place_method_aliases(self):
526+
# The Place manager defines configure, info, forget, slaves and
527+
# content as aliases of its place_* methods. On a real widget the
528+
# short names are provided by Misc and Pack (earlier in the method
529+
# resolution order), so the aliases are checked on the class itself.
530+
self.assertIs(tkinter.Place.configure, tkinter.Place.place_configure)
531+
self.assertIs(tkinter.Place.config, tkinter.Place.place_configure)
532+
self.assertIs(tkinter.Place.info, tkinter.Place.place_info)
533+
self.assertIs(tkinter.Place.forget, tkinter.Place.place_forget)
534+
self.assertIs(tkinter.Place.slaves, tkinter.Misc.place_slaves)
535+
self.assertIs(tkinter.Place.content, tkinter.Misc.place_content)
536+
506537

507538
class GridTest(AbstractWidgetTest, unittest.TestCase):
508539

@@ -938,6 +969,30 @@ def test_grid_slaves(self):
938969
self.assertEqual(self.root.grid_slaves(column=1), [d, c, a])
939970
self.assertEqual(self.root.grid_slaves(row=1, column=1), [d, c])
940971

972+
def test_grid_short_aliases(self):
973+
# columnconfigure, rowconfigure, size, anchor and bbox are aliases of
974+
# the corresponding grid_* methods (Misc precedes Pack, Place and Grid
975+
# in the method resolution order).
976+
root = self.root
977+
self.assertEqual(root.columnconfigure, root.grid_columnconfigure)
978+
self.assertEqual(root.rowconfigure, root.grid_rowconfigure)
979+
self.assertEqual(root.size, root.grid_size)
980+
self.assertEqual(root.anchor, root.grid_anchor)
981+
self.assertEqual(root.bbox, root.grid_bbox)
982+
983+
self.assertEqual(root.size(), (0, 0))
984+
b = tkinter.Button(root)
985+
b.grid_configure(column=2, row=3)
986+
self.assertEqual(root.size(), (3, 4))
987+
988+
root.columnconfigure(0, weight=2)
989+
self.assertEqual(root.grid_columnconfigure(0, 'weight'), 2)
990+
root.rowconfigure(0, weight=3)
991+
self.assertEqual(root.grid_rowconfigure(0, 'weight'), 3)
992+
993+
root.anchor('se')
994+
self.assertEqual(root.tk.call('grid', 'anchor', root), 'se')
995+
941996

942997
if __name__ == '__main__':
943998
unittest.main()

0 commit comments

Comments
 (0)