diff -r 4ddb89661a7f Lib/idlelib/configdialog.py --- a/Lib/idlelib/configdialog.py Tue Oct 25 21:43:41 2016 -0500 +++ b/Lib/idlelib/configdialog.py Mon Oct 31 17:11:09 2016 -0400 @@ -392,28 +392,28 @@ text=' Additional Help Sources ') #frameRun labelRunChoiceTitle = Label(frameRun, text='At Startup') - radioStartupEdit = Radiobutton( + self.radioStartupEdit = Radiobutton( frameRun, variable=self.startupEdit, value=1, - command=self.SetKeysType, text="Open Edit Window") - radioStartupShell = Radiobutton( + text="Open Edit Window") + self.radioStartupShell = Radiobutton( frameRun, variable=self.startupEdit, value=0, - command=self.SetKeysType, text='Open Shell Window') + text='Open Shell Window') #frameSave labelRunSaveTitle = Label(frameSave, text='At Start of Run (F5) ') - radioSaveAsk = Radiobutton( + self.radioSaveAsk = Radiobutton( frameSave, variable=self.autoSave, value=0, - command=self.SetKeysType, text="Prompt to Save") - radioSaveAuto = Radiobutton( + text="Prompt to Save") + self.radioSaveAuto = Radiobutton( frameSave, variable=self.autoSave, value=1, - command=self.SetKeysType, text='No Prompt') + text='No Prompt') #frameWinSize labelWinSizeTitle = Label( frameWinSize, text='Initial Window Size (in characters)') labelWinWidthTitle = Label(frameWinSize, text='Width') - entryWinWidth = Entry( + self.entryWinWidth = Entry( frameWinSize, textvariable=self.winWidth, width=3) labelWinHeightTitle = Label(frameWinSize, text='Height') - entryWinHeight = Entry( + self.entryWinHeight = Entry( frameWinSize, textvariable=self.winHeight, width=3) #frameHelp frameHelpList = Frame(frameHelp) @@ -443,17 +443,17 @@ frameHelp.pack(side=TOP, padx=5, pady=5, expand=TRUE, fill=BOTH) #frameRun labelRunChoiceTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5) - radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.radioStartupShell.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.radioStartupEdit.pack(side=RIGHT, anchor=W, padx=5, pady=5) #frameSave labelRunSaveTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5) - radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.radioSaveAuto.pack(side=RIGHT, anchor=W, padx=5, pady=5) + self.radioSaveAsk.pack(side=RIGHT, anchor=W, padx=5, pady=5) #frameWinSize labelWinSizeTitle.pack(side=LEFT, anchor=W, padx=5, pady=5) - entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5) + self.entryWinHeight.pack(side=RIGHT, anchor=E, padx=10, pady=5) labelWinHeightTitle.pack(side=RIGHT, anchor=E, pady=5) - entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5) + self.entryWinWidth.pack(side=RIGHT, anchor=E, padx=10, pady=5) labelWinWidthTitle.pack(side=RIGHT, anchor=E, pady=5) #frameHelp frameHelpListButtons.pack(side=RIGHT, padx=5, pady=5, fill=Y) diff -r 4ddb89661a7f Lib/idlelib/idle_test/test_configdialog.py --- a/Lib/idlelib/idle_test/test_configdialog.py Tue Oct 25 21:43:41 2016 -0500 +++ b/Lib/idlelib/idle_test/test_configdialog.py Mon Oct 31 17:11:09 2016 -0400 @@ -3,29 +3,122 @@ Coverage: 46% just by creating dialog. The other half is code for working with user customizations. ''' -from idlelib.configdialog import ConfigDialog # always test import +from idlelib.configdialog import ConfigDialog, idleConf # test import from test.support import requires requires('gui') from tkinter import Tk import unittest - -class ConfigDialogTest(unittest.TestCase): - - @classmethod - def setUpClass(cls): - cls.root = Tk() - cls.root.withdraw() +import idlelib.config as config - @classmethod - def tearDownClass(cls): - cls.root.update_idletasks() - cls.root.destroy() - del cls.root +# Tests should not depend on fortuitous user configurations. +# They must not affect actual user .cfg files. +# Use empty parsers with no filename (so cannot be saved). +usercfg = idleConf.userCfg +testcfg = { + 'main': config.IdleUserConfParser(''), + 'highlight': config.IdleUserConfParser(''), + 'keys': config.IdleUserConfParser(''), + 'extensions': config.IdleUserConfParser(''), +} - def test_configdialog(self): - d = ConfigDialog(self.root, 'Test', _utest=True) - d.remove_var_callbacks() +# 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) +def setUpModule(): + global root, configure + idleConf.userCfg = testcfg + root = Tk() + root.withdraw() + configure = TestDialog(root, 'Test', _utest=True) + + +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): + configure.fontName.set('Test Font') + expected = [ + ('main', 'EditorWindow', 'font', 'Test Font'), + ('main', 'EditorWindow', 'font-size', '10'), + ('main', 'EditorWindow', 'font-bold', False)] + self.assertEqual(changes, expected) + changes.clear() + configure.fontSize.set(12) + expected = [ + ('main', 'EditorWindow', 'font', 'Test Font'), + ('main', 'EditorWindow', 'font-size', '12'), + ('main', 'EditorWindow', 'font-bold', False)] + self.assertEqual(changes, expected) + changes.clear() + configure.fontBold.set(True) + expected = [ + ('main', 'EditorWindow', 'font', 'Test Font'), + ('main', 'EditorWindow', 'font-size', '12'), + ('main', 'EditorWindow', 'font-bold', True)] + 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 + if __name__ == '__main__': unittest.main(verbosity=2)