feat: .mandatory() is permissive by default, but this is not recommended in all cases
This commit is contained in:
parent
25c5381ae6
commit
29ed1c2b6c
3 changed files with 42 additions and 5 deletions
|
|
@ -746,3 +746,15 @@ def test_mandatory_and_disabled():
|
|||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
cfg.value.get()
|
||||
|
||||
|
||||
def test_mandatory_permissive():
|
||||
val1 = StrOption('val1', "", properties=('mandatory', 'hidden'))
|
||||
od2 = OptionDescription('val1', '', [val1])
|
||||
od1 = OptionDescription('rootconfig', '', [od2])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
compare(cfg.value.mandatory(set_permissive=False), [])
|
||||
compare(cfg.value.mandatory(), ['val1.val1'])
|
||||
compare(cfg.option("val1").value.mandatory(set_permissive=False), [])
|
||||
compare(cfg.option("val1").value.mandatory(), ['val1.val1'])
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ do_autopath()
|
|||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, BoolOption, ChoiceOption, \
|
||||
IPOption, OptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
|
||||
IPOption, OptionDescription, DynOptionDescription, Leadership, Config, GroupConfig, MetaConfig, \
|
||||
Calculation, Params, ParamOption, ParamValue, calc_value, ParamSelfOption, \
|
||||
valid_network_netmask, valid_not_equal
|
||||
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, LeadershipError
|
||||
|
|
@ -1306,3 +1306,26 @@ def test_meta_get_config():
|
|||
assert isinstance(meta.config('name1'), Config)
|
||||
with pytest.raises(ConfigError):
|
||||
meta.config('unknown')
|
||||
|
||||
|
||||
def test_meta_dyndescription():
|
||||
lst = StrOption('lst', '', multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], identifiers=Calculation(return_value, Params(ParamOption(lst))))
|
||||
od = OptionDescription('od', '', [dod, lst])
|
||||
cfg = Config(od, name="cfg")
|
||||
cfg.owner.set(owners.config)
|
||||
meta1 = MetaConfig([cfg], name='meta1')
|
||||
meta1.owner.set(owners.meta1)
|
||||
meta2 = MetaConfig([meta1], name='meta2')
|
||||
meta2.owner.set(owners.meta2)
|
||||
cfg.property.read_write()
|
||||
meta2.option('lst').value.set(["val1", "val2"])
|
||||
meta1.option('lst').value.set(["val3", "val4"])
|
||||
cfg.option('lst').value.set(["val5", "val6"])
|
||||
assert cfg.option('dodval6.st').value.get() is None
|
||||
with pytest.raises(AttributeError):
|
||||
meta1.option('dodval6.st').value.get()
|
||||
assert parse_od_get(cfg.value.get()) == {'dodval5.st': None, 'dodval6.st': None, 'lst': ['val5', 'val6']}
|
||||
assert parse_od_get(meta1.value.get()) == {'dodval3.st': None, 'dodval4.st': None, 'lst': ['val3', 'val4']}
|
||||
assert parse_od_get(meta2.value.get()) == {'dodval1.st': None, 'dodval2.st': None, 'lst': ['val1', 'val2']}
|
||||
|
|
|
|||
|
|
@ -1198,13 +1198,14 @@ class TiramisuOptionValue(CommonTiramisuOption, _TiramisuODGet):
|
|||
"""Length for a leadership"""
|
||||
return self._subconfig.parent.get_length_leadership()
|
||||
|
||||
def mandatory(self, *, return_type=False):
|
||||
def mandatory(self, *, return_type=False, set_permissive=True):
|
||||
"""Return path of options with mandatory property without any value"""
|
||||
subconfig = self._subconfig
|
||||
ori_config_bag = self._subconfig.config_bag
|
||||
config_bag = ori_config_bag.copy()
|
||||
config_bag.properties -= {"mandatory", "empty", "warnings"}
|
||||
config_bag.set_permissive()
|
||||
if set_permissive:
|
||||
config_bag.set_permissive()
|
||||
self._subconfig.config_bag = config_bag
|
||||
try:
|
||||
if subconfig.option.impl_is_optiondescription():
|
||||
|
|
@ -1488,11 +1489,12 @@ class TiramisuContextInformation(TiramisuConfig):
|
|||
class TiramisuContextValue(TiramisuConfig, _TiramisuODGet):
|
||||
"""Manage config value"""
|
||||
|
||||
def mandatory(self):
|
||||
def mandatory(self, set_permissive=True):
|
||||
"""Return path of options with mandatory property without any value"""
|
||||
config_bag = self._config_bag.copy()
|
||||
config_bag.properties -= {"mandatory", "empty", "warnings"}
|
||||
config_bag.set_permissive()
|
||||
if set_permissive:
|
||||
config_bag.set_permissive()
|
||||
root = self._config_bag.context.get_root(config_bag)
|
||||
options = []
|
||||
for subconfig in self._config_bag.context.walk(
|
||||
|
|
|
|||
Loading…
Reference in a new issue