summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib/config.py
diff options
context:
space:
mode:
authorLouie Lu <git@louie.lu>2017-07-12 18:05:32 (GMT)
committerterryjreedy <tjreedy@udel.edu>2017-07-12 18:05:32 (GMT)
commit50c9435c9b73b39fcf79cc3e58edc58bb943d0ed (patch)
tree19f695e2fb995e613378bf7fee064cff01c4d6f9 /Lib/idlelib/config.py
parentd1cc037d1442cc35d1b194ec8e50901514360949 (diff)
downloadcpython-50c9435c9b73b39fcf79cc3e58edc58bb943d0ed.zip
cpython-50c9435c9b73b39fcf79cc3e58edc58bb943d0ed.tar.gz
cpython-50c9435c9b73b39fcf79cc3e58edc58bb943d0ed.tar.bz2
bpo-30899: Add unittests, 100% coverage, for IDLE's two ConfigParser subclasses. (#2662)
Patch by Louie Lu.
Diffstat (limited to 'Lib/idlelib/config.py')
-rw-r--r--Lib/idlelib/config.py57
1 files changed, 31 insertions, 26 deletions
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py
index bbb3e3c..4cf4427 100644
--- a/Lib/idlelib/config.py
+++ b/Lib/idlelib/config.py
@@ -81,31 +81,6 @@ class IdleUserConfParser(IdleConfParser):
IdleConfigParser specialised for user configuration handling.
"""
- def AddSection(self, section):
- "If section doesn't exist, add it."
- if not self.has_section(section):
- self.add_section(section)
-
- def RemoveEmptySections(self):
- "Remove any sections that have no options."
- for section in self.sections():
- if not self.GetOptionList(section):
- self.remove_section(section)
-
- def IsEmpty(self):
- "Return True if no sections after removing empty sections."
- self.RemoveEmptySections()
- return not self.sections()
-
- def RemoveOption(self, section, option):
- """Return True if option is removed from section, else False.
-
- False if either section does not exist or did not have option.
- """
- if self.has_section(section):
- return self.remove_option(section, option)
- return False
-
def SetOption(self, section, option, value):
"""Return True if option is added or changed to value, else False.
@@ -123,6 +98,31 @@ class IdleUserConfParser(IdleConfParser):
self.set(section, option, value)
return True
+ def RemoveOption(self, section, option):
+ """Return True if option is removed from section, else False.
+
+ False if either section does not exist or did not have option.
+ """
+ if self.has_section(section):
+ return self.remove_option(section, option)
+ return False
+
+ def AddSection(self, section):
+ "If section doesn't exist, add it."
+ if not self.has_section(section):
+ self.add_section(section)
+
+ def RemoveEmptySections(self):
+ "Remove any sections that have no options."
+ for section in self.sections():
+ if not self.GetOptionList(section):
+ self.remove_section(section)
+
+ def IsEmpty(self):
+ "Return True if no sections after removing empty sections."
+ self.RemoveEmptySections()
+ return not self.sections()
+
def RemoveFile(self):
"Remove user config file self.file from disk if it exists."
if os.path.exists(self.file):
@@ -829,9 +829,12 @@ class ConfigChanges(dict):
def save_all(self):
"""Save configuration changes to the user config file.
- Then clear self in preparation for additional changes.
+ Clear self in preparation for additional changes.
+ Return changed for testing.
"""
idleConf.userCfg['main'].Save()
+
+ changed = False
for config_type in self:
cfg_type_changed = False
page = self[config_type]
@@ -844,12 +847,14 @@ class ConfigChanges(dict):
cfg_type_changed = True
if cfg_type_changed:
idleConf.userCfg[config_type].Save()
+ changed = True
for config_type in ['keys', 'highlight']:
# Save these even if unchanged!
idleConf.userCfg[config_type].Save()
self.clear()
# ConfigDialog caller must add the following call
# self.save_all_changed_extensions() # Uses a different mechanism.
+ return changed
def delete_section(self, config_type, section):
"""Delete a section from self, userCfg, and file.