Skip to content

Commit 86cdbd8

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.15] gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods (GH-151782) (GH-151799)
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 70d495a commit 86cdbd8

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
@@ -461,6 +461,48 @@ def test_tk_bisque(self):
461461
self.assertEqual(root['background'], '#ffe4c4')
462462
self.assertRaises(TypeError, root.tk_bisque, 'x')
463463

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

962+
def test_wm_iconposition(self):
963+
t = tkinter.Toplevel(self.root)
964+
t.wm_iconposition(3, 4) # An X11 hint; may be a no-op elsewhere.
965+
if t._windowingsystem == 'x11':
966+
self.assertEqual(t.wm_iconposition(), (3, 4))
967+
968+
def test_wm_iconmask_iconwindow(self):
969+
if self.root._windowingsystem != 'x11':
970+
self.skipTest('iconmask and iconwindow are X11-specific')
971+
t = tkinter.Toplevel(self.root)
972+
t.wm_iconmask('gray50') # No exception.
973+
icon = tkinter.Toplevel(self.root)
974+
t.wm_iconwindow(icon)
975+
self.assertEqual(str(t.wm_iconwindow()), str(icon))
976+
977+
def test_wm_colormapwindows(self):
978+
if self.root._windowingsystem != 'x11':
979+
self.skipTest('colormapwindows is X11-specific')
980+
t = tkinter.Toplevel(self.root)
981+
self.assertEqual(t.wm_colormapwindows(), [])
982+
f = tkinter.Frame(t)
983+
t.wm_colormapwindows(f)
984+
self.assertEqual([str(w) for w in t.wm_colormapwindows()], [str(f)])
985+
986+
def test_wm_manage_forget(self):
987+
f = tkinter.Frame(self.root)
988+
self.root.wm_manage(f) # Make the frame a top-level window.
989+
self.root.wm_forget(f) # Revert it; no exception either way.
990+
920991
def test_wm_client_command(self):
921992
t = tkinter.Toplevel(self.root)
922993
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)