refactor and better test in api

This commit is contained in:
2017-11-13 22:45:53 +01:00
parent a8d022b67f
commit 007a22ca94
9 changed files with 406 additions and 348 deletions

View File

@ -575,24 +575,29 @@ class Settings(object):
else:
opt_type = 'option'
if 'frozen' in properties:
return PropertiesOptionError(_('cannot change the value for '
'option "{0}" this option is'
' frozen').format(
opt_or_descr.impl_getname()),
props, self, datas, opt_type)
raise PropertiesOptionError(_('cannot change the value for '
'option "{0}" this option is'
' frozen').format(
opt_or_descr.impl_getname()),
props,
self,
datas,
opt_type)
else:
if len(props) == 1:
prop_msg = _('property')
else:
prop_msg = _('properties')
return PropertiesOptionError(_('cannot access to {0} "{1}" '
'because has {2} {3}'
'').format(opt_type,
opt_or_descr.impl_get_display_name(),
prop_msg,
display_list(props)),
props,
self, datas, opt_type)
raise PropertiesOptionError(_('cannot access to {0} "{1}" '
'because has {2} {3}'
'').format(opt_type,
opt_or_descr.impl_get_display_name(),
prop_msg,
display_list(props)),
props,
self,
datas,
opt_type)
def setpermissive(self, permissive, opt=None, path=None):
"""
@ -728,37 +733,36 @@ class Settings(object):
idx = index
else:
idx = None
value = context.getattr(reqpath, force_permissive=True,
_setting_properties=setting_properties,
index=idx, returns_raise=True)
if isinstance(value, Exception):
if isinstance(value, PropertiesOptionError):
if not transitive:
if all_properties is None:
all_properties = []
for requires in opt.impl_getrequires():
for require in requires:
all_properties.append(require[1])
if not set(value.proptype) - set(all_properties):
continue
properties = value.proptype
if same_action and action not in properties: # pragma: optional cover
if len(properties) == 1:
prop_msg = _('property')
else:
prop_msg = _('properties')
raise RequirementError(_('cannot access to option "{0}" because '
'required option "{1}" has {2} {3}'
'').format(opt.impl_get_display_name(),
option.impl_get_display_name(),
prop_msg,
display_list(properties)))
orig_value = value
# transitive action, force expected
value = expected[0]
inverse = False
else: # pragma: no cover
raise value
try:
value = context.getattr(reqpath,
force_permissive=True,
_setting_properties=setting_properties,
index=idx)
except PropertiesOptionError as err:
if not transitive:
if all_properties is None:
all_properties = []
for requires in opt.impl_getrequires():
for require in requires:
all_properties.append(require[1])
if not set(err.proptype) - set(all_properties):
continue
properties = err.proptype
if same_action and action not in properties: # pragma: optional cover
if len(properties) == 1:
prop_msg = _('property')
else:
prop_msg = _('properties')
raise RequirementError(_('cannot access to option "{0}" because '
'required option "{1}" has {2} {3}'
'').format(opt.impl_get_display_name(),
option.impl_get_display_name(),
prop_msg,
display_list(properties)))
orig_value = err
# transitive action, force expected
value = expected[0]
inverse = False
else:
orig_value = value
if (not inverse and value in expected or