bpo-30917: IDLE: Add config.IdleConf unittests (#2691) · python/cpython@f776eb0 (original) (raw)

`@@ -30,6 +30,7 @@

`

30

30

`import sys

`

31

31

``

32

32

`from tkinter.font import Font

`

``

33

`+

import idlelib

`

33

34

``

34

35

`class InvalidConfigType(Exception): pass

`

35

36

`class InvalidConfigSet(Exception): pass

`

`@@ -159,14 +160,15 @@ class IdleConf:

`

159

160

` for config_type in self.config_types:

`

160

161

` (user home dir)/.idlerc/config-{config-type}.cfg

`

161

162

` """

`

162

``

`-

def init(self):

`

``

163

`+

def init(self, _utest=False):

`

163

164

`self.config_types = ('main', 'highlight', 'keys', 'extensions')

`

164

165

`self.defaultCfg = {}

`

165

166

`self.userCfg = {}

`

166

167

`self.cfg = {} # TODO use to select userCfg vs defaultCfg

`

167

``

`-

self.CreateConfigHandlers()

`

168

``

`-

self.LoadCfgFiles()

`

169

168

``

``

169

`+

if not _utest:

`

``

170

`+

self.CreateConfigHandlers()

`

``

171

`+

self.LoadCfgFiles()

`

170

172

``

171

173

`def CreateConfigHandlers(self):

`

172

174

`"Populate default and user config parser dictionaries."

`

`@@ -215,7 +217,8 @@ def GetUserCfgDir(self):

`

215

217

`except OSError:

`

216

218

`warn = ('\n Warning: unable to create user config directory\n' +

`

217

219

`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)

`

219

222

`raise SystemExit

`

220

223

`# TODO continue without userDIr instead of exit

`

221

224

`return userDir

`

`@@ -463,16 +466,7 @@ def GetExtensions(self, active_only=True,

`

463

466

``

464

467

`def RemoveKeyBindNames(self, extnNameList):

`

465

468

`"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'))]

`

476

470

``

477

471

`def GetExtnNameForEvent(self, virtualEvent):

`

478

472

`"""Return the name of the extension binding virtualEvent, or None.

`