if an option has configerror for mandatory property but is disabled too, do not raise
This commit is contained in:
parent
e7b174f28f
commit
a3261abc94
2 changed files with 63 additions and 37 deletions
|
@ -5,7 +5,7 @@ do_autopath()
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from tiramisu import Config
|
from tiramisu import Config
|
||||||
from tiramisu import IntOption, StrOption, OptionDescription, DynOptionDescription, \
|
from tiramisu import IntOption, StrOption, OptionDescription, DynOptionDescription, PasswordOption, UsernameOption, \
|
||||||
SymLinkOption, Leadership, undefined, Calculation, Params, \
|
SymLinkOption, Leadership, undefined, Calculation, Params, \
|
||||||
ParamOption, ParamValue, ParamIndex, calc_value
|
ParamOption, ParamValue, ParamIndex, calc_value
|
||||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||||
|
@ -14,6 +14,8 @@ from tiramisu.setting import groups
|
||||||
|
|
||||||
#def teardown_function(function):
|
#def teardown_function(function):
|
||||||
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
# assert list_sessions() == [], 'session list is not empty when leaving "{}"'.format(function.__name__)
|
||||||
|
def is_mandatory(variable):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def make_description():
|
def make_description():
|
||||||
|
@ -723,3 +725,12 @@ def test_mandatory_callback_leader_and_followers_leader():
|
||||||
# FIXME cfg = get_config(cfg, config_type)
|
# FIXME cfg = get_config(cfg, config_type)
|
||||||
compare(cfg.value.mandatory(), ['val1.val1'])
|
compare(cfg.value.mandatory(), ['val1.val1'])
|
||||||
# assert not list_sessions()
|
# assert not list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
def test_mandatory_and_disabled():
|
||||||
|
password = PasswordOption(name="password", doc="Password", properties=frozenset({"disabled"}))
|
||||||
|
username = UsernameOption(name="username", doc="Username", properties=frozenset({"normal", Calculation(is_mandatory, Params((ParamOption(password)))), "disabled"}))
|
||||||
|
od1 = OptionDescription('rootconfig', '', [username, password])
|
||||||
|
cfg = Config(od1)
|
||||||
|
cfg.property.read_write()
|
||||||
|
cfg.value.dict()
|
||||||
|
|
|
@ -196,9 +196,12 @@ class OptionBag:
|
||||||
self.properties = None
|
self.properties = None
|
||||||
elif properties is undefined:
|
elif properties is undefined:
|
||||||
settings = context.get_settings()
|
settings = context.get_settings()
|
||||||
|
try:
|
||||||
self.properties = settings.getproperties(self,
|
self.properties = settings.getproperties(self,
|
||||||
apply_requires=apply_requires,
|
apply_requires=apply_requires,
|
||||||
)
|
)
|
||||||
|
except ConfigError:
|
||||||
|
self.properties = None
|
||||||
if properties is not undefined:
|
if properties is not undefined:
|
||||||
self.properties = properties
|
self.properties = properties
|
||||||
|
|
||||||
|
@ -454,6 +457,7 @@ class Settings:
|
||||||
apply_requires=True,
|
apply_requires=True,
|
||||||
uncalculated=False,
|
uncalculated=False,
|
||||||
help_property=False,
|
help_property=False,
|
||||||
|
transitive_raise=True,
|
||||||
):
|
):
|
||||||
"""get properties
|
"""get properties
|
||||||
"""
|
"""
|
||||||
|
@ -489,6 +493,7 @@ class Settings:
|
||||||
else:
|
else:
|
||||||
props.add((prop, prop))
|
props.add((prop, prop))
|
||||||
elif apply_requires:
|
elif apply_requires:
|
||||||
|
try:
|
||||||
if not help_property:
|
if not help_property:
|
||||||
new_prop = prop.execute(option_bag,
|
new_prop = prop.execute(option_bag,
|
||||||
for_settings=True,
|
for_settings=True,
|
||||||
|
@ -501,6 +506,10 @@ class Settings:
|
||||||
new_prop = (new_prop, new_prop)
|
new_prop = (new_prop, new_prop)
|
||||||
if new_prop is None:
|
if new_prop is None:
|
||||||
continue
|
continue
|
||||||
|
except ConfigError as err:
|
||||||
|
if transitive_raise:
|
||||||
|
raise err from err
|
||||||
|
continue
|
||||||
if (not help_property and not isinstance(new_prop, str)) or \
|
if (not help_property and not isinstance(new_prop, str)) or \
|
||||||
(help_property and not isinstance(new_prop, tuple)):
|
(help_property and not isinstance(new_prop, tuple)):
|
||||||
raise ValueError(_('invalid property type {type(new_prop)} for '
|
raise ValueError(_('invalid property type {type(new_prop)} for '
|
||||||
|
@ -514,7 +523,7 @@ class Settings:
|
||||||
props -= self.getpermissives(option_bag)
|
props -= self.getpermissives(option_bag)
|
||||||
if not uncalculated and apply_requires and \
|
if not uncalculated and apply_requires and \
|
||||||
not option_bag.config_bag.is_unrestraint and \
|
not option_bag.config_bag.is_unrestraint and \
|
||||||
not help_property:
|
not help_property and transitive_raise:
|
||||||
cache.setcache(option_bag,
|
cache.setcache(option_bag,
|
||||||
props,
|
props,
|
||||||
type_='properties',
|
type_='properties',
|
||||||
|
@ -683,15 +692,17 @@ class Settings:
|
||||||
option_bag,
|
option_bag,
|
||||||
apply_requires=True,
|
apply_requires=True,
|
||||||
uncalculated=False,
|
uncalculated=False,
|
||||||
|
transitive_raise=True,
|
||||||
):
|
):
|
||||||
"""raise if needed
|
"""raise if needed
|
||||||
"""
|
"""
|
||||||
if not uncalculated and apply_requires:
|
if not uncalculated and apply_requires and option_bag.properties is not None:
|
||||||
option_properties = option_bag.properties
|
option_properties = option_bag.properties
|
||||||
else:
|
else:
|
||||||
option_properties = self.getproperties(option_bag,
|
option_properties = self.getproperties(option_bag,
|
||||||
apply_requires=apply_requires,
|
apply_requires=apply_requires,
|
||||||
uncalculated=uncalculated,
|
uncalculated=uncalculated,
|
||||||
|
transitive_raise=transitive_raise,
|
||||||
)
|
)
|
||||||
return self._calc_raises_properties(option_bag.config_bag.properties,
|
return self._calc_raises_properties(option_bag.config_bag.properties,
|
||||||
option_bag.config_bag.permissives,
|
option_bag.config_bag.permissives,
|
||||||
|
@ -721,11 +732,15 @@ class Settings:
|
||||||
if not config_properties or config_properties == frozenset(['cache']):
|
if not config_properties or config_properties == frozenset(['cache']):
|
||||||
# if no global property
|
# if no global property
|
||||||
return
|
return
|
||||||
properties = self.calc_raises_properties(option_bag)
|
for transitive_raise in [False, True]:
|
||||||
|
properties = self.calc_raises_properties(option_bag,
|
||||||
|
transitive_raise=transitive_raise,
|
||||||
|
)
|
||||||
if properties != frozenset():
|
if properties != frozenset():
|
||||||
if need_help:
|
if need_help:
|
||||||
help_properties = dict(self.getproperties(option_bag,
|
help_properties = dict(self.getproperties(option_bag,
|
||||||
help_property=True,
|
help_property=True,
|
||||||
|
transitive_raise=transitive_raise,
|
||||||
))
|
))
|
||||||
calc_properties = []
|
calc_properties = []
|
||||||
for property_ in self._calc_raises_properties(option_bag.config_bag.properties,
|
for property_ in self._calc_raises_properties(option_bag.config_bag.properties,
|
||||||
|
|
Loading…
Reference in a new issue