Update config module to provide dict like access
This commit is contained in:
@@ -86,6 +86,13 @@ class Config(object):
|
|||||||
except (ValueError, ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
except (ValueError, ConfigParser.NoSectionError, ConfigParser.NoOptionError):
|
||||||
self.__dict__[section].__dict__[name] = vdefault
|
self.__dict__[section].__dict__[name] = vdefault
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
try:
|
||||||
|
return getattr(self, key)
|
||||||
|
except AttributeError, e:
|
||||||
|
raise KeyError(e)
|
||||||
|
|
||||||
|
|
||||||
def x2bool(s):
|
def x2bool(s):
|
||||||
"""
|
"""
|
||||||
Helper function to convert strings from the config to bool
|
Helper function to convert strings from the config to bool
|
||||||
|
@@ -131,6 +131,15 @@ value = True
|
|||||||
assert(cfg.somethingelse.bla == "test")
|
assert(cfg.somethingelse.bla == "test")
|
||||||
assert(cfg.world.somenum == 0)
|
assert(cfg.world.somenum == 0)
|
||||||
|
|
||||||
|
def testGetItem(self):
|
||||||
|
cfg = Config(default=self.cfg_default)
|
||||||
|
assert(cfg["world"]["domination"] == False)
|
||||||
|
|
||||||
|
def invalidaccess(c):
|
||||||
|
c["nointhisconfig"]
|
||||||
|
|
||||||
|
self.assertRaises(KeyError, invalidaccess, cfg)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#import sys;sys.argv = ['', 'Test.testName']
|
#import sys;sys.argv = ['', 'Test.testName']
|
||||||
|
Reference in New Issue
Block a user