Skip to content

Commit 58240c4

Browse files
gh-72880: Fix the fontchooser tests on macOS and with wantobjects=0
On macOS the native dialog stores the -font option as a resolved font description rather than the font name, and with wantobjects=0 Tcl returns strings instead of integers. Compare the actual font attributes and coerce the size to an integer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent f2bdda3 commit 58240c4

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Lib/test/test_tkinter/test_fontchooser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,17 @@ def test_parent(self):
7171

7272
def test_configure_font_instance(self):
7373
# A Font instance can be passed as the font, both to the
74-
# constructor and to configure().
74+
# constructor and to configure(). The dialog may store it as
75+
# the font name or as a resolved description depending on the
76+
# platform, so compare the actual attributes.
77+
def actual(spec):
78+
return font.Font(self.root, spec, exists=True).actual()
7579
f = font.Font(self.root, family='Courier', size=14, weight='bold')
7680
fc = FontChooser(self.root, font=f)
77-
self.assertEqual(str(fc.cget('font')), str(f))
81+
self.assertEqual(actual(fc.cget('font')), f.actual())
7882
f2 = font.Font(self.root, family='Times', size=11)
7983
fc.configure(font=f2)
80-
self.assertEqual(str(fc.cget('font')), str(f2))
84+
self.assertEqual(actual(fc.cget('font')), f2.actual())
8185

8286
def test_configure_visible_readonly(self):
8387
with self.assertRaises(tkinter.TclError):
@@ -101,7 +105,7 @@ def test_command(self):
101105
# The description is wrapped without creating a named font.
102106
self.assertEqual(str(selected), 'Courier 10')
103107
self.assertFalse(selected.delete_font)
104-
self.assertEqual(selected.actual('size'), 10)
108+
self.assertEqual(int(selected.actual('size')), 10)
105109
# Replacing the callback deletes the old Tcl command.
106110
self.fc.configure(command=lambda font: None)
107111
self.assertNotEqual(self.fc._command_name, name)

0 commit comments

Comments
 (0)