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

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

#countcontent
1n/a"""Test idlelib.configdialog.
2n/a
3n/aHalf the class creates dialog, half works with user customizations.
4n/aCoverage: 46% just by creating dialog, 56% with current tests.
5n/a"""
6n/afrom idlelib.configdialog import ConfigDialog, idleConf # test import
7n/afrom test.support import requires
8n/arequires('gui')
9n/afrom tkinter import Tk
10n/aimport unittest
11n/aimport idlelib.config as config
12n/a
13n/a# Tests should not depend on fortuitous user configurations.
14n/a# They must not affect actual user .cfg files.
15n/a# Use solution from test_config: empty parsers with no filename.
16n/ausercfg = idleConf.userCfg
17n/atestcfg = {
18n/a 'main': config.IdleUserConfParser(''),
19n/a 'highlight': config.IdleUserConfParser(''),
20n/a 'keys': config.IdleUserConfParser(''),
21n/a 'extensions': config.IdleUserConfParser(''),
22n/a}
23n/a
24n/a# ConfigDialog.changedItems is a 3-level hierarchical dictionary of
25n/a# pending changes that mirrors the multilevel user config dict.
26n/a# For testing, record args in a list for comparison with expected.
27n/achanges = []
28n/aclass TestDialog(ConfigDialog):
29n/a def AddChangedItem(self, *args):
30n/a changes.append(args)
31n/a
32n/adef setUpModule():
33n/a global root, configure
34n/a idleConf.userCfg = testcfg
35n/a root = Tk()
36n/a root.withdraw()
37n/a configure = TestDialog(root, 'Test', _utest=True)
38n/a
39n/a
40n/adef tearDownModule():
41n/a global root, configure
42n/a idleConf.userCfg = testcfg
43n/a configure.remove_var_callbacks()
44n/a del configure
45n/a root.update_idletasks()
46n/a root.destroy()
47n/a del root
48n/a
49n/a
50n/aclass FontTabTest(unittest.TestCase):
51n/a
52n/a
53n/a def setUp(self):
54n/a changes.clear()
55n/a
56n/a def test_font(self):
57n/a # Set values guaranteed not to be defaults.
58n/a dfont = idleConf.GetFont(root, 'main', 'EditorWindow')
59n/a dsize = str(dfont[1])
60n/a dbold = dfont[2] == 'bold'
61n/a configure.fontName.set('Test Font')
62n/a expected = [
63n/a ('main', 'EditorWindow', 'font', 'Test Font'),
64n/a ('main', 'EditorWindow', 'font-size', dsize),
65n/a ('main', 'EditorWindow', 'font-bold', dbold)]
66n/a self.assertEqual(changes, expected)
67n/a changes.clear()
68n/a configure.fontSize.set(20)
69n/a expected = [
70n/a ('main', 'EditorWindow', 'font', 'Test Font'),
71n/a ('main', 'EditorWindow', 'font-size', '20'),
72n/a ('main', 'EditorWindow', 'font-bold', dbold)]
73n/a self.assertEqual(changes, expected)
74n/a changes.clear()
75n/a configure.fontBold.set(not dbold)
76n/a expected = [
77n/a ('main', 'EditorWindow', 'font', 'Test Font'),
78n/a ('main', 'EditorWindow', 'font-size', '20'),
79n/a ('main', 'EditorWindow', 'font-bold', not dbold)]
80n/a self.assertEqual(changes, expected)
81n/a
82n/a #def test_sample(self): pass # TODO
83n/a
84n/a def test_tabspace(self):
85n/a configure.spaceNum.set(6)
86n/a self.assertEqual(changes, [('main', 'Indent', 'num-spaces', 6)])
87n/a
88n/a
89n/aclass HighlightTest(unittest.TestCase):
90n/a
91n/a def setUp(self):
92n/a changes.clear()
93n/a
94n/a #def test_colorchoose(self): pass # TODO
95n/a
96n/a
97n/aclass KeysTest(unittest.TestCase):
98n/a
99n/a def setUp(self):
100n/a changes.clear()
101n/a
102n/a
103n/aclass GeneralTest(unittest.TestCase):
104n/a
105n/a def setUp(self):
106n/a changes.clear()
107n/a
108n/a def test_startup(self):
109n/a configure.radioStartupEdit.invoke()
110n/a self.assertEqual(changes,
111n/a [('main', 'General', 'editor-on-startup', 1)])
112n/a
113n/a def test_autosave(self):
114n/a configure.radioSaveAuto.invoke()
115n/a self.assertEqual(changes, [('main', 'General', 'autosave', 1)])
116n/a
117n/a def test_editor_size(self):
118n/a configure.entryWinHeight.insert(0, '1')
119n/a self.assertEqual(changes, [('main', 'EditorWindow', 'height', '140')])
120n/a changes.clear()
121n/a configure.entryWinWidth.insert(0, '1')
122n/a self.assertEqual(changes, [('main', 'EditorWindow', 'width', '180')])
123n/a
124n/a #def test_help_sources(self): pass # TODO
125n/a
126n/a
127n/aif __name__ == '__main__':
128n/a unittest.main(verbosity=2)