summaryrefslogtreecommitdiff
path: root/Lib/idlelib/config.py
diff options
context:
space:
mode:
authorLouie Lu <git@louie.lu>2017-07-19 05:17:56 +0800
committerterryjreedy <tjreedy@udel.edu>2017-07-18 17:17:56 -0400
commitf776eb0f0e046f2fa3a96540bb42d8cf970f6c55 (patch)
tree195b981abe8f6880734afed2ee94e71bc38d7c60 /Lib/idlelib/config.py
parent5feda33a35d9413e2073411b848dc49d94c57497 (diff)
downloadcpython-git-f776eb0f0e046f2fa3a96540bb42d8cf970f6c55.tar.gz
bpo-30917: IDLE: Add config.IdleConf unittests (#2691)
Patch by Louie Lu.
Diffstat (limited to 'Lib/idlelib/config.py')
-rw-r--r--Lib/idlelib/config.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/Lib/idlelib/config.py b/Lib/idlelib/config.py
index 4cf44271f3..63d9a44234 100644
--- a/Lib/idlelib/config.py
+++ b/Lib/idlelib/config.py
@@ -30,6 +30,7 @@ import os
import sys
from tkinter.font import Font
+import idlelib
class InvalidConfigType(Exception): pass
class InvalidConfigSet(Exception): pass
@@ -159,14 +160,15 @@ class IdleConf:
for config_type in self.config_types:
(user home dir)/.idlerc/config-{config-type}.cfg
"""
- def __init__(self):
+ def __init__(self, _utest=False):
self.config_types = ('main', 'highlight', 'keys', 'extensions')
self.defaultCfg = {}
self.userCfg = {}
self.cfg = {} # TODO use to select userCfg vs defaultCfg
- self.CreateConfigHandlers()
- self.LoadCfgFiles()
+ if not _utest:
+ self.CreateConfigHandlers()
+ self.LoadCfgFiles()
def CreateConfigHandlers(self):
"Populate default and user config parser dictionaries."
@@ -215,7 +217,8 @@ class IdleConf:
except OSError:
warn = ('\n Warning: unable to create user config directory\n' +
userDir + '\n Check path and permissions.\n Exiting!\n')
- print(warn, file=sys.stderr)
+ if not idlelib.testing:
+ print(warn, file=sys.stderr)
raise SystemExit
# TODO continue without userDIr instead of exit
return userDir
@@ -463,16 +466,7 @@ class IdleConf:
def RemoveKeyBindNames(self, extnNameList):
"Return extnNameList with keybinding section names removed."
- # TODO Easier to return filtered copy with list comp
- names = extnNameList
- kbNameIndicies = []
- for name in names:
- if name.endswith(('_bindings', '_cfgBindings')):
- kbNameIndicies.append(names.index(name))
- kbNameIndicies.sort(reverse=True)
- for index in kbNameIndicies: #delete each keybinding section name
- del(names[index])
- return names
+ return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
def GetExtnNameForEvent(self, virtualEvent):
"""Return the name of the extension binding virtualEvent, or None.