diff -r 601a08fcb507 Lib/idlelib/idle_test/test_configuration.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/idle_test/test_configuration.py Sun Jun 15 11:24:08 2014 +0530 @@ -0,0 +1,103 @@ +"""Unittests to ensure correctness of defualt config files""" +import unittest +from test.support import requires, _is_gui_available +import re +from idlelib.configHandler import idleConf as conf +import tkinter as tk + +class DefaultConfigTest(unittest.TestCase): + + def get_option(self, option, _type='int'): + return conf.defaultCfg[self.cfgtype].Get(self.section, option, _type) + + def test_config_main(self): + get = self.get_option + self.cfgtype = 'main' + + self.section = 'General' + self.assertIn(get('editor-on-startup', 'bool'), (True, False)) + self.assertIn(get('autosave', 'bool'), (True, False)) + self.assertNotEqual(get('print-command-posix', 'str').strip(), '') + self.assertNotEqual(get('print-command-win', 'str').strip(), '') + self.assertIn(get('delete-exitfunc', 'bool'), (True, False)) + + self.section = 'EditorWindow' + self.assertGreater(get('width'), 0) + self.assertGreater(get('height'), 0) + self.assertNotEqual(get('font', 'str').strip(), '') + self.assertGreater(get('font-size'), 0) + self.assertIn(get('font-bold', 'bool'), (True, False)) + + self.section = 'Indent' + self.assertIn(get('use-spaces', 'bool'), (True, False)) + self.assertGreater(get('num-spaces'), 0) + + self.section = 'Theme' + self.assertIn(get('default', 'bool'), (True, False)) + if get('default'): + self.assertNotEqual(get('name', 'str').strip(), '') + + self.section = 'Keys' + self.assertIn(get('default', 'bool'), (True, False)) + if get('default'): + self.assertNotEqual(get('name', 'str').strip(), '') + + self.section = 'History' + self.assertIn(get('cyclic', 'bool'), (True, False)) + + def test_config_highlight(self): + + def is_valid_hex_color(colorcode): + m = re.match(r'^#([0-9a-f]{3,12})$', color, re.IGNORECASE) + return m is not None and len(m.group(1)) % 3 == 0 + + def is_valid_color_name(colorname): + # list of colors which are always present in tkinter + colors = ("white", "black", "red", "green", + "blue", "cyan", "yellow", "magenta") + if colorname in colors: + return True + requires('gui') + try: + return tk.Tk().winfo_rgb(colorname) is not None + except: + return False + + get = self.get_option + self.cfgtype = 'highlight' + sections = conf.GetSectionList('default', self.cfgtype) + + for s in sections: + options = conf.defaultCfg[self.cfgtype].GetOptionList(s) + self.section = s + for option in options: + color = get(option, 'str') + if color.startswith('#'): + self.assertTrue(is_valid_hex_color(color), + "{} in {} in config-highlight.def has an invalid" + "color code {}.".format(option, self.section, color)) + elif _is_gui_available(): + self.assertTrue(is_valid_color_name(color), + "{} in {} in config-highlight.def has an invalid" + "color name {}.".format(option, self.section, color)) + + def test_config_extensions(self): + get = self.get_option + self.cfgtype = 'extensions' + sections = conf.GetSectionList('default', self.cfgtype) + + for s in sections: + options = conf.defaultCfg[self.cfgtype].GetOptionList(s) + self.section = s + for option in options: + if option is 'enable': + self.assertIn(get(option, 'bool'), (True, False)) + if 'bindings' in self.section.lower(): + pass # todo - validate key binding. + else: + self.assertNotEqual(get(option, 'str').strip(), '', + "{} in {} in config-extensions.def has an empty " + "config value.".format(option, self.section)) + +if __name__ == '__main__': + unittest.main(verbosity=2)