summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-06-09 04:18:54 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-06-09 04:18:54 (GMT)
commitc0ed707b2ff8a2fda48a101c904b4267e1cd7866 (patch)
treef5b60dcee8212cef34e3ebe8a07a4db826bca398 /Lib/tkinter
parentd00407115db3f0ad149f0053bfd40469c4fd0e7c (diff)
downloadcpython-c0ed707b2ff8a2fda48a101c904b4267e1cd7866.zip
cpython-c0ed707b2ff8a2fda48a101c904b4267e1cd7866.tar.gz
cpython-c0ed707b2ff8a2fda48a101c904b4267e1cd7866.tar.bz2
Issue #24408: Added more tkinter.Font tests.
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/test/test_tkinter/test_font.py70
1 files changed, 65 insertions, 5 deletions
diff --git a/Lib/tkinter/test/test_tkinter/test_font.py b/Lib/tkinter/test/test_tkinter/test_font.py
index 09c963e..ba3b9da 100644
--- a/Lib/tkinter/test/test_tkinter/test_font.py
+++ b/Lib/tkinter/test/test_tkinter/test_font.py
@@ -6,14 +6,54 @@ from tkinter.test.support import AbstractTkTest
requires('gui')
+fontname = "TkDefaultFont"
+
class FontTest(AbstractTkTest, unittest.TestCase):
- def test_font_eq(self):
- fontname = "TkDefaultFont"
+ @classmethod
+ def setUpClass(cls):
+ AbstractTkTest.setUpClass()
try:
- f = font.Font(root=self.root, name=fontname, exists=True)
- except tkinter._tkinter.TclError:
- f = font.Font(root=self.root, name=fontname, exists=False)
+ cls.font = font.Font(root=cls.root, name=fontname, exists=True)
+ except tkinter.TclError:
+ 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)
font2 = font.Font(root=self.root, name=fontname, exists=True)
self.assertIsNot(font1, font2)
@@ -21,6 +61,26 @@ class FontTest(AbstractTkTest, unittest.TestCase):
self.assertNotEqual(font1, font1.copy())
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, )
if __name__ == "__main__":