mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Issue #24408: Added more tkinter.Font tests.
This commit is contained in:
		
						commit
						fabdc827a5
					
				
					 1 changed files with 65 additions and 5 deletions
				
			
		| 
						 | 
					@ -6,14 +6,54 @@ from tkinter.test.support import AbstractTkTest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
requires('gui')
 | 
					requires('gui')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fontname = "TkDefaultFont"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FontTest(AbstractTkTest, unittest.TestCase):
 | 
					class FontTest(AbstractTkTest, unittest.TestCase):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_font_eq(self):
 | 
					    @classmethod
 | 
				
			||||||
        fontname = "TkDefaultFont"
 | 
					    def setUpClass(cls):
 | 
				
			||||||
 | 
					        AbstractTkTest.setUpClass()
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            f = font.Font(root=self.root, name=fontname, exists=True)
 | 
					            cls.font = font.Font(root=cls.root, name=fontname, exists=True)
 | 
				
			||||||
        except tkinter._tkinter.TclError:
 | 
					        except tkinter.TclError:
 | 
				
			||||||
            f = font.Font(root=self.root, name=fontname, exists=False)
 | 
					            cls.font = font.Font(root=cls.root, name=fontname, exists=False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_configure(self):
 | 
				
			||||||
 | 
					        options = self.font.configure()
 | 
				
			||||||
 | 
					        self.assertGreaterEqual(set(options),
 | 
				
			||||||
 | 
					            {'family', 'size', 'weight', 'slant', 'underline', 'overstrike'})
 | 
				
			||||||
 | 
					        for key in options:
 | 
				
			||||||
 | 
					            self.assertEqual(self.font.cget(key), options[key])
 | 
				
			||||||
 | 
					            self.assertEqual(self.font[key], options[key])
 | 
				
			||||||
 | 
					        for key in 'family', 'weight', 'slant':
 | 
				
			||||||
 | 
					            self.assertIsInstance(options[key], str)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font.cget(key), str)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font[key], str)
 | 
				
			||||||
 | 
					        sizetype = int if self.wantobjects else str
 | 
				
			||||||
 | 
					        for key in 'size', 'underline', 'overstrike':
 | 
				
			||||||
 | 
					            self.assertIsInstance(options[key], sizetype)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font.cget(key), sizetype)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font[key], sizetype)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_actual(self):
 | 
				
			||||||
 | 
					        options = self.font.actual()
 | 
				
			||||||
 | 
					        self.assertGreaterEqual(set(options),
 | 
				
			||||||
 | 
					            {'family', 'size', 'weight', 'slant', 'underline', 'overstrike'})
 | 
				
			||||||
 | 
					        for key in options:
 | 
				
			||||||
 | 
					            self.assertEqual(self.font.actual(key), options[key])
 | 
				
			||||||
 | 
					        for key in 'family', 'weight', 'slant':
 | 
				
			||||||
 | 
					            self.assertIsInstance(options[key], str)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font.actual(key), str)
 | 
				
			||||||
 | 
					        sizetype = int if self.wantobjects else str
 | 
				
			||||||
 | 
					        for key in 'size', 'underline', 'overstrike':
 | 
				
			||||||
 | 
					            self.assertIsInstance(options[key], sizetype)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font.actual(key), sizetype)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_name(self):
 | 
				
			||||||
 | 
					        self.assertEqual(self.font.name, fontname)
 | 
				
			||||||
 | 
					        self.assertEqual(str(self.font), fontname)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_eq(self):
 | 
				
			||||||
        font1 = font.Font(root=self.root, name=fontname, exists=True)
 | 
					        font1 = font.Font(root=self.root, name=fontname, exists=True)
 | 
				
			||||||
        font2 = font.Font(root=self.root, name=fontname, exists=True)
 | 
					        font2 = font.Font(root=self.root, name=fontname, exists=True)
 | 
				
			||||||
        self.assertIsNot(font1, font2)
 | 
					        self.assertIsNot(font1, font2)
 | 
				
			||||||
| 
						 | 
					@ -21,6 +61,26 @@ class FontTest(AbstractTkTest, unittest.TestCase):
 | 
				
			||||||
        self.assertNotEqual(font1, font1.copy())
 | 
					        self.assertNotEqual(font1, font1.copy())
 | 
				
			||||||
        self.assertNotEqual(font1, 0)
 | 
					        self.assertNotEqual(font1, 0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_measure(self):
 | 
				
			||||||
 | 
					        self.assertIsInstance(self.font.measure('abc'), int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_metrics(self):
 | 
				
			||||||
 | 
					        metrics = self.font.metrics()
 | 
				
			||||||
 | 
					        self.assertGreaterEqual(set(metrics),
 | 
				
			||||||
 | 
					            {'ascent', 'descent', 'linespace', 'fixed'})
 | 
				
			||||||
 | 
					        for key in metrics:
 | 
				
			||||||
 | 
					            self.assertEqual(self.font.metrics(key), metrics[key])
 | 
				
			||||||
 | 
					            self.assertIsInstance(metrics[key], int)
 | 
				
			||||||
 | 
					            self.assertIsInstance(self.font.metrics(key), int)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_families(self):
 | 
				
			||||||
 | 
					        families = font.families(self.root)
 | 
				
			||||||
 | 
					        self.assertIn(self.font.actual('family'), families)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_names(self):
 | 
				
			||||||
 | 
					        names = font.names(self.root)
 | 
				
			||||||
 | 
					        self.assertIn(fontname, names)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
tests_gui = (FontTest, )
 | 
					tests_gui = (FontTest, )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue