Skip to content

Commit c971201

Browse files
gh-151678: Fix tkinter Wm/Winfo tests on Windows and Aqua
winfo_fpixels() reports a different bad-distance message on Tk 9; the wm command and client hints are X11 properties whose round trip (with the command returned as a split list on Aqua) is now only checked on X11; and Aqua enforces a minimum window width, so use larger minsize values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 36ae602 commit c971201

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

Lib/test/test_tkinter/test_misc.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,10 @@ def test_winfo_fpixels(self):
693693
self.assertIsInstance(self.root.winfo_fpixels('1i'), float)
694694
self.assertAlmostEqual(self.root.winfo_fpixels('1i'),
695695
self.root.winfo_fpixels('72p'))
696-
self.assertRaisesRegex(TclError, 'bad screen distance "spam"',
696+
# Tk < 9 reports 'bad screen distance "spam"', Tk 9 reports
697+
# 'expected screen distance ... but got "spam"'.
698+
self.assertRaisesRegex(TclError,
699+
r'(bad|expected) screen distance.*"spam"',
697700
self.root.winfo_fpixels, 'spam')
698701

699702
def test_winfo_screen(self):
@@ -833,8 +836,9 @@ def test_wm_geometry(self):
833836

834837
def test_wm_minsize_maxsize(self):
835838
t = tkinter.Toplevel(self.root)
836-
t.minsize(50, 60)
837-
self.assertEqual(t.minsize(), (50, 60))
839+
# Use a width above the minimum enforced by some platforms (72 on Aqua).
840+
t.minsize(150, 100)
841+
self.assertEqual(t.minsize(), (150, 100))
838842
t.maxsize(500, 600)
839843
self.assertEqual(t.maxsize(), (500, 600))
840844

@@ -878,13 +882,14 @@ def test_wm_iconname(self):
878882
self.assertIn(t.iconname(), ('Icon', ''))
879883

880884
def test_wm_client_command(self):
881-
# WM_CLIENT_MACHINE and WM_COMMAND are X11 properties and may be
882-
# no-ops on other platforms.
883885
t = tkinter.Toplevel(self.root)
884886
t.client('myhost')
885-
self.assertIn(t.client(), ('myhost', ''))
886887
t.wm_command('myapp -x')
887-
self.assertIn(t.wm_command(), ('myapp -x', ''))
888+
# WM_CLIENT_MACHINE and WM_COMMAND are X11 properties; elsewhere the
889+
# setters may be no-ops and wm_command may return a split list.
890+
if t._windowingsystem == 'x11':
891+
self.assertEqual(t.client(), 'myhost')
892+
self.assertEqual(t.wm_command(), 'myapp -x')
888893

889894
def test_wm_overrideredirect(self):
890895
t = tkinter.Toplevel(self.root)

0 commit comments

Comments
 (0)