Skip to content

Commit cafc8ae

Browse files
gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods
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 aa5b164 commit cafc8ae

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lib/test/test_tkinter/test_misc.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,43 @@ 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+
f = tkinter.Frame(self.root) # not yet viewable
494+
self.assertRaisesRegex(TclError, 'grab failed', f.grab_set_global)
495+
self.assertRaises(TypeError, self.root.grab_set_global, 'extra')
496+
497+
def test_send(self):
498+
if self.root._windowingsystem != 'x11':
499+
self.skipTest('send is only supported on X11')
500+
self.assertRaisesRegex(TclError, 'no application named',
501+
self.root.send, 'no_such_interp_xyzzy', 'set x 1')
502+
466503
def test_event_repr_defaults(self):
467504
e = tkinter.Event()
468505
e.serial = 12345
@@ -934,6 +971,35 @@ def test_wm_iconname(self):
934971
t.iconname('Icon')
935972
self.assertIn(t.iconname(), ('Icon', ''))
936973

974+
def test_wm_iconposition(self):
975+
t = tkinter.Toplevel(self.root)
976+
t.wm_iconposition(3, 4) # An X11 hint; may be a no-op elsewhere.
977+
if t._windowingsystem == 'x11':
978+
self.assertEqual(t.wm_iconposition(), (3, 4))
979+
980+
def test_wm_iconmask_iconwindow(self):
981+
if self.root._windowingsystem != 'x11':
982+
self.skipTest('iconmask and iconwindow are X11-specific')
983+
t = tkinter.Toplevel(self.root)
984+
t.wm_iconmask('gray50') # No exception.
985+
icon = tkinter.Toplevel(self.root)
986+
t.wm_iconwindow(icon)
987+
self.assertEqual(str(t.wm_iconwindow()), str(icon))
988+
989+
def test_wm_colormapwindows(self):
990+
if self.root._windowingsystem != 'x11':
991+
self.skipTest('colormapwindows is X11-specific')
992+
t = tkinter.Toplevel(self.root)
993+
self.assertEqual(t.wm_colormapwindows(), [])
994+
f = tkinter.Frame(t)
995+
t.wm_colormapwindows(f)
996+
self.assertEqual([str(w) for w in t.wm_colormapwindows()], [str(f)])
997+
998+
def test_wm_manage_forget(self):
999+
f = tkinter.Frame(self.root)
1000+
self.root.wm_manage(f) # Make the frame a top-level window.
1001+
self.root.wm_forget(f) # Revert it; no exception either way.
1002+
9371003
def test_wm_client_command(self):
9381004
t = tkinter.Toplevel(self.root)
9391005
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)