Skip to content

Commit f776eb0

Browse files
mlouieluterryjreedy
authored andcommitted
bpo-30917: IDLE: Add config.IdleConf unittests (#2691)
Patch by Louie Lu.
1 parent 5feda33 commit f776eb0

File tree

3 files changed

+454
-18
lines changed

3 files changed

+454
-18
lines changed

Lib/idlelib/config.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import sys
3131

3232
from tkinter.font import Font
33+
import idlelib
3334

3435
class InvalidConfigType(Exception): pass
3536
class InvalidConfigSet(Exception): pass
@@ -159,14 +160,15 @@ class IdleConf:
159160
for config_type in self.config_types:
160161
(user home dir)/.idlerc/config-{config-type}.cfg
161162
"""
162-
def __init__(self):
163+
def __init__(self, _utest=False):
163164
self.config_types = ('main', 'highlight', 'keys', 'extensions')
164165
self.defaultCfg = {}
165166
self.userCfg = {}
166167
self.cfg = {} # TODO use to select userCfg vs defaultCfg
167-
self.CreateConfigHandlers()
168-
self.LoadCfgFiles()
169168

169+
if not _utest:
170+
self.CreateConfigHandlers()
171+
self.LoadCfgFiles()
170172

171173
def CreateConfigHandlers(self):
172174
"Populate default and user config parser dictionaries."
@@ -215,7 +217,8 @@ def GetUserCfgDir(self):
215217
except OSError:
216218
warn = ('\n Warning: unable to create user config directory\n' +
217219
userDir + '\n Check path and permissions.\n Exiting!\n')
218-
print(warn, file=sys.stderr)
220+
if not idlelib.testing:
221+
print(warn, file=sys.stderr)
219222
raise SystemExit
220223
# TODO continue without userDIr instead of exit
221224
return userDir
@@ -463,16 +466,7 @@ def GetExtensions(self, active_only=True,
463466

464467
def RemoveKeyBindNames(self, extnNameList):
465468
"Return extnNameList with keybinding section names removed."
466-
# TODO Easier to return filtered copy with list comp
467-
names = extnNameList
468-
kbNameIndicies = []
469-
for name in names:
470-
if name.endswith(('_bindings', '_cfgBindings')):
471-
kbNameIndicies.append(names.index(name))
472-
kbNameIndicies.sort(reverse=True)
473-
for index in kbNameIndicies: #delete each keybinding section name
474-
del(names[index])
475-
return names
469+
return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
476470

477471
def GetExtnNameForEvent(self, virtualEvent):
478472
"""Return the name of the extension binding virtualEvent, or None.

0 commit comments

Comments
 (0)