@@ -21,6 +21,7 @@ def setUpClass(cls):
2121 cls .font = font .Font (root = cls .root , name = fontname , exists = False )
2222
2323 def test_configure (self ):
24+ self .assertEqual (self .font .config , self .font .configure )
2425 options = self .font .configure ()
2526 self .assertGreaterEqual (set (options ),
2627 {'family' , 'size' , 'weight' , 'slant' , 'underline' , 'overstrike' })
@@ -36,6 +37,26 @@ def test_configure(self):
3637 self .assertIsInstance (options [key ], sizetype )
3738 self .assertIsInstance (self .font .cget (key ), sizetype )
3839 self .assertIsInstance (self .font [key ], sizetype )
40+ self .assertRaisesRegex (tkinter .TclError , 'bad option "-spam"' ,
41+ self .font .cget , 'spam' )
42+ self .assertRaisesRegex (tkinter .TclError , 'bad option "-spam"' ,
43+ self .font .configure , spam = 'x' )
44+ self .assertRaises (TypeError , self .font .cget )
45+ self .assertRaises (TypeError , self .font .cget , 'size' , 'weight' )
46+
47+ def test_copy (self ):
48+ f = font .Font (root = self .root , family = 'Times' , size = 10 , weight = 'bold' )
49+ copied = f .copy ()
50+ self .assertIsInstance (copied , font .Font )
51+ self .assertIsNot (copied , f )
52+ self .assertNotEqual (copied .name , f .name )
53+ self .assertEqual (copied .actual (), f .actual ())
54+ # The copy is independent of the original.
55+ sizetype = int if self .wantobjects else str
56+ copied .configure (size = 20 )
57+ self .assertEqual (f .cget ('size' ), sizetype (10 ))
58+ self .assertEqual (copied .cget ('size' ), sizetype (20 ))
59+ self .assertRaises (TypeError , f .copy , 'x' )
3960
4061 def test_unicode_family (self ):
4162 family = 'MS \u30b4 \u30b7 \u30c3 \u30af '
@@ -60,6 +81,9 @@ def test_actual(self):
6081 for key in 'size' , 'underline' , 'overstrike' :
6182 self .assertIsInstance (options [key ], sizetype )
6283 self .assertIsInstance (self .font .actual (key ), sizetype )
84+ self .assertRaisesRegex (tkinter .TclError , 'bad option "-spam"' ,
85+ self .font .actual , 'spam' )
86+ self .assertRaises (TypeError , self .font .actual , 'size' , 'weight' , 'slant' )
6387
6488 def test_name (self ):
6589 self .assertEqual (self .font .name , fontname )
@@ -83,15 +107,24 @@ def test_equality(self):
83107
84108 def test_measure (self ):
85109 self .assertIsInstance (self .font .measure ('abc' ), int )
110+ self .assertEqual (self .font .measure ('' ), 0 )
111+ self .assertIsInstance (
112+ self .font .measure ('abc' , displayof = self .root ), int )
113+ self .assertRaises (TypeError , self .font .measure )
114+ self .assertRaises (TypeError , self .font .measure , 'a' , 'b' , 'c' )
86115
87116 def test_metrics (self ):
88117 metrics = self .font .metrics ()
89118 self .assertGreaterEqual (set (metrics ),
90119 {'ascent' , 'descent' , 'linespace' , 'fixed' })
91120 for key in metrics :
92121 self .assertEqual (self .font .metrics (key ), metrics [key ])
122+ self .assertEqual (self .font .metrics (key , displayof = self .root ),
123+ metrics [key ])
93124 self .assertIsInstance (metrics [key ], int )
94125 self .assertIsInstance (self .font .metrics (key ), int )
126+ self .assertRaisesRegex (tkinter .TclError , 'bad metric "-spam"' ,
127+ self .font .metrics , 'spam' )
95128
96129 def test_families (self ):
97130 families = font .families (self .root )
0 commit comments