Skip to content

Commit 308f419

Browse files
serhiy-storchakaclaude
authored andcommitted
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. (cherry picked from commit 23793ac) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cc7043d commit 308f419

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
@@ -281,6 +281,25 @@ def test_pack_slaves(self):
281281
b.pack_configure()
282282
self.assertEqual(pack.pack_slaves(), [a, b])
283283

284+
def test_pack_short_aliases(self):
285+
# slaves, content and propagate are aliases of the pack_* methods
286+
# (Misc precedes Pack, Place and Grid in the method resolution order).
287+
pack, a, b, c, d = self.create2()
288+
self.assertEqual(pack.slaves, pack.pack_slaves)
289+
self.assertEqual(pack.content, pack.pack_content)
290+
self.assertEqual(pack.propagate, pack.pack_propagate)
291+
292+
self.assertEqual(pack.slaves(), [])
293+
a.pack_configure()
294+
self.assertEqual(pack.slaves(), [a])
295+
self.assertEqual(pack.content(), [a])
296+
297+
pack.configure(width=300, height=200)
298+
pack.propagate(False)
299+
self.root.update()
300+
self.assertEqual(pack.winfo_reqwidth(), 300)
301+
self.assertEqual(pack.winfo_reqheight(), 200)
302+
284303

285304
class PlaceTest(AbstractWidgetTest, unittest.TestCase):
286305

@@ -486,6 +505,18 @@ def test_place_slaves(self):
486505
with self.assertRaises(TypeError):
487506
foo.place_slaves(0)
488507

508+
def test_place_method_aliases(self):
509+
# The Place manager defines configure, info, forget, slaves and
510+
# content as aliases of its place_* methods. On a real widget the
511+
# short names are provided by Misc and Pack (earlier in the method
512+
# resolution order), so the aliases are checked on the class itself.
513+
self.assertIs(tkinter.Place.configure, tkinter.Place.place_configure)
514+
self.assertIs(tkinter.Place.config, tkinter.Place.place_configure)
515+
self.assertIs(tkinter.Place.info, tkinter.Place.place_info)
516+
self.assertIs(tkinter.Place.forget, tkinter.Place.place_forget)
517+
self.assertIs(tkinter.Place.slaves, tkinter.Misc.place_slaves)
518+
self.assertIs(tkinter.Place.content, tkinter.Misc.place_content)
519+
489520

490521
class GridTest(AbstractWidgetTest, unittest.TestCase):
491522

@@ -904,6 +935,30 @@ def test_grid_slaves(self):
904935
self.assertEqual(self.root.grid_slaves(column=1), [d, c, a])
905936
self.assertEqual(self.root.grid_slaves(row=1, column=1), [d, c])
906937

938+
def test_grid_short_aliases(self):
939+
# columnconfigure, rowconfigure, size, anchor and bbox are aliases of
940+
# the corresponding grid_* methods (Misc precedes Pack, Place and Grid
941+
# in the method resolution order).
942+
root = self.root
943+
self.assertEqual(root.columnconfigure, root.grid_columnconfigure)
944+
self.assertEqual(root.rowconfigure, root.grid_rowconfigure)
945+
self.assertEqual(root.size, root.grid_size)
946+
self.assertEqual(root.anchor, root.grid_anchor)
947+
self.assertEqual(root.bbox, root.grid_bbox)
948+
949+
self.assertEqual(root.size(), (0, 0))
950+
b = tkinter.Button(root)
951+
b.grid_configure(column=2, row=3)
952+
self.assertEqual(root.size(), (3, 4))
953+
954+
root.columnconfigure(0, weight=2)
955+
self.assertEqual(root.grid_columnconfigure(0, 'weight'), 2)
956+
root.rowconfigure(0, weight=3)
957+
self.assertEqual(root.grid_rowconfigure(0, 'weight'), 3)
958+
959+
root.anchor('se')
960+
self.assertEqual(root.tk.call('grid', 'anchor', root), 'se')
961+
907962

908963
if __name__ == '__main__':
909964
unittest.main()

0 commit comments

Comments
 (0)