Skip to content

Commit aa71eb2

Browse files
gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods (GH-151782)
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. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 58fd9ec commit aa71eb2

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

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

979+
def test_wm_iconposition(self):
980+
t = tkinter.Toplevel(self.root)
981+
t.wm_iconposition(3, 4) # An X11 hint; may be a no-op elsewhere.
982+
if t._windowingsystem == 'x11':
983+
self.assertEqual(t.wm_iconposition(), (3, 4))
984+
985+
def test_wm_iconmask_iconwindow(self):
986+
if self.root._windowingsystem != 'x11':
987+
self.skipTest('iconmask and iconwindow are X11-specific')
988+
t = tkinter.Toplevel(self.root)
989+
t.wm_iconmask('gray50') # No exception.
990+
icon = tkinter.Toplevel(self.root)
991+
t.wm_iconwindow(icon)
992+
self.assertEqual(str(t.wm_iconwindow()), str(icon))
993+
994+
def test_wm_colormapwindows(self):
995+
if self.root._windowingsystem != 'x11':
996+
self.skipTest('colormapwindows is X11-specific')
997+
t = tkinter.Toplevel(self.root)
998+
self.assertEqual(t.wm_colormapwindows(), [])
999+
f = tkinter.Frame(t)
1000+
t.wm_colormapwindows(f)
1001+
self.assertEqual([str(w) for w in t.wm_colormapwindows()], [str(f)])
1002+
1003+
def test_wm_manage_forget(self):
1004+
f = tkinter.Frame(self.root)
1005+
self.root.wm_manage(f) # Make the frame a top-level window.
1006+
self.root.wm_forget(f) # Revert it; no exception either way.
1007+
9371008
def test_wm_client_command(self):
9381009
t = tkinter.Toplevel(self.root)
9391010
t.client('myhost')

Lib/test/test_tkinter/test_text.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,7 @@ def test_window_configure(self):
528528
self.assertIsInstance(cnf, dict)
529529
self.assertIn('stretch', cnf)
530530
self.assertRaises(TclError, text.window_cget, '1.1', 'spam')
531+
self.assertEqual(text.window_config, text.window_configure)
531532
button.destroy()
532533

533534
def test_peer(self):
@@ -585,6 +586,11 @@ def test_see(self):
585586
self.assertRaises(TypeError, text.see)
586587
self.assertRaises(TypeError, text.see, '1.0', '2.0')
587588

589+
# yview_pickplace is a deprecated way to make an index visible.
590+
text.yview_pickplace('1.0')
591+
text.update()
592+
self.assertIsNotNone(text.bbox('1.0'))
593+
588594
def test_search(self):
589595
text = self.text
590596

0 commit comments

Comments
 (0)