add DynOptionDescription
This commit is contained in:
@ -114,11 +114,11 @@ class _NameSpace(object):
|
||||
"""
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name in self.__dict__:
|
||||
if name in self.__dict__: # pragma: optional cover
|
||||
raise ConstError(_("can't rebind {0}").format(name))
|
||||
self.__dict__[name] = value
|
||||
|
||||
def __delattr__(self, name):
|
||||
def __delattr__(self, name): # pragma: optional cover
|
||||
if name in self.__dict__:
|
||||
raise ConstError(_("can't unbind {0}").format(name))
|
||||
raise ValueError(name)
|
||||
@ -248,7 +248,7 @@ class Property(object):
|
||||
:type propname: string
|
||||
"""
|
||||
if self._opt is not None and self._opt.impl_getrequires() is not None \
|
||||
and propname in self._opt._calc_properties:
|
||||
and propname in self._opt._calc_properties: # pragma: optional cover
|
||||
raise ValueError(_('cannot append {0} property for option {1}: '
|
||||
'this property is calculated').format(
|
||||
propname, self._opt.impl_getname()))
|
||||
@ -315,7 +315,7 @@ class Settings(object):
|
||||
old `SubConfig`, `Values`, `Multi` or `Settings`)
|
||||
"""
|
||||
context = self.context()
|
||||
if context is None:
|
||||
if context is None: # pragma: optional cover
|
||||
raise ConfigError(_('the context does not exist anymore'))
|
||||
return context
|
||||
|
||||
@ -329,24 +329,24 @@ class Settings(object):
|
||||
return str(list(self._getproperties()))
|
||||
|
||||
def __getitem__(self, opt):
|
||||
path = self._get_path_by_opt(opt)
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
return self._getitem(opt, path)
|
||||
|
||||
def _getitem(self, opt, path):
|
||||
return Property(self, self._getproperties(opt, path), opt, path)
|
||||
|
||||
def __setitem__(self, opt, value):
|
||||
def __setitem__(self, opt, value): # pragma: optional cover
|
||||
raise ValueError('you should only append/remove properties')
|
||||
|
||||
def reset(self, opt=None, _path=None, all_properties=False):
|
||||
if all_properties and (_path or opt):
|
||||
if all_properties and (_path or opt): # pragma: optional cover
|
||||
raise ValueError(_('opt and all_properties must not be set '
|
||||
'together in reset'))
|
||||
if all_properties:
|
||||
self._p_.reset_all_properties()
|
||||
else:
|
||||
if opt is not None and _path is None:
|
||||
_path = self._get_path_by_opt(opt)
|
||||
_path = opt.impl_getpath(self._getcontext())
|
||||
self._p_.reset_properties(_path)
|
||||
self._getcontext().cfgimpl_reset_cache()
|
||||
|
||||
@ -357,7 +357,7 @@ class Settings(object):
|
||||
if opt is None:
|
||||
props = copy(self._p_.getproperties(path, default_properties))
|
||||
else:
|
||||
if path is None:
|
||||
if path is None: # pragma: optional cover
|
||||
raise ValueError(_('if opt is not None, path should not be'
|
||||
' None in _getproperties'))
|
||||
ntime = None
|
||||
@ -491,15 +491,15 @@ class Settings(object):
|
||||
instead of passing a :class:`tiramisu.option.Option()` object.
|
||||
"""
|
||||
if opt is not None and path is None:
|
||||
path = self._get_path_by_opt(opt)
|
||||
if not isinstance(permissive, tuple):
|
||||
path = opt.impl_getpath(self._getcontext())
|
||||
if not isinstance(permissive, tuple): # pragma: optional cover
|
||||
raise TypeError(_('permissive must be a tuple'))
|
||||
self._p_.setpermissive(path, permissive)
|
||||
|
||||
#____________________________________________________________
|
||||
def setowner(self, owner):
|
||||
":param owner: sets the default value for owner at the Config level"
|
||||
if not isinstance(owner, owners.Owner):
|
||||
if not isinstance(owner, owners.Owner): # pragma: optional cover
|
||||
raise TypeError(_("invalid generic owner {0}").format(str(owner)))
|
||||
self._owner = owner
|
||||
|
||||
@ -586,8 +586,8 @@ class Settings(object):
|
||||
for require in requires:
|
||||
option, expected, action, inverse, \
|
||||
transitive, same_action = require
|
||||
reqpath = self._get_path_by_opt(option)
|
||||
if reqpath == path or reqpath.startswith(path + '.'):
|
||||
reqpath = option.impl_getpath(context)
|
||||
if reqpath == path or reqpath.startswith(path + '.'): # pragma: optional cover
|
||||
raise RequirementError(_("malformed requirements "
|
||||
"imbrication detected for option:"
|
||||
" '{0}' with requirement on: "
|
||||
@ -598,7 +598,7 @@ class Settings(object):
|
||||
if not transitive:
|
||||
continue
|
||||
properties = err.proptype
|
||||
if same_action and action not in properties:
|
||||
if same_action and action not in properties: # pragma: optional cover
|
||||
raise RequirementError(_("option '{0}' has "
|
||||
"requirement's property "
|
||||
"error: "
|
||||
@ -616,14 +616,6 @@ class Settings(object):
|
||||
break
|
||||
return calc_properties
|
||||
|
||||
def _get_path_by_opt(self, opt):
|
||||
"""just a wrapper to get path in optiondescription's cache
|
||||
|
||||
:param opt: `Option`'s object
|
||||
:returns: path
|
||||
"""
|
||||
return self._getcontext().cfgimpl_get_description().impl_get_path_by_opt(opt)
|
||||
|
||||
def get_modified_properties(self):
|
||||
return self._p_.get_modified_properties()
|
||||
|
||||
|
Reference in New Issue
Block a user