summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/idle_test/test_config.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib/idle_test/test_config.py')
-rw-r--r--Lib/idlelib/idle_test/test_config.py86
1 files changed, 84 insertions, 2 deletions
diff --git a/Lib/idlelib/idle_test/test_config.py b/Lib/idlelib/idle_test/test_config.py
index e678cc6..e157bbb 100644
--- a/Lib/idlelib/idle_test/test_config.py
+++ b/Lib/idlelib/idle_test/test_config.py
@@ -9,12 +9,13 @@ from idlelib import config
# Tests should not depend on fortuitous user configurations.
# They must not affect actual user .cfg files.
-# Replace user parsers with empty parsers that cannot be saved.
+# Replace user parsers with empty parsers that cannot be saved
+# due to getting '' as the filename when created.
idleConf = config.idleConf
usercfg = idleConf.userCfg
testcfg = {}
-usermain = testcfg['main'] = config.IdleUserConfParser('') # filename
+usermain = testcfg['main'] = config.IdleUserConfParser('')
userhigh = testcfg['highlight'] = config.IdleUserConfParser('')
userkeys = testcfg['keys'] = config.IdleUserConfParser('')
@@ -136,6 +137,87 @@ class CurrentColorKeysTest(unittest.TestCase):
userkeys.remove_section('Custom Keys')
+class ChangesTest(unittest.TestCase):
+
+ empty = {'main':{}, 'highlight':{}, 'keys':{}, 'extensions':{}}
+
+ def load(self): # Test_add_option verifies that this works.
+ changes = self.changes
+ changes.add_option('main', 'Msec', 'mitem', 'mval')
+ changes.add_option('highlight', 'Hsec', 'hitem', 'hval')
+ changes.add_option('keys', 'Ksec', 'kitem', 'kval')
+ return changes
+
+ loaded = {'main': {'Msec': {'mitem': 'mval'}},
+ 'highlight': {'Hsec': {'hitem': 'hval'}},
+ 'keys': {'Ksec': {'kitem':'kval'}},
+ 'extensions': {}}
+
+ def setUp(self):
+ self.changes = config.ConfigChanges()
+
+ def test_init(self):
+ self.assertEqual(self.changes, self.empty)
+
+ def test_add_option(self):
+ changes = self.load()
+ self.assertEqual(changes, self.loaded)
+ changes.add_option('main', 'Msec', 'mitem', 'mval')
+ self.assertEqual(changes, self.loaded)
+
+ def test_save_option(self): # Static function does not touch changes.
+ save_option = self.changes.save_option
+ self.assertTrue(save_option('main', 'Indent', 'what', '0'))
+ self.assertFalse(save_option('main', 'Indent', 'what', '0'))
+ self.assertEqual(usermain['Indent']['what'], '0')
+
+ self.assertTrue(save_option('main', 'Indent', 'use-spaces', '0'))
+ self.assertEqual(usermain['Indent']['use-spaces'], '0')
+ self.assertTrue(save_option('main', 'Indent', 'use-spaces', '1'))
+ self.assertFalse(usermain.has_option('Indent', 'use-spaces'))
+ usermain.remove_section('Indent')
+
+ def test_save_added(self):
+ changes = self.load()
+ changes.save_all()
+ self.assertEqual(usermain['Msec']['mitem'], 'mval')
+ self.assertEqual(userhigh['Hsec']['hitem'], 'hval')
+ self.assertEqual(userkeys['Ksec']['kitem'], 'kval')
+ usermain.remove_section('Msec')
+ userhigh.remove_section('Hsec')
+ userkeys.remove_section('Ksec')
+
+ def test_save_help(self):
+ changes = self.changes
+ changes.save_option('main', 'HelpFiles', 'IDLE', 'idledoc')
+ changes.add_option('main', 'HelpFiles', 'ELDI', 'codeldi')
+ changes.save_all()
+ self.assertFalse(usermain.has_option('HelpFiles', 'IDLE'))
+ self.assertTrue(usermain.has_option('HelpFiles', 'ELDI'))
+
+ def test_save_default(self): # Cover 2nd and 3rd false branches.
+ changes = self.changes
+ changes.add_option('main', 'Indent', 'use-spaces', '1')
+ # save_option returns False; cfg_type_changed remains False.
+
+ # TODO: test that save_all calls usercfg Saves.
+
+ def test_delete_section(self):
+ changes = self.load()
+ changes.delete_section('main', 'fake') # Test no exception.
+ self.assertEqual(changes, self.loaded) # Test nothing deleted.
+ for cfgtype, section in (('main', 'Msec'), ('keys', 'Ksec')):
+ changes.delete_section(cfgtype, section)
+ with self.assertRaises(KeyError):
+ changes[cfgtype][section] # Test section gone.
+ # TODO Test change to userkeys and maybe save call.
+
+ def test_clear(self):
+ changes = self.load()
+ changes.clear()
+ self.assertEqual(changes, self.empty)
+
+
class WarningTest(unittest.TestCase):
def test_warn(self):