Skip to content

Commit 90bbdec

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.13] gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods (GH-151782) (GH-151801)
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 9b503ae commit 90bbdec

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

449+
def test_wait_variable(self):
450+
var = tkinter.StringVar(self.root)
451+
self.assertEqual(self.root.waitvar, self.root.wait_variable)
452+
self.root.after(1, var.set, 'done')
453+
self.root.wait_variable(var) # Returns once the variable is set.
454+
self.assertEqual(var.get(), 'done')
455+
456+
def test_wait_window(self):
457+
top = tkinter.Toplevel(self.root)
458+
self.root.after(1, top.destroy)
459+
self.root.wait_window(top) # Returns once the window is destroyed.
460+
self.assertFalse(top.winfo_exists())
461+
462+
def test_tk_focusFollowsMouse(self):
463+
self.root.tk_focusFollowsMouse() # No exception.
464+
465+
def test_selection_handle(self):
466+
f = tkinter.Frame(self.root)
467+
def handler(offset, length):
468+
return 'PAYLOAD'[int(offset):int(offset) + int(length)]
469+
f.selection_handle(handler)
470+
f.selection_own()
471+
self.assertEqual(f.selection_get(), 'PAYLOAD')
472+
473+
def test_grab_set_global(self):
474+
# A successful global grab directs all events on the display to this
475+
# application, so only the error paths are tested here.
476+
self.assertRaises(TypeError, self.root.grab_set_global, 'extra')
477+
with self.subTest('non-viewable window'):
478+
if self.root._windowingsystem != 'x11':
479+
# Grabbing a non-viewable window fails only on X11; elsewhere
480+
# it would actually grab the whole display.
481+
self.skipTest('only X11 fails the grab')
482+
f = tkinter.Frame(self.root) # not yet viewable
483+
self.assertRaisesRegex(TclError, 'grab failed', f.grab_set_global)
484+
485+
def test_send(self):
486+
if self.root._windowingsystem != 'x11':
487+
self.skipTest('send is only supported on X11')
488+
self.assertRaisesRegex(TclError, 'no application named',
489+
self.root.send, 'no_such_interp_xyzzy', 'set x 1')
490+
449491
def test_event_repr_defaults(self):
450492
e = tkinter.Event()
451493
e.serial = 12345
@@ -891,6 +933,35 @@ def test_wm_iconname(self):
891933
t.iconname('Icon')
892934
self.assertIn(t.iconname(), ('Icon', ''))
893935

936+
def test_wm_iconposition(self):
937+
t = tkinter.Toplevel(self.root)
938+
t.wm_iconposition(3, 4) # An X11 hint; may be a no-op elsewhere.
939+
if t._windowingsystem == 'x11':
940+
self.assertEqual(t.wm_iconposition(), (3, 4))
941+
942+
def test_wm_iconmask_iconwindow(self):
943+
if self.root._windowingsystem != 'x11':
944+
self.skipTest('iconmask and iconwindow are X11-specific')
945+
t = tkinter.Toplevel(self.root)
946+
t.wm_iconmask('gray50') # No exception.
947+
icon = tkinter.Toplevel(self.root)
948+
t.wm_iconwindow(icon)
949+
self.assertEqual(str(t.wm_iconwindow()), str(icon))
950+
951+
def test_wm_colormapwindows(self):
952+
if self.root._windowingsystem != 'x11':
953+
self.skipTest('colormapwindows is X11-specific')
954+
t = tkinter.Toplevel(self.root)
955+
self.assertEqual(t.wm_colormapwindows(), [])
956+
f = tkinter.Frame(t)
957+
t.wm_colormapwindows(f)
958+
self.assertEqual([str(w) for w in t.wm_colormapwindows()], [str(f)])
959+
960+
def test_wm_manage_forget(self):
961+
f = tkinter.Frame(self.root)
962+
self.root.wm_manage(f) # Make the frame a top-level window.
963+
self.root.wm_forget(f) # Revert it; no exception either way.
964+
894965
def test_wm_client_command(self):
895966
t = tkinter.Toplevel(self.root)
896967
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)