ยปCore Development>Code coverage>Lib/tkinter/test/test_tkinter/test_font.py

Python code coverage for Lib/tkinter/test/test_tkinter/test_font.py

#countcontent
1n/aimport unittest
2n/aimport tkinter
3n/afrom tkinter import font
4n/afrom test.support import requires, run_unittest
5n/afrom tkinter.test.support import AbstractTkTest
6n/a
7n/arequires('gui')
8n/a
9n/afontname = "TkDefaultFont"
10n/a
11n/aclass FontTest(AbstractTkTest, unittest.TestCase):
12n/a
13n/a @classmethod
14n/a def setUpClass(cls):
15n/a AbstractTkTest.setUpClass.__func__(cls)
16n/a try:
17n/a cls.font = font.Font(root=cls.root, name=fontname, exists=True)
18n/a except tkinter.TclError:
19n/a cls.font = font.Font(root=cls.root, name=fontname, exists=False)
20n/a
21n/a def test_configure(self):
22n/a options = self.font.configure()
23n/a self.assertGreaterEqual(set(options),
24n/a {'family', 'size', 'weight', 'slant', 'underline', 'overstrike'})
25n/a for key in options:
26n/a self.assertEqual(self.font.cget(key), options[key])
27n/a self.assertEqual(self.font[key], options[key])
28n/a for key in 'family', 'weight', 'slant':
29n/a self.assertIsInstance(options[key], str)
30n/a self.assertIsInstance(self.font.cget(key), str)
31n/a self.assertIsInstance(self.font[key], str)
32n/a sizetype = int if self.wantobjects else str
33n/a for key in 'size', 'underline', 'overstrike':
34n/a self.assertIsInstance(options[key], sizetype)
35n/a self.assertIsInstance(self.font.cget(key), sizetype)
36n/a self.assertIsInstance(self.font[key], sizetype)
37n/a
38n/a def test_actual(self):
39n/a options = self.font.actual()
40n/a self.assertGreaterEqual(set(options),
41n/a {'family', 'size', 'weight', 'slant', 'underline', 'overstrike'})
42n/a for key in options:
43n/a self.assertEqual(self.font.actual(key), options[key])
44n/a for key in 'family', 'weight', 'slant':
45n/a self.assertIsInstance(options[key], str)
46n/a self.assertIsInstance(self.font.actual(key), str)
47n/a sizetype = int if self.wantobjects else str
48n/a for key in 'size', 'underline', 'overstrike':
49n/a self.assertIsInstance(options[key], sizetype)
50n/a self.assertIsInstance(self.font.actual(key), sizetype)
51n/a
52n/a def test_name(self):
53n/a self.assertEqual(self.font.name, fontname)
54n/a self.assertEqual(str(self.font), fontname)
55n/a
56n/a def test_eq(self):
57n/a font1 = font.Font(root=self.root, name=fontname, exists=True)
58n/a font2 = font.Font(root=self.root, name=fontname, exists=True)
59n/a self.assertIsNot(font1, font2)
60n/a self.assertEqual(font1, font2)
61n/a self.assertNotEqual(font1, font1.copy())
62n/a self.assertNotEqual(font1, 0)
63n/a
64n/a def test_measure(self):
65n/a self.assertIsInstance(self.font.measure('abc'), int)
66n/a
67n/a def test_metrics(self):
68n/a metrics = self.font.metrics()
69n/a self.assertGreaterEqual(set(metrics),
70n/a {'ascent', 'descent', 'linespace', 'fixed'})
71n/a for key in metrics:
72n/a self.assertEqual(self.font.metrics(key), metrics[key])
73n/a self.assertIsInstance(metrics[key], int)
74n/a self.assertIsInstance(self.font.metrics(key), int)
75n/a
76n/a def test_families(self):
77n/a families = font.families(self.root)
78n/a self.assertIsInstance(families, tuple)
79n/a self.assertTrue(families)
80n/a for family in families:
81n/a self.assertIsInstance(family, str)
82n/a self.assertTrue(family)
83n/a
84n/a def test_names(self):
85n/a names = font.names(self.root)
86n/a self.assertIsInstance(names, tuple)
87n/a self.assertTrue(names)
88n/a for name in names:
89n/a self.assertIsInstance(name, str)
90n/a self.assertTrue(name)
91n/a self.assertIn(fontname, names)
92n/a
93n/atests_gui = (FontTest, )
94n/a
95n/aif __name__ == "__main__":
96n/a run_unittest(*tests_gui)