| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | """Test idlelib.configdialog.
 | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | Half the class creates dialog, half works with user customizations. | 
					
						
							|  |  |  | Coverage: 46% just by creating dialog, 56% with current tests. | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  | from idlelib.configdialog import ConfigDialog, idleConf  # test import | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | from test.support import requires | 
					
						
							| 
									
										
										
										
											2016-06-04 15:54:44 -04:00
										 |  |  | requires('gui') | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | from tkinter import Tk | 
					
						
							| 
									
										
										
										
											2016-06-04 15:54:44 -04:00
										 |  |  | import unittest | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | import idlelib.config as config | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | # Tests should not depend on fortuitous user configurations. | 
					
						
							|  |  |  | # They must not affect actual user .cfg files. | 
					
						
							|  |  |  | # Use solution from test_config: empty parsers with no filename. | 
					
						
							|  |  |  | usercfg = idleConf.userCfg | 
					
						
							|  |  |  | testcfg = { | 
					
						
							|  |  |  |     'main': config.IdleUserConfParser(''), | 
					
						
							|  |  |  |     'highlight': config.IdleUserConfParser(''), | 
					
						
							|  |  |  |     'keys': config.IdleUserConfParser(''), | 
					
						
							|  |  |  |     'extensions': config.IdleUserConfParser(''), | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | # ConfigDialog.changedItems is a 3-level hierarchical dictionary of | 
					
						
							|  |  |  | # pending changes that mirrors the multilevel user config dict. | 
					
						
							|  |  |  | # For testing, record args in a list for comparison with expected. | 
					
						
							|  |  |  | changes = [] | 
					
						
							|  |  |  | class TestDialog(ConfigDialog): | 
					
						
							|  |  |  |     def AddChangedItem(self, *args): | 
					
						
							|  |  |  |         changes.append(args) | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | def setUpModule(): | 
					
						
							|  |  |  |     global root, configure | 
					
						
							|  |  |  |     idleConf.userCfg = testcfg | 
					
						
							|  |  |  |     root = Tk() | 
					
						
							|  |  |  |     root.withdraw() | 
					
						
							|  |  |  |     configure = TestDialog(root, 'Test', _utest=True) | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | def tearDownModule(): | 
					
						
							|  |  |  |     global root, configure | 
					
						
							|  |  |  |     idleConf.userCfg = testcfg | 
					
						
							|  |  |  |     configure.remove_var_callbacks() | 
					
						
							|  |  |  |     del configure | 
					
						
							|  |  |  |     root.update_idletasks() | 
					
						
							|  |  |  |     root.destroy() | 
					
						
							|  |  |  |     del root | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FontTabTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_font(self): | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |         # Set values guaranteed not to be defaults. | 
					
						
							|  |  |  |         dfont = idleConf.GetFont(root, 'main', 'EditorWindow') | 
					
						
							|  |  |  |         dsize = str(dfont[1]) | 
					
						
							|  |  |  |         dbold = dfont[2] == 'bold' | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         configure.fontName.set('Test Font') | 
					
						
							|  |  |  |         expected = [ | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font', 'Test Font'), | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |             ('main', 'EditorWindow', 'font-size', dsize), | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font-bold', dbold)] | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         self.assertEqual(changes, expected) | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |         configure.fontSize.set(20) | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         expected = [ | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font', 'Test Font'), | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |             ('main', 'EditorWindow', 'font-size', '20'), | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font-bold', dbold)] | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         self.assertEqual(changes, expected) | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |         configure.fontBold.set(not dbold) | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         expected = [ | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font', 'Test Font'), | 
					
						
							| 
									
										
										
										
											2016-11-07 23:14:53 -05:00
										 |  |  |             ('main', 'EditorWindow', 'font-size', '20'), | 
					
						
							|  |  |  |             ('main', 'EditorWindow', 'font-bold', not dbold)] | 
					
						
							| 
									
										
										
										
											2016-11-07 17:15:01 -05:00
										 |  |  |         self.assertEqual(changes, expected) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #def test_sample(self): pass  # TODO | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_tabspace(self): | 
					
						
							|  |  |  |         configure.spaceNum.set(6) | 
					
						
							|  |  |  |         self.assertEqual(changes, [('main', 'Indent', 'num-spaces', 6)]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HighlightTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #def test_colorchoose(self): pass  # TODO | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class KeysTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class GeneralTest(unittest.TestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_startup(self): | 
					
						
							|  |  |  |         configure.radioStartupEdit.invoke() | 
					
						
							|  |  |  |         self.assertEqual(changes, | 
					
						
							|  |  |  |                          [('main', 'General', 'editor-on-startup', 1)]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_autosave(self): | 
					
						
							|  |  |  |         configure.radioSaveAuto.invoke() | 
					
						
							|  |  |  |         self.assertEqual(changes, [('main', 'General', 'autosave', 1)]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_editor_size(self): | 
					
						
							|  |  |  |         configure.entryWinHeight.insert(0, '1') | 
					
						
							|  |  |  |         self.assertEqual(changes, [('main', 'EditorWindow', 'height', '140')]) | 
					
						
							|  |  |  |         changes.clear() | 
					
						
							|  |  |  |         configure.entryWinWidth.insert(0, '1') | 
					
						
							|  |  |  |         self.assertEqual(changes, [('main', 'EditorWindow', 'width', '180')]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     #def test_help_sources(self): pass  # TODO | 
					
						
							| 
									
										
										
										
											2014-07-14 23:07:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     unittest.main(verbosity=2) |