diff -r a98fd4eeed40 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 Wed Jun 11 19:36:57 2014 +0530 @@ -0,0 +1,96 @@ +"""Unittests to ensure correctness of defualt config files""" +import unittest +from idlelib.configHandler import idleConf + + +class DefaultConfigTest(unittest.TestCase): + + def get_option(self, option, type=int): + option = idleConf.defaultCfg[self.cfgtype].Get(self.section, option) + return type(option) + + def test_config_main(self): + get = self.get_option + self.cfgtype = 'main' + + self.section = 'General' + self.assertIn(get('editor-on-startup'), (0, 1)) + self.assertIn(get('autosave'), (0, 1)) + self.assertNotEqual(get('print-command-posix', str.strip), '') + self.assertNotEqual(get('print-command-win', str.strip), '') + self.assertIn(get('delete-exitfunc'), (0, 1)) + + 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'), (0, 1)) + + self.section = 'Indent' + self.assertIn(get('use-spaces'), (0, 1)) + self.assertGreater(get('num-spaces'), 0) + + self.section = 'Theme' + self.assertIn(get('default'), (0, 1)) + if get('default'): + self.assertIn('IDLE', get('name', str)) + + self.section = 'Keys' + self.assertIn(get('default'), (0, 1)) + if get('default'): + self.assertIn('IDLE', get('name', str)) + + self.section = 'History' + self.assertIn(get('cyclic'), (0, 1)) + + def test_config_highlight(self): + + def is_valid_hex_color(color): + """ + color - six digit hex color code + + color is valid if it is between 0 and 256**3(=16777216) + i.e. between 0x000000 and 0xffffff. + """ + if len(color) is not 6: + return False + return 0 <= int(color, 16) < 16777216 + + get = self.get_option + self.cfgtype = 'highlight' + sections = idleConf.GetSectionList('default', self.cfgtype) + # expand the below tuple as neceassry + colors = ('black', 'blue', 'red', 'gray', 'white') + + for s in sections: + options = idleConf.defaultCfg[self.cfgtype].GetOptionList(s) + self.section = s + for o in options: + color = get(o, str) + if color in colors: + continue + self.assertTrue(is_valid_hex_color(color[1:]), # strip '#' + "{} in {} in config-highlight.def has an invalid" + " color code for {}.".format(o, self.section, color)) + + def test_config_extensions(self): + get = self.get_option + self.cfgtype = 'extensions' + sections = idleConf.GetSectionList('default', self.cfgtype) + + for s in sections: + options = idleConf.defaultCfg[self.cfgtype].GetOptionList(s) + self.section = s + for o in options: + if o is 'enable': + self.assertIn(get(o), (0, 1)) + if 'bindings' in self.section.lower(): + pass # todo - validate key binding. + else: + self.assertNotEqual(get(o, str.strip), '', + "{} in {} in config-extensions.def has an empty " + "config value.".format(o, self.section)) + +if __name__ == '__main__': + unittest.main(verbosity=2)