finally a getvalue without a getattr
This commit is contained in:
parent
c40d33fec3
commit
df3753c36b
|
@ -58,6 +58,13 @@ def test_iter_subconfig():
|
||||||
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
zip(conf.gc, [("name", "ref"), ("dummy", False)]):
|
||||||
assert name == gname
|
assert name == gname
|
||||||
assert value == gvalue
|
assert value == gvalue
|
||||||
|
|
||||||
|
def test_cfgimpl_get_value():
|
||||||
|
"same as getattr."
|
||||||
|
descr = make_description()
|
||||||
|
conf = Config(descr)
|
||||||
|
assert conf.cfgimpl_get_value(('gc', 'dummy')) == False
|
||||||
|
|
||||||
#____________________________________________________________
|
#____________________________________________________________
|
||||||
def test_getpaths():
|
def test_getpaths():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
|
|
|
@ -79,6 +79,25 @@ class Config(object):
|
||||||
raise ConfigError("setting not allowed")
|
raise ConfigError("setting not allowed")
|
||||||
self._cfgimpl_context._cfgimpl_settings = settings
|
self._cfgimpl_context._cfgimpl_settings = settings
|
||||||
|
|
||||||
|
def cfgimpl_get_description(self):
|
||||||
|
return self._cfgimpl_descr
|
||||||
|
|
||||||
|
def cfgimpl_get_value(self, path):
|
||||||
|
"""same as multiple getattrs
|
||||||
|
|
||||||
|
:param path: list or tuple of path
|
||||||
|
|
||||||
|
example : ``path = (sub_conf, opt)`` makes a getattr of sub_conf, then
|
||||||
|
a getattr of opt, and then returns the opt's value.
|
||||||
|
|
||||||
|
:returns: subconf or option's value
|
||||||
|
"""
|
||||||
|
subpaths = list(path)
|
||||||
|
subconf_or_opt = self
|
||||||
|
for subpath in subpaths:
|
||||||
|
subconf_or_opt = getattr(subconf_or_opt, subpath)
|
||||||
|
return subconf_or_opt
|
||||||
|
|
||||||
def _validate_duplicates(self, children):
|
def _validate_duplicates(self, children):
|
||||||
"""duplicates Option names in the schema
|
"""duplicates Option names in the schema
|
||||||
:type children: list of `Option` or `OptionDescription`
|
:type children: list of `Option` or `OptionDescription`
|
||||||
|
|
Loading…
Reference in New Issue