can use requires with self option
This commit is contained in:
parent
2018a92b66
commit
b442d52289
|
@ -58,6 +58,24 @@ def test_requires():
|
||||||
api.option('ip_address_service').value.get()
|
api.option('ip_address_service').value.get()
|
||||||
|
|
||||||
|
|
||||||
|
def test_requires_self():
|
||||||
|
a = StrOption('ip_address_service', '',
|
||||||
|
requires=[{'option': 'self', 'expected': 'b', 'action': 'disabled'}])
|
||||||
|
od = OptionDescription('service', '', [a])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
api.property.read_write()
|
||||||
|
assert api.option('ip_address_service').value.get() == None
|
||||||
|
api.option('ip_address_service').value.set('a')
|
||||||
|
assert api.option('ip_address_service').value.get() == 'a'
|
||||||
|
api.option('ip_address_service').value.set('b')
|
||||||
|
props = []
|
||||||
|
try:
|
||||||
|
api.option('ip_address_service').value.get()
|
||||||
|
except PropertiesOptionError as err:
|
||||||
|
props = err.proptype
|
||||||
|
assert frozenset(props) == frozenset(['disabled'])
|
||||||
|
|
||||||
|
|
||||||
def test_requires_with_requires():
|
def test_requires_with_requires():
|
||||||
a = BoolOption('activate_service', '', True)
|
a = BoolOption('activate_service', '', True)
|
||||||
b = IPOption('ip_address_service', '',
|
b = IPOption('ip_address_service', '',
|
||||||
|
|
|
@ -74,6 +74,8 @@ def manager_callback(callbk,
|
||||||
(not opt.impl_is_master_slaves('slave') or index is None):
|
(not opt.impl_is_master_slaves('slave') or index is None):
|
||||||
return orig_value
|
return orig_value
|
||||||
if opt == option:
|
if opt == option:
|
||||||
|
sconfig_bag.setting_properties = None
|
||||||
|
sconfig_bag.force_unrestraint= False
|
||||||
sconfig_bag.validate = False
|
sconfig_bag.validate = False
|
||||||
try:
|
try:
|
||||||
# get value
|
# get value
|
||||||
|
|
|
@ -77,7 +77,7 @@ class PropertiesOptionError(AttributeError):
|
||||||
self._requires = config_bag.option.impl_getrequires()
|
self._requires = config_bag.option.impl_getrequires()
|
||||||
self._name = config_bag.option.impl_get_display_name()
|
self._name = config_bag.option.impl_get_display_name()
|
||||||
self._orig_opt = None
|
self._orig_opt = None
|
||||||
self._config_bag = config_bag.copy('nooption')
|
self._config_bag = config_bag.copy()
|
||||||
self.proptype = proptype
|
self.proptype = proptype
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
self.msg = None
|
self.msg = None
|
||||||
|
|
|
@ -469,6 +469,8 @@ def validate_requires_arg(new_option,
|
||||||
"""
|
"""
|
||||||
def get_option(require):
|
def get_option(require):
|
||||||
option = require['option']
|
option = require['option']
|
||||||
|
if option == 'self':
|
||||||
|
option = new_option
|
||||||
if not isinstance(option, BaseOption):
|
if not isinstance(option, BaseOption):
|
||||||
raise ValueError(_('malformed requirements '
|
raise ValueError(_('malformed requirements '
|
||||||
'must be an option in option {0}').format(name))
|
'must be an option in option {0}').format(name))
|
||||||
|
|
|
@ -481,7 +481,7 @@ class Settings(object):
|
||||||
for option, expected in exps:
|
for option, expected in exps:
|
||||||
reqpath = option.impl_getpath(context)
|
reqpath = option.impl_getpath(context)
|
||||||
#FIXME c'est un peut tard !
|
#FIXME c'est un peut tard !
|
||||||
if reqpath == path or reqpath.startswith(path + '.'):
|
if reqpath.startswith(path + '.'):
|
||||||
raise RequirementError(_("malformed requirements "
|
raise RequirementError(_("malformed requirements "
|
||||||
"imbrication detected for option:"
|
"imbrication detected for option:"
|
||||||
" '{0}' with requirement on: "
|
" '{0}' with requirement on: "
|
||||||
|
@ -493,8 +493,13 @@ class Settings(object):
|
||||||
elif option.impl_is_multi():
|
elif option.impl_is_multi():
|
||||||
is_indexed = True
|
is_indexed = True
|
||||||
sconfig_bag = config_bag.copy('nooption')
|
sconfig_bag = config_bag.copy('nooption')
|
||||||
sconfig_bag.option = option
|
if config_bag.option == option:
|
||||||
|
sconfig_bag.setting_properties = None
|
||||||
|
sconfig_bag.force_unrestraint= False
|
||||||
|
sconfig_bag.validate = False
|
||||||
|
else:
|
||||||
sconfig_bag.force_permissive = True
|
sconfig_bag.force_permissive = True
|
||||||
|
sconfig_bag.option = option
|
||||||
try:
|
try:
|
||||||
value = context.getattr(reqpath,
|
value = context.getattr(reqpath,
|
||||||
idx,
|
idx,
|
||||||
|
|
|
@ -152,6 +152,14 @@ class Values(object):
|
||||||
with_value=True)
|
with_value=True)
|
||||||
|
|
||||||
if owner != owners.default:
|
if owner != owners.default:
|
||||||
|
if config_bag.setting_properties is None:
|
||||||
|
# get property without apply requires
|
||||||
|
settings = self._getcontext().cfgimpl_get_settings()
|
||||||
|
self_properties = settings.getproperties(path,
|
||||||
|
index,
|
||||||
|
config_bag,
|
||||||
|
apply_requires=False)
|
||||||
|
else:
|
||||||
# if a value is store in storage, check if not frozen + force_default_on_freeze
|
# if a value is store in storage, check if not frozen + force_default_on_freeze
|
||||||
# if frozen + force_default_on_freeze => force default value
|
# if frozen + force_default_on_freeze => force default value
|
||||||
self_properties = config_bag.properties
|
self_properties = config_bag.properties
|
||||||
|
|
Loading…
Reference in New Issue