Skip to content

Commit 2b32ded

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.14] gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods (GH-151782) (GH-151800)
Cover Misc.wait_variable and wait_window, tk_focusFollowsMouse, selection_handle, the error paths of grab_set_global, send, the X11-specific Wm methods iconposition, iconmask, iconwindow, colormapwindows and manage/forget, and the Text.window_config alias and deprecated yview_pickplace. (cherry picked from commit aa71eb2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a23a0b4 commit 2b32ded

2 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lib/test/test_tkinter/test_misc.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,48 @@ def test_tk_bisque(self):
460460
self.assertEqual(root['background'], '#ffe4c4')
461461
self.assertRaises(TypeError, root.tk_bisque, 'x')
462462

463+
def test_wait_variable(self):
464+
var = tkinter.StringVar(self.root)
465+
self.assertEqual(self.root.waitvar, self.root.wait_variable)
466+
self.root.after(1, var.set, 'done')
467+
self.root.wait_variable(var) # Returns once the variable is set.
468+
self.assertEqual(var.get(), 'done')
469+
470+
def test_wait_window(self):
471+
top = tkinter.Toplevel(self.root)
472+
self.root.after(1, top.destroy)
473+
self.root.wait_window(top) # Returns once the window is destroyed.
474+
self.assertFalse(top.winfo_exists())
475+
476+
def test_tk_focusFollowsMouse(self):
477+
self.root.tk_focusFollowsMouse() # No exception.
478+
479+
def test_selection_handle(self):
480+
f = tkinter.Frame(self.root)
481+
def handler(offset, length):
482+
return 'PAYLOAD'[int(offset):int(offset) + int(length)]
483+
f.selection_handle(handler)
484+
f.selection_own()
485+
self.assertEqual(f.selection_get(), 'PAYLOAD')
486+
487+
def test_grab_set_global(self):
488+
# A successful global grab directs all events on the display to this
489+
# application, so only the error paths are tested here.
490+
self.assertRaises(TypeError, self.root.grab_set_global, 'extra')
491+
with self.subTest('non-viewable window'):
492+
if self.root._windowingsystem != 'x11':
493+
# Grabbing a non-viewable window fails only on X11; elsewhere
494+
# it would actually grab the whole display.
495+
self.skipTest('only X11 fails the grab')
496+
f = tkinter.Frame(self.root) # not yet viewable
497+
self.assertRaisesRegex(TclError, 'grab failed', f.grab_set_global)
498+
499+
def test_send(self):
500+
if self.root._windowingsystem != 'x11':
501+
self.skipTest('send is only supported on X11')
502+
self.assertRaisesRegex(TclError, 'no application named',
503+
self.root.send, 'no_such_interp_xyzzy', 'set x 1')
504+
463505
def test_event_repr_defaults(self):
464506
e = tkinter.Event()
465507
e.serial = 12345
@@ -905,6 +947,35 @@ def test_wm_iconname(self):
905947
t.iconname('Icon')
906948
self.assertIn(t.iconname(), ('Icon', ''))
907949

950+
def test_wm_iconposition(self):
951+
t = tkinter.Toplevel(self.root)
952+
t.wm_iconposition(3, 4) # An X11 hint; may be a no-op elsewhere.
953+
if t._windowingsystem == 'x11':
954+
self.assertEqual(t.wm_iconposition(), (3, 4))
955+
956+
def test_wm_iconmask_iconwindow(self):
957+
if self.root._windowingsystem != 'x11':
958+
self.skipTest('iconmask and iconwindow are X11-specific')
959+
t = tkinter.Toplevel(self.root)
960+
t.wm_iconmask('gray50') # No exception.
961+
icon = tkinter.Toplevel(self.root)
962+
t.wm_iconwindow(icon)
963+
self.assertEqual(str(t.wm_iconwindow()), str(icon))
964+
965+
def test_wm_colormapwindows(self):
966+
if self.root._windowingsystem != 'x11':
967+
self.skipTest('colormapwindows is X11-specific')
968+
t = tkinter.Toplevel(self.root)
969+
self.assertEqual(t.wm_colormapwindows(), [])
970+
f = tkinter.Frame(t)
971+
t.wm_colormapwindows(f)
972+
self.assertEqual([str(w) for w in t.wm_colormapwindows()], [str(f)])
973+
974+
def test_wm_manage_forget(self):
975+
f = tkinter.Frame(self.root)
976+
self.root.wm_manage(f) # Make the frame a top-level window.
977+
self.root.wm_forget(f) # Revert it; no exception either way.
978+
908979
def test_wm_client_command(self):
909980
t = tkinter.Toplevel(self.root)
910981
t.client('myhost')

Lib/test/test_tkinter/test_text.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ def test_window_configure(self):
505505
self.assertIsInstance(cnf, dict)
506506
self.assertIn('stretch', cnf)
507507
self.assertRaises(TclError, text.window_cget, '1.1', 'spam')
508+
self.assertEqual(text.window_config, text.window_configure)
508509
button.destroy()
509510

510511
def test_peer(self):
@@ -562,6 +563,11 @@ def test_see(self):
562563
self.assertRaises(TypeError, text.see)
563564
self.assertRaises(TypeError, text.see, '1.0', '2.0')
564565

566+
# yview_pickplace is a deprecated way to make an index visible.
567+
text.yview_pickplace('1.0')
568+
text.update()
569+
self.assertIsNotNone(text.bbox('1.0'))
570+
565571
def test_search(self):
566572
text = self.text
567573

0 commit comments

Comments
 (0)