Kaydet (Commit) 65c24c84 authored tarafından terryjreedy's avatar terryjreedy Kaydeden (comit) GitHub

[3.6] bpo-30917: IDLE: Add config.IdleConf unittests (GH-2691) (#2753)

Patch by Louie Lu.
(cherry picked from commit f776eb0f)
(includes diffs of  ed014f7e and 9f9192af)
* fix config reset from pr 2754

* Fix test_get_font (from pr 2769)
üst ae4dca77
...@@ -30,6 +30,7 @@ import os ...@@ -30,6 +30,7 @@ import os
import sys import sys
from tkinter.font import Font from tkinter.font import Font
import idlelib
class InvalidConfigType(Exception): pass class InvalidConfigType(Exception): pass
class InvalidConfigSet(Exception): pass class InvalidConfigSet(Exception): pass
...@@ -159,14 +160,15 @@ class IdleConf: ...@@ -159,14 +160,15 @@ class IdleConf:
for config_type in self.config_types: for config_type in self.config_types:
(user home dir)/.idlerc/config-{config-type}.cfg (user home dir)/.idlerc/config-{config-type}.cfg
""" """
def __init__(self): def __init__(self, _utest=False):
self.config_types = ('main', 'highlight', 'keys', 'extensions') self.config_types = ('main', 'highlight', 'keys', 'extensions')
self.defaultCfg = {} self.defaultCfg = {}
self.userCfg = {} self.userCfg = {}
self.cfg = {} # TODO use to select userCfg vs defaultCfg self.cfg = {} # TODO use to select userCfg vs defaultCfg
self.CreateConfigHandlers()
self.LoadCfgFiles()
if not _utest:
self.CreateConfigHandlers()
self.LoadCfgFiles()
def CreateConfigHandlers(self): def CreateConfigHandlers(self):
"Populate default and user config parser dictionaries." "Populate default and user config parser dictionaries."
...@@ -215,7 +217,8 @@ class IdleConf: ...@@ -215,7 +217,8 @@ class IdleConf:
except OSError: except OSError:
warn = ('\n Warning: unable to create user config directory\n' + warn = ('\n Warning: unable to create user config directory\n' +
userDir + '\n Check path and permissions.\n Exiting!\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 raise SystemExit
# TODO continue without userDIr instead of exit # TODO continue without userDIr instead of exit
return userDir return userDir
...@@ -463,16 +466,7 @@ class IdleConf: ...@@ -463,16 +466,7 @@ class IdleConf:
def RemoveKeyBindNames(self, extnNameList): def RemoveKeyBindNames(self, extnNameList):
"Return extnNameList with keybinding section names removed." "Return extnNameList with keybinding section names removed."
# TODO Easier to return filtered copy with list comp return [n for n in extnNameList if not n.endswith(('_bindings', '_cfgBindings'))]
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
def GetExtnNameForEvent(self, virtualEvent): def GetExtnNameForEvent(self, virtualEvent):
"""Return the name of the extension binding virtualEvent, or None. """Return the name of the extension binding virtualEvent, or None.
......
Add tests for idlelib.config.IdleConf.
Increase coverage from 46% to 96%.
Patch by Louie Lu.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment