Skip to content

Commit 6d13b22

Browse files
csabellaterryjreedy
authored andcommitted
bpo-30779: IDLE: fix changes.delete_section calls in configdialog (#2667)
Also improve test of config.ConfigChanges.delete_section. Original patch by Cheryl Sabella.
1 parent f523255 commit 6d13b22

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

Lib/idlelib/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,8 @@ class ConfigChanges(dict):
794794
add_option: Add option and value to changes.
795795
save_option: Save option and value to config parser.
796796
save_all: Save all the changes to the config parser and file.
797-
delete_section: Delete section if it exists.
797+
delete_section: If section exists,
798+
delete from changes, userCfg, and file.
798799
clear: Clear all changes by clearing each page.
799800
"""
800801
def __init__(self):

Lib/idlelib/configdialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ def delete_custom_keys(self):
839839
return
840840
self.deactivate_current_config()
841841
# Remove key set from changes, config, and file.
842-
changes.remove(keyset_name)
842+
changes.delete_section('keys', keyset_name)
843843
# Reload user key set list.
844844
item_list = idleConf.GetSectionList('user', 'keys')
845845
item_list.sort()
@@ -873,7 +873,7 @@ def delete_custom_theme(self):
873873
return
874874
self.deactivate_current_config()
875875
# Remove theme from changes, config, and file.
876-
changes.delete_section('highlight')
876+
changes.delete_section('highlight', theme_name)
877877
# Reload user theme list.
878878
item_list = idleConf.GetSectionList('user', 'highlight')
879879
item_list.sort()

Lib/idlelib/idle_test/test_config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def test_save_added(self):
188188
userkeys.remove_section('Ksec')
189189

190190
def test_save_help(self):
191+
# Any change to HelpFiles overwrites entire section.
191192
changes = self.changes
192193
changes.save_option('main', 'HelpFiles', 'IDLE', 'idledoc')
193194
changes.add_option('main', 'HelpFiles', 'ELDI', 'codeldi')
@@ -207,10 +208,12 @@ def test_delete_section(self):
207208
changes.delete_section('main', 'fake') # Test no exception.
208209
self.assertEqual(changes, self.loaded) # Test nothing deleted.
209210
for cfgtype, section in (('main', 'Msec'), ('keys', 'Ksec')):
211+
testcfg[cfgtype].SetOption(section, 'name', 'value')
210212
changes.delete_section(cfgtype, section)
211213
with self.assertRaises(KeyError):
212-
changes[cfgtype][section] # Test section gone.
213-
# TODO Test change to userkeys and maybe save call.
214+
changes[cfgtype][section] # Test section gone from changes
215+
testcfg[cfgtype][section] # and from mock userCfg.
216+
# TODO test for save call.
214217

215218
def test_clear(self):
216219
changes = self.load()

0 commit comments

Comments
 (0)