@@ -20,6 +20,10 @@ def setUpClass(cls):
2020 except tkinter .TclError :
2121 cls .font = font .Font (root = cls .root , name = fontname , exists = False )
2222
23+ def actual_size (self , desc ):
24+ # The requested size is not always available (e.g. bitmap fonts).
25+ return self .root .tk .call ('font' , 'actual' , desc , '-size' )
26+
2327 def test_configure (self ):
2428 self .assertEqual (self .font .config , self .font .configure )
2529 options = self .font .configure ()
@@ -51,7 +55,7 @@ def test_create(self):
5155 f = font .Font (root = self .root , font = ('Times' , 20 , 'bold' ))
5256 self .assertIn (f .name , font .names (self .root ))
5357 self .assertEqual (f .actual ('weight' ), 'bold' )
54- self .assertEqual (f .cget ('size' ), sizetype ( 20 ))
58+ self .assertEqual (f .cget ('size' ), self . actual_size (( 'Times' , 20 , 'bold' ) ))
5559
5660 # ... or from the keyword options.
5761 f = font .Font (root = self .root , family = 'Times' , size = 20 , weight = 'bold' )
@@ -62,13 +66,13 @@ def test_create(self):
6266 # Explicit options override the corresponding settings of *font*.
6367 f = font .Font (root = self .root , font = ('Times' , 20 , 'bold' ), weight = 'normal' )
6468 self .assertEqual (f .actual ('weight' ), 'normal' )
65- self .assertEqual (f .cget ('size' ), sizetype ( 20 ))
69+ self .assertEqual (f .cget ('size' ), self . actual_size (( 'Times' , 20 , 'bold' ) ))
6670
6771 # The new font can be given an explicit name.
6872 f = font .Font (root = self .root , name = 'testfont' , font = ('Times' , 20 ))
6973 self .assertEqual (f .name , 'testfont' )
7074 self .assertIn ('testfont' , font .names (self .root ))
71- self .assertEqual (f .cget ('size' ), sizetype ( 20 ))
75+ self .assertEqual (f .cget ('size' ), self . actual_size (( 'Times' , 20 ) ))
7276 # Reusing the name of an existing font fails.
7377 self .assertRaises (tkinter .TclError , font .Font , root = self .root ,
7478 name = 'testfont' , font = ('Times' , 10 ))
@@ -134,7 +138,7 @@ def test_existing(self):
134138 self .assertEqual (str (f ), 'Times 20 bold' )
135139 self .assertNotIn (f .name , font .names (self .root ))
136140 self .assertEqual (f .actual ('weight' ), 'bold' )
137- self .assertEqual (f .actual ('size' ), sizetype ( 20 ))
141+ self .assertEqual (f .actual ('size' ), self . actual_size (( 'Times' , 20 , 'bold' ) ))
138142 # It can be used as a widget option, with the same effect as the
139143 # description itself (gh-143990).
140144 self .assertEqual (tkinter .Label (self .root , font = f ).cget ('font' ),
0 commit comments