Skip to content

Commit c843def

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-151678: Add tests for tkinter Misc, Wm and geometry manager methods (GH-151732) (GH-151738)
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 c110457 commit c843def

2 files changed

Lines changed: 404 additions & 37 deletions

File tree

Lib/test/test_tkinter/test_geometry_managers.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,23 @@ 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.propagate, pack.pack_propagate)
290+
291+
self.assertEqual(pack.slaves(), [])
292+
a.pack_configure()
293+
self.assertEqual(pack.slaves(), [a])
294+
295+
pack.configure(width=300, height=200)
296+
pack.propagate(False)
297+
self.root.update()
298+
self.assertEqual(pack.winfo_reqwidth(), 300)
299+
self.assertEqual(pack.winfo_reqheight(), 200)
300+
284301

285302
class PlaceTest(AbstractWidgetTest, unittest.TestCase):
286303

@@ -486,6 +503,17 @@ def test_place_slaves(self):
486503
with self.assertRaises(TypeError):
487504
foo.place_slaves(0)
488505

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

490518
class GridTest(AbstractWidgetTest, unittest.TestCase):
491519

@@ -904,6 +932,30 @@ def test_grid_slaves(self):
904932
self.assertEqual(self.root.grid_slaves(column=1), [d, c, a])
905933
self.assertEqual(self.root.grid_slaves(row=1, column=1), [d, c])
906934

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

908960
if __name__ == '__main__':
909961
unittest.main()

0 commit comments

Comments
 (0)