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