ยปCore Development>Code coverage>Lib/idlelib/idle_test/test_macosx.py

Python code coverage for Lib/idlelib/idle_test/test_macosx.py

#countcontent
1n/a'''Test idlelib.macosx.py.
2n/a
3n/aCoverage: 71% on Windows.
4n/a'''
5n/afrom idlelib import macosx
6n/afrom test.support import requires
7n/aimport tkinter as tk
8n/aimport unittest
9n/aimport unittest.mock as mock
10n/afrom idlelib.filelist import FileList
11n/a
12n/amactypes = {'carbon', 'cocoa', 'xquartz'}
13n/anontypes = {'other'}
14n/aalltypes = mactypes | nontypes
15n/a
16n/a
17n/aclass InitTktypeTest(unittest.TestCase):
18n/a "Test _init_tk_type."
19n/a
20n/a @classmethod
21n/a def setUpClass(cls):
22n/a requires('gui')
23n/a cls.root = tk.Tk()
24n/a cls.root.withdraw()
25n/a cls.orig_platform = macosx.platform
26n/a
27n/a @classmethod
28n/a def tearDownClass(cls):
29n/a cls.root.update_idletasks()
30n/a cls.root.destroy()
31n/a del cls.root
32n/a macosx.platform = cls.orig_platform
33n/a
34n/a def test_init_sets_tktype(self):
35n/a "Test that _init_tk_type sets _tk_type according to platform."
36n/a for platform, types in ('darwin', alltypes), ('other', nontypes):
37n/a with self.subTest(platform=platform):
38n/a macosx.platform = platform
39n/a macosx._tk_type == None
40n/a macosx._init_tk_type()
41n/a self.assertIn(macosx._tk_type, types)
42n/a
43n/a
44n/aclass IsTypeTkTest(unittest.TestCase):
45n/a "Test each of the four isTypeTk predecates."
46n/a isfuncs = ((macosx.isAquaTk, ('carbon', 'cocoa')),
47n/a (macosx.isCarbonTk, ('carbon')),
48n/a (macosx.isCocoaTk, ('cocoa')),
49n/a (macosx.isXQuartz, ('xquartz')),
50n/a )
51n/a
52n/a @mock.patch('idlelib.macosx._init_tk_type')
53n/a def test_is_calls_init(self, mockinit):
54n/a "Test that each isTypeTk calls _init_tk_type when _tk_type is None."
55n/a macosx._tk_type = None
56n/a for func, whentrue in self.isfuncs:
57n/a with self.subTest(func=func):
58n/a func()
59n/a self.assertTrue(mockinit.called)
60n/a mockinit.reset_mock()
61n/a
62n/a def test_isfuncs(self):
63n/a "Test that each isTypeTk return correct bool."
64n/a for func, whentrue in self.isfuncs:
65n/a for tktype in alltypes:
66n/a with self.subTest(func=func, whentrue=whentrue, tktype=tktype):
67n/a macosx._tk_type = tktype
68n/a (self.assertTrue if tktype in whentrue else self.assertFalse)\
69n/a (func())
70n/a
71n/a
72n/aclass SetupTest(unittest.TestCase):
73n/a "Test setupApp."
74n/a
75n/a @classmethod
76n/a def setUpClass(cls):
77n/a requires('gui')
78n/a cls.root = tk.Tk()
79n/a cls.root.withdraw()
80n/a
81n/a @classmethod
82n/a def tearDownClass(cls):
83n/a cls.root.update_idletasks()
84n/a cls.root.destroy()
85n/a del cls.root
86n/a
87n/a @mock.patch('idlelib.macosx.overrideRootMenu') #27312
88n/a def test_setupapp(self, overrideRootMenu):
89n/a "Call setupApp with each possible graphics type."
90n/a root = self.root
91n/a flist = FileList(root)
92n/a for tktype in alltypes:
93n/a with self.subTest(tktype=tktype):
94n/a macosx._tk_type = tktype
95n/a macosx.setupApp(root, flist)
96n/a if tktype in ('carbon', 'cocoa'):
97n/a self.assertTrue(overrideRootMenu.called)
98n/a overrideRootMenu.reset_mock()
99n/a
100n/a
101n/aif __name__ == '__main__':
102n/a unittest.main(verbosity=2)