remove subconfig
This commit is contained in:
parent
4b76e3314e
commit
1d18cc74b7
25 changed files with 1599 additions and 1708 deletions
|
@ -856,31 +856,31 @@ def autocheck_reset_value_permissive(cfg, mcfg, pathread, pathwrite, confread, c
|
|||
_autocheck_default_value(cfg, pathread, confread, **kwargs)
|
||||
if confread != confwrite:
|
||||
_autocheck_default_value(cfg, pathwrite, confwrite, **kwargs)
|
||||
|
||||
|
||||
@autocheck
|
||||
def autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
"""re set value
|
||||
"""
|
||||
if kwargs['callback']:
|
||||
return
|
||||
make_dict = kwargs['make_dict']
|
||||
make_dict_value = kwargs['make_dict_value']
|
||||
if confread is not None:
|
||||
cfg_ = cfg.config(confread)
|
||||
else:
|
||||
cfg_ = cfg
|
||||
if confwrite is not None:
|
||||
cfg2_ = cfg.config(confwrite)
|
||||
else:
|
||||
cfg2_ = cfg
|
||||
assert cfg_.value.dict() == make_dict
|
||||
if confread != confwrite:
|
||||
assert(cfg2_.value.dict()) == make_dict
|
||||
_set_value(cfg, pathwrite, confwrite, **kwargs)
|
||||
assert cfg_.value.dict() == make_dict_value
|
||||
if confread != confwrite:
|
||||
assert(cfg2_.value.dict()) == make_dict_value
|
||||
#FIXME
|
||||
#FIXME
|
||||
#FIXME@autocheck
|
||||
#FIXMEdef autocheck_display(cfg, mcfg, pathread, pathwrite, confread, confwrite, **kwargs):
|
||||
#FIXME """re set value
|
||||
#FIXME """
|
||||
#FIXME if kwargs['callback']:
|
||||
#FIXME return
|
||||
#FIXME make_dict = kwargs['make_dict']
|
||||
#FIXME make_dict_value = kwargs['make_dict_value']
|
||||
#FIXME if confread is not None:
|
||||
#FIXME cfg_ = cfg.config(confread)
|
||||
#FIXME else:
|
||||
#FIXME cfg_ = cfg
|
||||
#FIXME if confwrite is not None:
|
||||
#FIXME cfg2_ = cfg.config(confwrite)
|
||||
#FIXME else:
|
||||
#FIXME cfg2_ = cfg
|
||||
#FIXME assert cfg_.value.dict() == make_dict
|
||||
#FIXME if confread != confwrite:
|
||||
#FIXME assert(cfg2_.value.dict()) == make_dict
|
||||
#FIXME _set_value(cfg, pathwrite, confwrite, **kwargs)
|
||||
#FIXME assert cfg_.value.dict() == make_dict_value
|
||||
#FIXME if confread != confwrite:
|
||||
#FIXME assert(cfg2_.value.dict()) == make_dict_value
|
||||
|
||||
|
||||
@autocheck
|
||||
|
|
|
@ -390,7 +390,7 @@ def test_cache_leader_and_followers():
|
|||
compare(settings.get_cached(), {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {idx_val2: (val1_val2_props, None)}})
|
||||
})
|
||||
# len is 0 so don't get any value
|
||||
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
|
||||
#
|
||||
|
@ -441,7 +441,7 @@ def test_cache_leader_callback():
|
|||
compare(settings.get_cached(), {None: {None: (global_props, None)},
|
||||
'val1': {None: (val1_props, None)},
|
||||
'val1.val1': {None: (val1_val1_props, None)},
|
||||
'val1.val2': {None: (val1_val2_props, None)}})
|
||||
})
|
||||
compare(values.get_cached(), {'val1.val1': {None: ([], None)}})
|
||||
cfg.option('val1.val1').value.set([undefined])
|
||||
compare(settings.get_cached(), {None: {None: (set(global_props), None)},
|
||||
|
|
|
@ -10,7 +10,6 @@ from .config import config_type, get_config, value_list, global_owner
|
|||
|
||||
import pytest
|
||||
from tiramisu import Config
|
||||
from tiramisu.config import SubConfig
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu import Config, IntOption, FloatOption, ChoiceOption, \
|
||||
BoolOption, StrOption, SymLinkOption, OptionDescription, undefined
|
||||
|
|
|
@ -82,8 +82,6 @@ def test_make_dict(config_type):
|
|||
cfg.option('s1.a').value.set(True)
|
||||
d = cfg.value.dict()
|
||||
assert d == {"s1.a": True, "int": 43}
|
||||
d2 = cfg.value.dict(flatten=True)
|
||||
assert d2 == {'a': True, 'int': 43}
|
||||
if config_type == 'tiramisu':
|
||||
assert cfg.forcepermissive.value.dict() == {"s1.a": True, "s1.b": False, "int": 43}
|
||||
# assert not list_sessions()
|
||||
|
@ -100,7 +98,7 @@ def test_make_dict_sub(config_type):
|
|||
cfg.property.read_write()
|
||||
cfg.permissive.add('hidden')
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.option('s1').value.dict() == {'a': False}
|
||||
assert cfg.option('s1').value.dict() == {'s1.a': False}
|
||||
|
||||
|
||||
def test_make_dict_not_value(config_type):
|
||||
|
@ -169,13 +167,7 @@ def test_make_dict_fullpath(config_type):
|
|||
cfg.property.read_only()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
if config_type == 'tiramisu':
|
||||
# FIXME
|
||||
assert cfg.option('opt').value.dict() == {"s1.a": False, "int": 42}
|
||||
assert cfg.value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42, "introot": 42}
|
||||
if config_type == 'tiramisu':
|
||||
# FIXME
|
||||
assert cfg.option('opt').value.dict(fullpath=True) == {"opt.s1.a": False, "opt.int": 42}
|
||||
assert cfg.option('opt').value.dict() == {"opt.s1.a": False, "opt.int": 42}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
@ -406,7 +406,6 @@ def test_mandatory_dyndescription():
|
|||
cfg.property.read_only()
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('od.dodval1.stval1').value.get()
|
||||
assert list(cfg.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -582,7 +581,6 @@ def test_mandatory_dyndescription_context():
|
|||
cfg.property.read_only()
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('od.dodval1.stval1').value.get()
|
||||
assert list(cfg.value.mandatory()) == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -952,7 +950,6 @@ def test_makedict_dyndescription_context():
|
|||
cfg = Config(od2)
|
||||
cfg.option('od.dodval1.stval1').value.set('yes')
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
|
||||
assert cfg.value.dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -1102,14 +1099,14 @@ def test_leadership_dyndescription():
|
|||
cfg = Config(od1)
|
||||
owner = cfg.owner.get()
|
||||
#
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.value.dict() == {'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
|
@ -1167,20 +1164,20 @@ def test_leadership_dyndescription_force_store_value_leader():
|
|||
assert cfg.option('od.stval1.st1val1.st2val1', 1).owner.isdefault() == True
|
||||
assert cfg.option('od.stval2.st1val2.st2val2', 0).owner.isdefault() == True
|
||||
assert cfg.option('od.stval2.st1val2.st2val2', 1).owner.isdefault() == True
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.val1': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}]}
|
||||
#
|
||||
cfg.option('od.val1').value.set(['val1', 'val2', 'val3'])
|
||||
assert cfg.option('od.stval3.st1val3.st1val3').owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 0).owner.isdefault() == True
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 1).owner.isdefault() == True
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.stval3.st1val3.st1val3': ['val1', 'val2'], 'od.stval3.st1val3.st2val3': ['val1', 'val2'], 'od.val1': ['val1', 'val2', 'val3']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}], 'od.stval3.st1val3.st1val3': [{'od.stval3.st1val3.st1val3': 'val1', 'od.stval3.st1val3.st2val3': 'val1'}, {'od.stval3.st1val3.st1val3': 'val2', 'od.stval3.st1val3.st2val3': 'val2'}]}
|
||||
#
|
||||
cfg.option('od.stval3.st1val3.st1val3').value.set(['val1', 'val2', 'val3'])
|
||||
assert cfg.option('od.stval3.st1val3.st1val3').owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 0).owner.isdefault() == True
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 1).owner.isdefault() == True
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 2).owner.isdefault() == True
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.stval3.st1val3.st1val3': ['val1', 'val2', 'val3'], 'od.stval3.st1val3.st2val3': ['val1', 'val2', 'val3'], 'od.val1': ['val1', 'val2', 'val3']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}], 'od.stval3.st1val3.st1val3': [{'od.stval3.st1val3.st1val3': 'val1', 'od.stval3.st1val3.st2val3': 'val1'}, {'od.stval3.st1val3.st1val3': 'val2', 'od.stval3.st1val3.st2val3': 'val2'}, {'od.stval3.st1val3.st1val3': 'val3', 'od.stval3.st1val3.st2val3': 'val3'}]}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -1200,20 +1197,20 @@ def test_leadership_dyndescription_force_store_value():
|
|||
assert cfg.option('od.stval1.st1val1.st2val1', 1).owner.isdefault() == False
|
||||
assert cfg.option('od.stval2.st1val2.st2val2', 0).owner.isdefault() == False
|
||||
assert cfg.option('od.stval2.st1val2.st2val2', 1).owner.isdefault() == False
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.val1': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}]}
|
||||
#
|
||||
cfg.option('od.val1').value.set(['val1', 'val2', 'val3'])
|
||||
assert cfg.option('od.stval3.st1val3.st1val3').owner.isdefault() == True
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 0).owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 1).owner.isdefault() == False
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.stval3.st1val3.st1val3': ['val1', 'val2'], 'od.stval3.st1val3.st2val3': ['val1', 'val2'], 'od.val1': ['val1', 'val2', 'val3']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}], 'od.stval3.st1val3.st1val3': [{'od.stval3.st1val3.st1val3': 'val1', 'od.stval3.st1val3.st2val3': 'val1'}, {'od.stval3.st1val3.st1val3': 'val2', 'od.stval3.st1val3.st2val3': 'val2'}]}
|
||||
#
|
||||
cfg.option('od.stval3.st1val3.st1val3').value.set(['val1', 'val2', 'val3'])
|
||||
assert cfg.option('od.stval3.st1val3.st1val3').owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 0).owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 1).owner.isdefault() == False
|
||||
assert cfg.option('od.stval3.st1val3.st2val3', 2).owner.isdefault() == False
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['val1', 'val2'], 'od.stval1.st1val1.st2val1': ['val1', 'val2'], 'od.stval2.st1val2.st1val2': ['val1', 'val2'], 'od.stval2.st1val2.st2val2': ['val1', 'val2'], 'od.stval3.st1val3.st1val3': ['val1', 'val2', 'val3'], 'od.stval3.st1val3.st2val3': ['val1', 'val2', 'val3'], 'od.val1': ['val1', 'val2', 'val3']}
|
||||
assert cfg.value.dict() == {'od.val1': ['val1', 'val2', 'val3'], 'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'val1', 'od.stval1.st1val1.st2val1': 'val1'}, {'od.stval1.st1val1.st1val1': 'val2', 'od.stval1.st1val1.st2val1': 'val2'}], 'od.stval2.st1val2.st1val2': [{'od.stval2.st1val2.st1val2': 'val1', 'od.stval2.st1val2.st2val2': 'val1'}, {'od.stval2.st1val2.st1val2': 'val2', 'od.stval2.st1val2.st2val2': 'val2'}], 'od.stval3.st1val3.st1val3': [{'od.stval3.st1val3.st1val3': 'val1', 'od.stval3.st1val3.st2val3': 'val1'}, {'od.stval3.st1val3.st1val3': 'val2', 'od.stval3.st1val3.st2val3': 'val2'}, {'od.stval3.st1val3.st1val3': 'val3', 'od.stval3.st1val3.st2val3': 'val3'}]}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -1253,14 +1250,14 @@ def test_leadership_dyndescription_param():
|
|||
od1 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od1)
|
||||
owner = cfg.owner.get()
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.odval1.val1': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': [], 'od.odval1.val1': ['val1', 'val2']}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.odval1.val1': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None}], 'od.stval2.st1val2.st1val2': [], 'od.odval1.val1': ['val1', 'val2']}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
|
@ -1333,14 +1330,14 @@ def _test_leadership(cfg):
|
|||
cfg.option('od.val1.val1').value.set(['val1', 'val2'])
|
||||
cfg.option('od.val1.val2', 0).value.set('val1')
|
||||
cfg.option('od.val1.val2', 1).value.set('val2')
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': [], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owners.default
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.get() == owners.default
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes'], 'od.val1.val1': ['val1', 'val2'], 'od.val1.val2': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None}], 'od.stval2.st1val2.st1val2': [], 'od.val1.val1': [{'od.val1.val1': 'val1', 'od.val1.val2': 'val1'}, {'od.val1.val1': 'val2', 'od.val1.val2': 'val2'}]}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
|
@ -1504,14 +1501,14 @@ def test_leadership_callback_dyndescription():
|
|||
od2 = OptionDescription('od', '', [od1])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.owner.get()
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() ==[]
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': 'yes'}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == 'yes'
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
|
@ -1599,36 +1596,21 @@ def test_leadership_callback_samegroup_dyndescription():
|
|||
od2 = OptionDescription('od', '', [od1])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.owner.get()
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [],
|
||||
'od.stval1.st1val1.st2val1': [],
|
||||
'od.stval1.st1val1.st3val1': [],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': [None],
|
||||
'od.stval1.st1val1.st3val1': [None],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None, 'od.stval1.st1val1.st3val1': None}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
|
||||
assert cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': ['yes'],
|
||||
'od.stval1.st1val1.st3val1': ['yes'],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': 'yes', 'od.stval1.st1val1.st3val1': 'yes'}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
|
||||
|
@ -1712,14 +1694,14 @@ def test_leadership_dyndescription_convert():
|
|||
cfg = Config(od1)
|
||||
owner = cfg.owner.get()
|
||||
#
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == ['yes']
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).value.get() == None
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
|
@ -1771,36 +1753,21 @@ def test_leadership_callback_samegroup_dyndescription_convert():
|
|||
od2 = OptionDescription('od', '', [od1])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.owner.get()
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [],
|
||||
'od.stval1.st1val1.st2val1': [],
|
||||
'od.stval1.st1val1.st3val1': [],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').value.get() == []
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').value.get() == []
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st1val1').value.set(['yes'])
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': [None],
|
||||
'od.stval1.st1val1.st3val1': [None],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': None, 'od.stval1.st1val1.st3val1': None}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.isdefault()
|
||||
assert cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
|
||||
assert cfg.option('od.stval2.st1val2.st1val2').owner.isdefault()
|
||||
#
|
||||
cfg.option('od.stval1.st1val1.st2val1', 0).value.set('yes')
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': ['yes'],
|
||||
'od.stval1.st1val1.st3val1': ['yes'],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.value.dict() == {'od.stval1.st1val1.st1val1': [{'od.stval1.st1val1.st1val1': 'yes', 'od.stval1.st1val1.st2val1': 'yes', 'od.stval1.st1val1.st3val1': 'yes'}], 'od.stval2.st1val2.st1val2': []}
|
||||
assert cfg.option('od.stval1.st1val1.st1val1').owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st2val1', 0).owner.get() == owner
|
||||
assert cfg.option('od.stval1.st1val1.st3val1', 0).owner.isdefault()
|
||||
|
@ -1824,7 +1791,7 @@ def test_dyn_with_leader_hidden_in_config():
|
|||
cfg.option('leaderval1.ip_admin_eth0val1.ip_admin_eth0val1').value.get()
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get()
|
||||
cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
|
||||
cfg.value.dict() == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
|
||||
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': [{'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': '192.168.1.1'}]}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
@ -1858,12 +1825,7 @@ def test_dyn_leadership_requires():
|
|||
assert cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get() is None
|
||||
cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get() == '255.255.255.255'
|
||||
assert cfg.value.dict() == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': ['192.168.1.2', '192.168.1.2'],
|
||||
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': [None, '255.255.255.255'],
|
||||
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': [],
|
||||
'leaderval2.ip_admin_eth0val2.netmask_admin_eth0val2': []}
|
||||
|
||||
ret = cfg.value.dict(leader_to_list=True)
|
||||
ret = cfg.value.dict()
|
||||
assert ret == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
|
||||
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': '255.255.255.255'}],
|
||||
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
|
||||
|
@ -1873,24 +1835,8 @@ def test_dyn_leadership_requires():
|
|||
assert cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 0).value.get() is None
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 1).value.get()
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['leaderval1.ip_admin_eth0val1.ip_admin_eth0val1', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1', 'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2', 'leaderval2.ip_admin_eth0val2.netmask_admin_eth0val2'])
|
||||
assert ret['leaderval1.ip_admin_eth0val1.ip_admin_eth0val1'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1']) == 2
|
||||
assert ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][0] is None
|
||||
assert isinstance(ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][1], PropertiesOptionError)
|
||||
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][1]
|
||||
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1'][0]
|
||||
del ret['leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1']
|
||||
assert cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2',
|
||||
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
|
||||
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
|
||||
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
|
||||
assert cfg.value.dict() == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2', 'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None}, {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}], 'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
|
||||
#
|
||||
assert cfg.value.dict(leader_to_list=True) == {'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': [{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.2',
|
||||
'leaderval1.ip_admin_eth0val1.netmask_admin_eth0val1': None},
|
||||
{'leaderval1.ip_admin_eth0val1.ip_admin_eth0val1': '192.168.1.1'}],
|
||||
'leaderval2.ip_admin_eth0val2.ip_admin_eth0val2': []}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
@ -62,17 +62,7 @@ def test_base_config(config_type):
|
|||
if config_type != 'tiramisu-api':
|
||||
ret = cfg.option.find('nom_machine', first=True)
|
||||
assert ret.value.get() == "eoleng"
|
||||
result = {'general.numero_etab': None, 'general.nombre_interfaces': 1,
|
||||
'general.serveur_ntp': [], 'interface1.ip_admin_eth0.ip_admin_eth0': None,
|
||||
'general.mode_conteneur_actif': False, 'general.time_zone': 'Paris',
|
||||
'interface1.ip_admin_eth0.netmask_admin_eth0': None, 'general.nom_machine':
|
||||
'eoleng', 'general.activer_proxy_client': False}
|
||||
assert cfg.option('creole').value.dict() == result
|
||||
result = {'serveur_ntp': [], 'mode_conteneur_actif': False,
|
||||
'ip_admin_eth0': None, 'time_zone': 'Paris', 'numero_etab': None,
|
||||
'netmask_admin_eth0': None, 'nom_machine': 'eoleng', 'activer_proxy_client':
|
||||
False, 'nombre_interfaces': 1}
|
||||
assert cfg.option('creole').value.dict(flatten=True) == result
|
||||
assert cfg.option('creole').value.dict() == {'creole.general.numero_etab': None, 'creole.general.nom_machine': 'eoleng', 'creole.general.nombre_interfaces': 1, 'creole.general.activer_proxy_client': False, 'creole.general.mode_conteneur_actif': False, 'creole.general.serveur_ntp': [], 'creole.general.time_zone': 'Paris', 'creole.interface1.ip_admin_eth0.ip_admin_eth0': None, 'creole.interface1.ip_admin_eth0.netmask_admin_eth0': None}
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
# assert not list_sessions()
|
||||
|
@ -94,11 +84,13 @@ def test_iter_on_groups():
|
|||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
result = cfg.option('creole').list('optiondescription',
|
||||
group_type=groups.family)
|
||||
group_type=groups.family,
|
||||
)
|
||||
group_names = [res.option.name() for res in result]
|
||||
assert group_names == ['general', 'interface1']
|
||||
for i in cfg.option('creole').list('optiondescription',
|
||||
group_type=groups.family):
|
||||
group_type=groups.family,
|
||||
):
|
||||
#test StopIteration
|
||||
break
|
||||
result = cfg.option('creole').list('option',
|
||||
|
@ -125,7 +117,7 @@ def test_list_recursive():
|
|||
'netmask_admin_eth0']
|
||||
result = list(cfg.option.list(recursive=True, type='optiondescription'))
|
||||
group_names = [res.option.name() for res in result]
|
||||
assert group_names == ['general', 'ip_admin_eth0', 'interface1', 'creole']
|
||||
assert group_names == ['creole', 'general', 'interface1', 'ip_admin_eth0']
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -185,12 +177,8 @@ def test_iter_not_group():
|
|||
od1 = OptionDescription("name", "descr", [])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
try:
|
||||
list(cfg.option.list(type='optiondescription', group_type='family'))
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
raise Exception('must raise')
|
||||
with pytest.raises(AssertionError):
|
||||
print(list(cfg.option.list(type='optiondescription', group_type='family')))
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -257,8 +245,7 @@ def test_groups_with_leader_make_dict(config_type):
|
|||
od1 = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': []}
|
||||
assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': []}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': []}
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME useful? already in leadership
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 0
|
||||
|
@ -268,8 +255,7 @@ def test_groups_with_leader_make_dict(config_type):
|
|||
# FIXME
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.len() == 2
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.len() == 2
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip1', 'ip2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None]}
|
||||
assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'ip2', 'ip_admin_eth0.netmask_admin_eth0': None}]}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'ip2', 'ip_admin_eth0.netmask_admin_eth0': None}]}
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
# assert not list_sessions()
|
||||
|
@ -292,8 +278,7 @@ def test_groups_with_leader_make_dict2(config_type):
|
|||
od1 = OptionDescription('root', '', [interface1])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'other.ip_admin_eth0': [], 'other.netmask_admin_eth0': []}
|
||||
assert cfg.value.dict(leader_to_list=True) == {'other.ip_admin_eth0': []}
|
||||
assert cfg.value.dict() == {'other.ip_admin_eth0': []}
|
||||
if config_type != 'tiramisu-api':
|
||||
# FIXME useful? already in leadership
|
||||
assert cfg.option('other.ip_admin_eth0').value.len() == 0
|
||||
|
@ -303,8 +288,7 @@ def test_groups_with_leader_make_dict2(config_type):
|
|||
# FIXME
|
||||
assert cfg.option('other.ip_admin_eth0').value.len() == 2
|
||||
assert cfg.option('other.netmask_admin_eth0').value.len() == 2
|
||||
assert cfg.value.dict() == {'other.ip_admin_eth0': ['ip1', 'ip2'], 'other.netmask_admin_eth0': [None, None]}
|
||||
assert cfg.value.dict(leader_to_list=True) == {'other.ip_admin_eth0': [{'other.ip_admin_eth0': 'ip1', 'other.netmask_admin_eth0': None}, {'other.ip_admin_eth0': 'ip2', 'other.netmask_admin_eth0': None}]}
|
||||
assert cfg.value.dict() == {'other.ip_admin_eth0': [{'other.ip_admin_eth0': 'ip1', 'other.netmask_admin_eth0': None}, {'other.ip_admin_eth0': 'ip2', 'other.netmask_admin_eth0': None}]}
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
# assert not list_sessions()
|
||||
|
@ -344,13 +328,11 @@ def test_groups_with_leader_default_value_2(config_type):
|
|||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('netmask2')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'netmask2'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.default() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.default() == 'netmask1'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0').value.default() == ['netmask1', 'netmask1']
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
# assert not list_sessions()
|
||||
|
@ -372,7 +354,6 @@ def test_groups_with_leader_hidden_in_config():
|
|||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
assert cfg.value.dict() == {}
|
||||
assert cfg.value.dict(leader_to_list=True) == {}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
@ -5,9 +5,9 @@ do_autopath()
|
|||
|
||||
import pytest
|
||||
from tiramisu import Config
|
||||
from tiramisu import IntOption, StrOption, OptionDescription, \
|
||||
from tiramisu import IntOption, StrOption, OptionDescription, DynOptionDescription, \
|
||||
SymLinkOption, Leadership, undefined, Calculation, Params, \
|
||||
ParamOption, ParamValue, calc_value
|
||||
ParamOption, ParamValue, ParamIndex, calc_value
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError
|
||||
from tiramisu.setting import groups
|
||||
|
||||
|
@ -36,14 +36,14 @@ def return_value(value):
|
|||
|
||||
|
||||
def make_description2():
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
stroption = StrOption('str', 'str', default="abc",
|
||||
properties=('mandatory', ))
|
||||
stroption1 = StrOption('str1', 'Test string option',
|
||||
stroption1 = StrOption('str1', 'str1',
|
||||
properties=('mandatory', ))
|
||||
stroption2 = SymLinkOption('unicode2', stroption1)
|
||||
stroption3 = StrOption('str3', 'Test string option', multi=True,
|
||||
stroption3 = StrOption('str3', 'str3', multi=True,
|
||||
properties=('mandatory', ))
|
||||
unicode1 = StrOption('unicode1', 'Test string option', Calculation(return_value, Params(ParamOption(stroption))), properties=('mandatory',))
|
||||
unicode1 = StrOption('unicode1', 'unicode1', Calculation(return_value, Params(ParamOption(stroption))), properties=('mandatory',))
|
||||
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
|
||||
return descr
|
||||
|
||||
|
@ -319,6 +319,18 @@ def test_mandatory_unicode():
|
|||
# assert not list_sessions()
|
||||
|
||||
|
||||
def compare(ret, expected):
|
||||
assert(len(ret) == len(expected))
|
||||
for index, opt in enumerate(ret):
|
||||
exp = expected[index]
|
||||
if isinstance(exp, list):
|
||||
assert opt.option.path() == exp[0]
|
||||
assert opt.option.index() == exp[1]
|
||||
else:
|
||||
assert opt.option.path() == exp
|
||||
assert opt.option.index() == None
|
||||
|
||||
|
||||
def test_mandatory_warnings_ro():
|
||||
od1 = make_description()
|
||||
cfg = Config(od1)
|
||||
|
@ -330,11 +342,11 @@ def test_mandatory_warnings_ro():
|
|||
except PropertiesOptionError as err:
|
||||
prop = err.proptype
|
||||
assert 'mandatory' in prop
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.set('a')
|
||||
cfg.property.read_only()
|
||||
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -344,9 +356,9 @@ def test_mandatory_warnings_rw():
|
|||
cfg.option('str').value.set('')
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.get()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
cfg.option('str').value.set('a')
|
||||
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -356,9 +368,9 @@ def test_mandatory_warnings_disabled():
|
|||
cfg.option('str').value.set('')
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.get()
|
||||
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
cfg.option('str').property.add('disabled')
|
||||
assert set(cfg.value.mandatory()) == {'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -369,9 +381,9 @@ def test_mandatory_warnings_hidden():
|
|||
cfg.property.read_write()
|
||||
cfg.permissive.add('hidden')
|
||||
cfg.option('str').value.get()
|
||||
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
cfg.option('str').property.add('hidden')
|
||||
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -381,10 +393,10 @@ def test_mandatory_warnings_frozen():
|
|||
cfg.option('str').value.set('')
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.get()
|
||||
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
cfg.option('str').property.add('frozen')
|
||||
cfg.property.read_only()
|
||||
assert set(cfg.value.mandatory()) == {'str', 'str1', 'unicode2', 'str3'}
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -429,7 +441,7 @@ def test_mandatory_warnings_leader():
|
|||
interface1 = Leadership('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od1 = OptionDescription('o', '', [interface1])
|
||||
cfg = Config(od1)
|
||||
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -492,17 +504,17 @@ def test_mandatory_warnings_leader_empty():
|
|||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([undefined])
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == [None]
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
#
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set([''])
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['']
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.ip_admin_eth0']
|
||||
compare(cfg.value.mandatory(), ['ip_admin_eth0.ip_admin_eth0'])
|
||||
#
|
||||
cfg.property.read_write()
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(cfg.value.mandatory()) == []
|
||||
compare(cfg.value.mandatory(), [])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -515,8 +527,7 @@ def test_mandatory_follower():
|
|||
cfg = Config(od1)
|
||||
cfg.property.read_only()
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [],
|
||||
'ip_admin_eth0.netmask_admin_eth0': []}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': []}
|
||||
#
|
||||
cfg.property.read_write()
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
|
@ -537,8 +548,7 @@ def test_mandatory_follower():
|
|||
cfg.property.read_only()
|
||||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == ['ip']
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == 'ip'
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['ip'],
|
||||
'ip_admin_eth0.netmask_admin_eth0': ['ip']}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'ip', 'ip_admin_eth0.netmask_admin_eth0': 'ip'}]}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -553,9 +563,9 @@ def test_mandatory_warnings_follower():
|
|||
assert cfg.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||
#
|
||||
cfg.property.read_write()
|
||||
assert list(cfg.value.mandatory()) == []
|
||||
compare(cfg.value.mandatory(), [])
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['ip'])
|
||||
assert list(cfg.value.mandatory()) == ['ip_admin_eth0.netmask_admin_eth0']
|
||||
compare(cfg.value.mandatory(), [['ip_admin_eth0.netmask_admin_eth0', 0]])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -565,10 +575,10 @@ def test_mandatory_warnings_symlink():
|
|||
cfg.option('str').value.set('')
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.get()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'str3'])
|
||||
cfg.option('str').property.add('frozen')
|
||||
cfg.property.read_only()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -577,7 +587,7 @@ def test_mandatory_warnings_validate_empty():
|
|||
cfg = Config(od1)
|
||||
cfg.option('str').value.set('')
|
||||
cfg.property.read_only()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'str3', 'unicode1'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -599,12 +609,12 @@ def test_mandatory_warnings_requires():
|
|||
cfg.option('str').value.set('')
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.get()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2'])
|
||||
cfg.property.read_only()
|
||||
assert list(cfg.value.mandatory()) == ['str', 'str1', 'unicode2']
|
||||
compare(cfg.value.mandatory(), ['str', 'str1', 'unicode2'])
|
||||
cfg.property.read_write()
|
||||
cfg.option('str').value.set('yes')
|
||||
assert list(cfg.value.mandatory()) == ['str1', 'unicode2', 'str3']
|
||||
compare(cfg.value.mandatory(), ['str1', 'unicode2', 'str3'])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -624,9 +634,9 @@ def test_mandatory_warnings_requires_leadership():
|
|||
cfg = Config(od1)
|
||||
cfg.option('str').value.set('')
|
||||
cfg.option('leader.str1').value.set(['str'])
|
||||
assert list(cfg.value.mandatory()) == ['str']
|
||||
compare(cfg.value.mandatory(), ['str'])
|
||||
cfg.option('str').value.set('yes')
|
||||
assert list(cfg.value.mandatory()) == ['leader.str2']
|
||||
compare(cfg.value.mandatory(), [['leader.str2', 0]])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -644,9 +654,21 @@ def test_mandatory_warnings_requires_leadership_follower():
|
|||
od1 = OptionDescription('tiram', '', [leadership])
|
||||
cfg = Config(od1)
|
||||
cfg.option('leader.str').value.set(['str'])
|
||||
assert list(cfg.value.mandatory()) == []
|
||||
compare(cfg.value.mandatory(), [])
|
||||
cfg.option('leader.str1', 0).value.set('yes')
|
||||
assert list(cfg.value.mandatory()) == ['leader.str2']
|
||||
compare(cfg.value.mandatory(), [['leader.str2', 0]])
|
||||
cfg.option('leader.str2', 0).value.set('yes')
|
||||
compare(cfg.value.mandatory(), [])
|
||||
#
|
||||
cfg.option('leader.str').value.set(['str', 'str1'])
|
||||
compare(cfg.value.mandatory(), [])
|
||||
cfg.option('leader.str1', 1).value.set('yes')
|
||||
compare(cfg.value.mandatory(), [['leader.str2', 1]])
|
||||
cfg.option('leader.str2', 1).value.set('yes')
|
||||
compare(cfg.value.mandatory(), [])
|
||||
cfg.option('leader.str2', 0).value.reset()
|
||||
cfg.option('leader.str2', 1).value.reset()
|
||||
compare(cfg.value.mandatory(), [['leader.str2', 0], ['leader.str2', 1]])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -655,7 +677,49 @@ def test_mandatory_od_disabled():
|
|||
od1 = OptionDescription('od', '', [descr])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_only()
|
||||
assert list(cfg.value.mandatory()) == ['tiram.str1', 'tiram.unicode2', 'tiram.str3']
|
||||
compare(cfg.value.mandatory(), ['tiram.str1', 'tiram.unicode2', 'tiram.str3'])
|
||||
cfg.option('tiram').property.add('disabled')
|
||||
assert list(cfg.value.mandatory()) == []
|
||||
compare(cfg.value.mandatory(), [])
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
def return_list(val=None, suffix=None):
|
||||
if val:
|
||||
return val
|
||||
else:
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def test_mandatory_dyndescription():
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.property.read_only()
|
||||
compare(cfg.value.mandatory(), ['od.dodval1.stval1', 'od.dodval2.stval2'])
|
||||
|
||||
|
||||
def test_mandatory_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.property.read_only()
|
||||
compare(cfg.value.mandatory(), ['od.dodval1.stval1', 'od.dodval2.stval2'])
|
||||
|
||||
|
||||
def test_mandatory_callback_leader_and_followers_leader():
|
||||
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
||||
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
||||
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
|
||||
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
|
||||
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
||||
od1 = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
# FIXME cfg = get_config(cfg, config_type)
|
||||
compare(cfg.value.mandatory(), ['val1.val1'])
|
||||
# assert not list_sessions()
|
||||
|
|
|
@ -88,7 +88,7 @@ def test_none():
|
|||
assert meta.option('od1.i3').value.get() is conf1.option('od1.i3').value.get() is conf2.option('od1.i3').value.get() is None
|
||||
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.default
|
||||
#
|
||||
meta.option('od1.i3').value.set(3)
|
||||
assert meta.option('od1.i3').value.set(3) == []
|
||||
assert meta.option('od1.i3').value.get() == conf1.option('od1.i3').value.get() == conf2.option('od1.i3').value.get() == 3
|
||||
assert meta.option('od1.i3').owner.get() is conf1.option('od1.i3').owner.get() is conf2.option('od1.i3').owner.get() is owners.meta1
|
||||
#
|
||||
|
@ -870,7 +870,7 @@ def test_meta_properties_requires_mandatory():
|
|||
meta.option('ip_gw').value.set('1.1.1.2')
|
||||
conf1.option('eth0_method').value.set('dhcp')
|
||||
conf1.property.read_only()
|
||||
assert conf1.value.dict(fullpath=True) == {'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1', 'ip_gw': '1.1.1.2'}
|
||||
assert conf1.value.dict() == {'ip_gw': '1.1.1.2', 'probes': True, 'eth0_method': 'dhcp', 'ip_address': '1.1.1.1', 'ip_eth0': '1.1.1.1'}
|
||||
|
||||
|
||||
def test_meta_callback():
|
||||
|
@ -909,51 +909,51 @@ def test_meta_callback_follower():
|
|||
conf1 = Config(maconfig, name='conf1')
|
||||
meta = MetaConfig([conf1])
|
||||
meta.property.read_write()
|
||||
assert conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
conf1.option('val').value.set('val1')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]}
|
||||
#
|
||||
conf1.option('val').value.reset()
|
||||
meta.option('val').value.set('val1')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
assert conf1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]}
|
||||
#
|
||||
meta.option('val').value.reset()
|
||||
conf1.option('val1.val2', 0).value.set('val2')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
conf1.option('val1.val2', 0).value.reset()
|
||||
assert conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
meta.option('val1.val2', 0).value.set('val2')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
meta.option('val1.val1').value.set(['val'])
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
conf1.option('val1.val3', 0).value.set('val6')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]}
|
||||
#
|
||||
meta.option('val1.val2', 0).value.reset()
|
||||
conf1.option('val1.val3', 0).value.reset()
|
||||
conf1.option('val1.val1').value.set(['val3'])
|
||||
assert conf1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
conf1.option('val1.val1').value.reset()
|
||||
assert conf1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
meta.option('val1.val1').value.set(['val3'])
|
||||
assert conf1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
conf1.option('val1.val2', 0).value.set('val2')
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
meta.option('val1.val1').value.set(['val3', 'rah'])
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]}
|
||||
#
|
||||
meta.option('val1.val1').value.pop(1)
|
||||
meta.option('val1.val1').value.set(['val4'])
|
||||
assert conf1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
|
||||
assert conf1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]}
|
||||
|
||||
|
||||
def test_meta_reset():
|
||||
|
|
|
@ -709,51 +709,51 @@ def test_mix_callback_follower():
|
|||
mix = MixConfig(maconfig, [cfg])
|
||||
mix.property.read_write()
|
||||
newcfg1 = mix.config('cfg1')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
newcfg1.option('val').value.set('val1')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]}
|
||||
#
|
||||
newcfg1.option('val').value.reset()
|
||||
mix.option('val').value.set('val1')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val1'], 'val1.val1': ['val1'], 'val1.val3': ['val1'], 'val': 'val1'}
|
||||
assert newcfg1.value.dict() == {'val': 'val1', 'val1.val1': [{'val1.val1': 'val1', 'val1.val2': 'val1', 'val1.val3': 'val1'}]}
|
||||
#
|
||||
mix.option('val').value.reset()
|
||||
newcfg1.option('val1.val2', 0).value.set('val2')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
newcfg1.option('val1.val2', 0).value.reset()
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
mix.option('val1.val2', 0).value.set('val2')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
mix.option('val1.val1').value.set(['val'])
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val'}]}
|
||||
#
|
||||
newcfg1.option('val1.val3', 0).value.set('val6')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val'], 'val1.val3': ['val6'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val2', 'val1.val3': 'val6'}]}
|
||||
#
|
||||
mix.option('val1.val2', 0).value.reset()
|
||||
newcfg1.option('val1.val3', 0).value.reset()
|
||||
newcfg1.option('val1.val1').value.set(['val3'])
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
newcfg1.option('val1.val1').value.reset()
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val'], 'val1.val1': ['val'], 'val1.val3': ['val'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val', 'val1.val2': 'val', 'val1.val3': 'val'}]}
|
||||
#
|
||||
mix.option('val1.val1').value.set(['val3'])
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val3'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val3', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
newcfg1.option('val1.val2', 0).value.set('val2')
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val3'], 'val1.val3': ['val3'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}]}
|
||||
#
|
||||
mix.option('val1.val1').value.set(['val3', 'rah'])
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2', 'rah'], 'val1.val1': ['val3', 'rah'], 'val1.val3': ['val3', 'rah'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val3', 'val1.val2': 'val2', 'val1.val3': 'val3'}, {'val1.val1': 'rah', 'val1.val2': 'rah', 'val1.val3': 'rah'}]}
|
||||
#
|
||||
mix.option('val1.val1').value.pop(1)
|
||||
mix.option('val1.val1').value.set(['val4'])
|
||||
assert newcfg1.value.dict() == {'val1.val2': ['val2'], 'val1.val1': ['val4'], 'val1.val3': ['val4'], 'val': 'val'}
|
||||
assert newcfg1.value.dict() == {'val': 'val', 'val1.val1': [{'val1.val1': 'val4', 'val1.val2': 'val2', 'val1.val3': 'val4'}]}
|
||||
|
||||
|
||||
def test_meta_reset():
|
||||
|
|
|
@ -776,20 +776,6 @@ def test_callback_leader_and_followers_leader_mandatory4(config_type):
|
|||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_callback_leader_and_followers_leader3():
|
||||
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
||||
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
||||
val3 = StrOption('val3', "", Calculation(calc_value, Params(ParamOption(val2), {'index': ParamIndex()})), multi=True)
|
||||
val4 = StrOption('val4', "", Calculation(calc_value, Params(ParamOption(val3), {'index': ParamIndex()})), multi=True)
|
||||
interface1 = Leadership('val1', '', [val1, val2, val3, val4])
|
||||
od1 = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
# FIXME cfg = get_config(cfg, config_type)
|
||||
assert list(cfg.value.mandatory()) == ['val1.val1']
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_callback_leader_and_followers_leader4():
|
||||
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
|
||||
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
|
||||
|
@ -996,7 +982,7 @@ def test_callback_leader_and_followers_leader_callback_disabled():
|
|||
with pytest.raises(ConfigError):
|
||||
cfg.option('val1.val1').value.get()
|
||||
with pytest.raises(ConfigError):
|
||||
cfg.option('val1.val2').value.get()
|
||||
cfg.option('val1.val2', 0).value.get()
|
||||
cfg.property.remove('disabled')
|
||||
cfg.option('val1.val1').value.set([])
|
||||
cfg.property.add('disabled')
|
||||
|
|
|
@ -219,7 +219,7 @@ def test_setowner_symlinkoption(config_type):
|
|||
assert not cfg.option('tiramisu.symdummy').owner.isdefault()
|
||||
if config_type == 'tiramisu-api':
|
||||
cfg.send()
|
||||
with pytest.raises(ConfigError):
|
||||
with pytest.raises(APIError):
|
||||
cfg_ori.option('tiramisu.symdummy').owner.set('user')
|
||||
# assert not list_sessions()
|
||||
|
||||
|
|
|
@ -709,7 +709,7 @@ def test_pprint():
|
|||
kwargs={'condition': ParamOption(intoption, todict=True),
|
||||
'expected': ParamValue(1)}),
|
||||
calc_value_property_help)
|
||||
descr2 = OptionDescription("options", "", [val2], properties=(hidden_property,))
|
||||
descr2 = OptionDescription("options", "options", [val2], properties=(hidden_property,))
|
||||
#descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
||||
|
||||
hidden_property = Calculation(calc_value,
|
||||
|
@ -721,7 +721,7 @@ def test_pprint():
|
|||
val3 = StrOption('val3', "", properties=(hidden_property,))
|
||||
#val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
|
||||
od1 = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
od1 = OptionDescription("options", "root option", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
cfg.option('int').value.set(1)
|
||||
|
|
|
@ -1106,39 +1106,19 @@ def test_leadership_requires(config_type):
|
|||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() is None
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('255.255.255.255')
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == '255.255.255.255'
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.2'],
|
||||
'ip_admin_eth0.netmask_admin_eth0': [None, '255.255.255.255']}
|
||||
assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': None},
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': None},
|
||||
{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2', 'ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'}]}
|
||||
#
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.2', '192.168.1.1'])
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
assert ret['ip_admin_eth0.netmask_admin_eth0'][0] is None
|
||||
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][1]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2',
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2',
|
||||
'ip_admin_eth0.netmask_admin_eth0': None},
|
||||
{'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]}
|
||||
#
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.255')
|
||||
ret = cfg.value.dict()
|
||||
assert set(ret.keys()) == set(['ip_admin_eth0.ip_admin_eth0', 'ip_admin_eth0.netmask_admin_eth0'])
|
||||
assert ret['ip_admin_eth0.ip_admin_eth0'] == ['192.168.1.2', '192.168.1.1']
|
||||
assert len(ret['ip_admin_eth0.netmask_admin_eth0']) == 2
|
||||
assert ret['ip_admin_eth0.netmask_admin_eth0'][0] == '255.255.255.255'
|
||||
assert isinstance(ret['ip_admin_eth0.netmask_admin_eth0'][1], PropertiesOptionError)
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][1]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0'][0]
|
||||
del ret['ip_admin_eth0.netmask_admin_eth0']
|
||||
assert cfg.value.dict(leader_to_list=True) == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2',
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2',
|
||||
'ip_admin_eth0.netmask_admin_eth0': '255.255.255.255'},
|
||||
{'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]}
|
||||
# assert not list_sessions()
|
||||
|
@ -1258,7 +1238,7 @@ def test_leadership_requires_no_leader(config_type):
|
|||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get()
|
||||
with pytest.raises(PropertiesOptionError):
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get()
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['192.168.1.2', '192.168.1.1'], 'activate': False}
|
||||
assert cfg.value.dict() == {'activate': False, 'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': '192.168.1.2'}, {'ip_admin_eth0.ip_admin_eth0': '192.168.1.1'}]}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -1319,53 +1299,10 @@ def test_leadership_requires_complet(config_type):
|
|||
cfg = get_config(cfg, config_type)
|
||||
cfg.option('options.unicode.unicode').value.set(['test', 'trah'])
|
||||
cfg.option('options.unicode.unicode2', 0).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
assert dico['options.unicode.unicode2'] == ['test', None]
|
||||
assert dico['options.unicode.unicode3'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode6'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode6'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode7'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode7'][1], PropertiesOptionError)
|
||||
assert dico['options.unicodetoto'] is None
|
||||
del dico['options.unicode.unicode3'][1]
|
||||
del dico['options.unicode.unicode3']
|
||||
del dico['options.unicode.unicode4'][1]
|
||||
del dico['options.unicode.unicode4']
|
||||
del dico['options.unicode.unicode6'][1]
|
||||
del dico['options.unicode.unicode6'][0]
|
||||
del dico['options.unicode.unicode7'][1]
|
||||
del dico['options.unicode.unicode7'][0]
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': None}
|
||||
#
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert dico.keys() == set(['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicode.unicode5', 'options.unicode.unicode6', 'options.unicode.unicode7', 'options.unicodetoto'])
|
||||
assert dico['options.unicode.unicode'] == ['test', 'trah']
|
||||
assert dico['options.unicode.unicode1'] == [None, None]
|
||||
assert dico['options.unicode.unicode2'] == ['test', None]
|
||||
assert dico['options.unicode.unicode3'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode5'] == [None, None]
|
||||
assert dico['options.unicode.unicode6'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode6'][1], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode7'][0] is None
|
||||
assert isinstance(dico['options.unicode.unicode7'][1], PropertiesOptionError)
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
del dico['options.unicode.unicode3'][1]
|
||||
del dico['options.unicode.unicode3']
|
||||
del dico['options.unicode.unicode4'][1]
|
||||
del dico['options.unicode.unicode4']
|
||||
del dico['options.unicode.unicode6'][1]
|
||||
del dico['options.unicode.unicode6'][0]
|
||||
del dico['options.unicode.unicode7'][1]
|
||||
del dico['options.unicode.unicode7'][0]
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'test', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': None, 'options.unicode.unicode4': None, 'options.unicode.unicode5': None, 'options.unicode.unicode6': None, 'options.unicode.unicode7': None}, {'options.unicode.unicode': 'trah', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None, 'options.unicode.unicode5': None}], 'options.unicodetoto': 'test'}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
@ -1402,91 +1339,24 @@ def test_leadership_requires_transitive1(config_type):
|
|||
cfg = Config(od1)
|
||||
cfg.property.read_write()
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': None}
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicodetoto': None}
|
||||
#
|
||||
cfg.option('options.unicodetoto').value.set('test')
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicode.unicode1': [], 'options.unicode.unicode2': [], 'options.unicode.unicode3': [], 'options.unicode.unicode4': [], 'options.unicodetoto': 'test'}
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [], 'options.unicodetoto': 'test'}
|
||||
#
|
||||
cfg.option('options.unicode.unicode').value.set(['a', 'b', 'c'])
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, None, None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'}
|
||||
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicode.unicode3', 1).value.set('test')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, 'test', None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode3'][1] == 'test'
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert dico['options.unicode.unicode4'][1] == None
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'test', 'options.unicode.unicode3': 'test', 'options.unicode.unicode4': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'}
|
||||
#
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode2', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'test'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert dico['options.unicode.unicode2'] == [None, 'rah', None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None, 'options.unicode.unicode2': 'rah'}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None, 'options.unicode.unicode2': None}], 'options.unicodetoto': 'test'}
|
||||
#
|
||||
cfg.option('options.unicode.unicode2', 1).value.set('test')
|
||||
cfg.option('options.unicodetoto').value.set('rah')
|
||||
dico = cfg.value.dict()
|
||||
assert list(dico.keys()) == ['options.unicode.unicode', 'options.unicode.unicode1', 'options.unicode.unicode3', 'options.unicode.unicode4', 'options.unicodetoto']
|
||||
assert dico['options.unicodetoto'] == 'rah'
|
||||
assert dico['options.unicode.unicode'] == ['a', 'b', 'c']
|
||||
assert dico['options.unicode.unicode1'] == [None, None, None]
|
||||
assert isinstance(dico['options.unicode.unicode3'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode3'][2], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][0], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][1], PropertiesOptionError)
|
||||
assert isinstance(dico['options.unicode.unicode4'][2], PropertiesOptionError)
|
||||
del (dico['options.unicode.unicode3'][2])
|
||||
del (dico['options.unicode.unicode3'][1])
|
||||
del (dico['options.unicode.unicode3'][0])
|
||||
del (dico['options.unicode.unicode4'][2])
|
||||
del (dico['options.unicode.unicode4'][1])
|
||||
del (dico['options.unicode.unicode4'][0])
|
||||
assert cfg.value.dict() == {'options.unicode.unicode': [{'options.unicode.unicode': 'a', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'b', 'options.unicode.unicode1': None}, {'options.unicode.unicode': 'c', 'options.unicode.unicode1': None}], 'options.unicodetoto': 'rah'}
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ try:
|
|||
except:
|
||||
tiramisu_version = 2
|
||||
from tiramisu import Config
|
||||
from tiramisu.config import SubConfig
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption,\
|
||||
StrOption, SymLinkOption, StrOption, IPOption, OptionDescription, \
|
||||
PortOption, NetworkOption, NetmaskOption, DomainnameOption, EmailOption, \
|
||||
|
@ -158,28 +157,6 @@ def test_slots_option_readonly():
|
|||
# assert slots == set(OptionDescription.__slots__)
|
||||
|
||||
|
||||
def test_slots_config():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
cfg = Config(od2)
|
||||
with pytest.raises(AttributeError):
|
||||
cfg._config_bag.context.x = 1
|
||||
with pytest.raises(AttributeError):
|
||||
cfg._config_bag.context.x = 1
|
||||
option_bag = OptionBag(od2,
|
||||
'a',
|
||||
ConfigBag(cfg._config_bag.context, None, None),
|
||||
properties=None,
|
||||
)
|
||||
sc = cfg._config_bag.context.get_subconfig(option_bag)
|
||||
assert isinstance(sc, SubConfig)
|
||||
with pytest.raises(AttributeError):
|
||||
sc.x = 1
|
||||
with pytest.raises(AttributeError):
|
||||
sc.x = 1
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
def test_slots_setting():
|
||||
od1 = OptionDescription('a', '', [])
|
||||
od2 = OptionDescription('a', '', [od1])
|
||||
|
|
|
@ -43,7 +43,7 @@ def test_symlink_assign_option(config_type):
|
|||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
with pytest.raises(ConfigError):
|
||||
with pytest.raises(APIError):
|
||||
cfg.option('c').value.set(True)
|
||||
# assert not list_sessions()
|
||||
|
||||
|
@ -55,7 +55,7 @@ def test_symlink_del_option(config_type):
|
|||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
with pytest.raises(ConfigError):
|
||||
with pytest.raises(APIError):
|
||||
cfg.option('c').value.reset()
|
||||
# assert not list_sessions()
|
||||
|
||||
|
@ -191,7 +191,7 @@ def test_symlink_assign(config_type):
|
|||
[linkopt, OptionDescription("s1", "", [boolopt])])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
with pytest.raises(ConfigError):
|
||||
with pytest.raises(APIError):
|
||||
cfg.option('c').value.set(True)
|
||||
# assert not list_sessions()
|
||||
|
||||
|
@ -246,9 +246,9 @@ def test_symlink_with_leader(config_type):
|
|||
od1 = OptionDescription('root', '', [interface1, leader])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'leader': []}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'leader': []}
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'leader': ['val1', 'val2']}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'leader': ['val1', 'val2']}
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||
with pytest.raises(APIError):
|
||||
cfg.option('leader').value.pop(0)
|
||||
|
@ -263,36 +263,36 @@ def test_symlink_with_follower(config_type):
|
|||
od1 = OptionDescription('root', '', [interface1, follower])
|
||||
cfg = Config(od1)
|
||||
cfg = get_config(cfg, config_type)
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'ip_admin_eth0.netmask_admin_eth0': [], 'follower': []}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [], 'follower': []}
|
||||
cfg.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val2'])
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, None], 'follower': [None, None]}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': None}], 'follower': [None, None]}
|
||||
#
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'default'
|
||||
with pytest.raises(APIError):
|
||||
assert cfg.option('follower', 0).owner.get() == 'default'
|
||||
assert cfg.option('follower', 1).owner.get() == 'default'
|
||||
assert cfg.option('follower').owner.get() == ['default', 'default']
|
||||
assert cfg.option('follower').owner.get() == 'default'
|
||||
#
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||
with pytest.raises(APIError):
|
||||
assert cfg.option('follower', 0).value.get() == None
|
||||
assert cfg.option('follower', 1).value.get() == None
|
||||
assert cfg.option('follower').value.get() == [None, None]
|
||||
#
|
||||
cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set('val3')
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': ['val1', 'val2'], 'ip_admin_eth0.netmask_admin_eth0': [None, 'val3'], 'follower': [None, 'val3']}
|
||||
assert cfg.value.dict() == {'ip_admin_eth0.ip_admin_eth0': [{'ip_admin_eth0.ip_admin_eth0': 'val1', 'ip_admin_eth0.netmask_admin_eth0': None}, {'ip_admin_eth0.ip_admin_eth0': 'val2', 'ip_admin_eth0.netmask_admin_eth0': 'val3'}], 'follower': [None, 'val3']}
|
||||
#
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == 'val3'
|
||||
with pytest.raises(APIError):
|
||||
assert cfg.option('follower', 0).value.get() == None
|
||||
assert cfg.option('follower', 1).value.get() == 'val3'
|
||||
assert cfg.option('follower').value.get() == [None, 'val3']
|
||||
#
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == 'default'
|
||||
assert cfg.option('ip_admin_eth0.netmask_admin_eth0', 1).owner.get() == 'user'
|
||||
with pytest.raises(APIError):
|
||||
assert cfg.option('follower', 0).owner.get() == 'default'
|
||||
assert cfg.option('follower', 1).owner.get() == 'user'
|
||||
assert cfg.option('follower').owner.get() == ['default', 'user']
|
||||
assert cfg.option('follower').owner.get() == 'user'
|
||||
# assert not list_sessions()
|
||||
|
||||
|
||||
|
|
846
tiramisu/api.py
846
tiramisu/api.py
File diff suppressed because it is too large
Load diff
|
@ -243,7 +243,12 @@ def manager_callback(callbk: Param,
|
|||
return index
|
||||
return None
|
||||
|
||||
def calc_self(callbk, option, index, value, config_bag):
|
||||
def calc_self(callbk,
|
||||
option,
|
||||
index,
|
||||
value,
|
||||
config_bag,
|
||||
):
|
||||
# index must be apply only if follower
|
||||
is_follower = option.impl_is_follower()
|
||||
apply_index = calc_index(callbk, index, is_follower)
|
||||
|
@ -251,12 +256,40 @@ def manager_callback(callbk: Param,
|
|||
if config_bag is undefined:
|
||||
return undefined
|
||||
path = option.impl_getpath()
|
||||
option_bag = get_option_bag(config_bag,
|
||||
option_bag = OptionBag(option,
|
||||
None,
|
||||
config_bag,
|
||||
properties=None,
|
||||
)
|
||||
properties = config_bag.context.get_settings().getproperties(option_bag,
|
||||
uncalculated=True,
|
||||
)
|
||||
parent_option_bag, option_bag = get_option_bag(config_bag,
|
||||
option,
|
||||
callbk,
|
||||
apply_index,
|
||||
True,
|
||||
properties=properties,
|
||||
)
|
||||
if option.impl_is_follower() and apply_index is None:
|
||||
new_value = []
|
||||
for idx in range(config_bag.context.get_length_leadership(parent_option_bag)):
|
||||
parent_option_bag, option_bag = get_option_bag(config_bag,
|
||||
option,
|
||||
callbk,
|
||||
idx,
|
||||
True,
|
||||
properties=properties,
|
||||
)
|
||||
new_value.append(get_value(callbk,
|
||||
option_bag,
|
||||
path,
|
||||
))
|
||||
else:
|
||||
new_value = get_value(callbk,
|
||||
option_bag,
|
||||
path,
|
||||
)
|
||||
new_value = get_value(callbk, option_bag, path)
|
||||
if apply_index is None and is_follower:
|
||||
new_value[index] = value
|
||||
value = new_value
|
||||
|
@ -270,9 +303,7 @@ def manager_callback(callbk: Param,
|
|||
):
|
||||
try:
|
||||
# get value
|
||||
value = config_bag.context.getattr(path,
|
||||
option_bag,
|
||||
)
|
||||
value = config_bag.context.get_value(option_bag)
|
||||
except PropertiesOptionError as err:
|
||||
# raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation
|
||||
if callbk.notraisepropertyerror or callbk.raisepropertyerror:
|
||||
|
@ -293,8 +324,11 @@ def manager_callback(callbk: Param,
|
|||
|
||||
def get_option_bag(config_bag,
|
||||
opt,
|
||||
callbk,
|
||||
index_,
|
||||
self_calc):
|
||||
self_calc,
|
||||
properties=undefined,
|
||||
):
|
||||
# don't validate if option is option that we tried to validate
|
||||
config_bag = config_bag.copy()
|
||||
if for_settings:
|
||||
|
@ -305,12 +339,41 @@ def manager_callback(callbk: Param,
|
|||
if self_calc:
|
||||
config_bag.unrestraint()
|
||||
config_bag.remove_validation()
|
||||
option_bag = OptionBag(opt,
|
||||
index_,
|
||||
root_option_bag = OptionBag(config_bag.context.get_description(),
|
||||
None,
|
||||
config_bag,
|
||||
apply_requires=not self_calc, # if we are in properties calculation, cannot calculated properties
|
||||
)
|
||||
return option_bag
|
||||
try:
|
||||
options_bag = config_bag.context.get_sub_option_bag(root_option_bag,
|
||||
opt.impl_getpath(),
|
||||
index_,
|
||||
validate_properties=not self_calc,
|
||||
properties=properties,
|
||||
)
|
||||
except PropertiesOptionError as err:
|
||||
# raise PropertiesOptionError (which is catched) because must not add value None in carry_out_calculation
|
||||
if callbk.notraisepropertyerror or callbk.raisepropertyerror:
|
||||
raise err from err
|
||||
raise ConfigError(_('unable to carry out a calculation for "{}"'
|
||||
', {}').format(option.impl_get_display_name(), err), err) from err
|
||||
except ValueError as err:
|
||||
raise ValueError(_('the option "{0}" is used in a calculation but is invalid ({1})').format(option.impl_get_display_name(), err)) from err
|
||||
except AttributeError as err:
|
||||
if isinstance(callbk, ParamDynOption) and callbk.optional:
|
||||
# cannot acces, simulate a propertyerror
|
||||
raise PropertiesOptionError(options_bag[-1],
|
||||
['configerror'],
|
||||
config_bag.context.get_settings(),
|
||||
)
|
||||
raise ConfigError(_(f'unable to get value for calculating "{option.impl_get_display_name()}", {err}')) from err
|
||||
if self_calc:
|
||||
if len(options_bag) > 1:
|
||||
parent_option_bag = options_bag[-2]
|
||||
else:
|
||||
parent_option_bag = None
|
||||
return parent_option_bag, options_bag[-1]
|
||||
else:
|
||||
return options_bag[-1]
|
||||
|
||||
if isinstance(callbk, ParamValue):
|
||||
return callbk.value
|
||||
|
@ -345,11 +408,17 @@ def manager_callback(callbk: Param,
|
|||
if isinstance(callbk, ParamSelfOption):
|
||||
if leadership_must_have_index and option.impl_is_follower() and index is None:
|
||||
raise Break()
|
||||
value = calc_self(callbk, option, index, orig_value, config_bag)
|
||||
value = calc_self(callbk,
|
||||
option,
|
||||
index,
|
||||
orig_value,
|
||||
config_bag,
|
||||
)
|
||||
if not callbk.todict:
|
||||
return value
|
||||
return {'name': option.impl_get_display_name(),
|
||||
'value': value}
|
||||
'value': value,
|
||||
}
|
||||
|
||||
if isinstance(callbk, ParamOption):
|
||||
callbk_option = callbk.option
|
||||
|
@ -362,7 +431,8 @@ def manager_callback(callbk: Param,
|
|||
suffix = callbk.suffix
|
||||
callbk_option = callbk_option.to_dynoption(rootpath,
|
||||
suffix,
|
||||
subdyn)
|
||||
subdyn,
|
||||
)
|
||||
found = True
|
||||
elif option.impl_is_dynsymlinkoption():
|
||||
rootpath = option.rootpath
|
||||
|
@ -416,6 +486,7 @@ def manager_callback(callbk: Param,
|
|||
path = callbk_option.impl_getpath()
|
||||
option_bag = get_option_bag(config_bag,
|
||||
callbk_option,
|
||||
callbk,
|
||||
index_,
|
||||
False,
|
||||
)
|
||||
|
|
|
@ -52,7 +52,8 @@ class Cache:
|
|||
index,
|
||||
props,
|
||||
self_props,
|
||||
type_):
|
||||
type_,
|
||||
):
|
||||
no_cache = False, None, False
|
||||
if 'cache' in props or type_ == 'context_props':
|
||||
values = self._cache.get(path)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -169,7 +169,8 @@ class Leadership(OptionDescription):
|
|||
values: Values,
|
||||
index: int,
|
||||
option_bag: OptionBag,
|
||||
followers: Optional[List[Option]]=undefined) -> None:
|
||||
followers: Optional[List[Option]]=undefined,
|
||||
) -> None:
|
||||
if followers is undefined:
|
||||
# followers are not undefined only in SynDynLeadership
|
||||
followers = self.get_followers()
|
||||
|
@ -202,19 +203,22 @@ class Leadership(OptionDescription):
|
|||
def reset_cache(self,
|
||||
path: str,
|
||||
config_bag: 'ConfigBag',
|
||||
resetted_opts: List[Option]) -> None:
|
||||
resetted_opts: List[Option],
|
||||
) -> None:
|
||||
self._reset_cache(path,
|
||||
self.get_leader(),
|
||||
self.get_followers(),
|
||||
config_bag,
|
||||
resetted_opts)
|
||||
resetted_opts,
|
||||
)
|
||||
|
||||
def _reset_cache(self,
|
||||
path: str,
|
||||
leader: Option,
|
||||
followers: List[Option],
|
||||
config_bag: 'ConfigBag',
|
||||
resetted_opts: List[Option]) -> None:
|
||||
resetted_opts: List[Option],
|
||||
) -> None:
|
||||
super().reset_cache(path,
|
||||
config_bag,
|
||||
resetted_opts)
|
||||
|
|
|
@ -46,7 +46,8 @@ class SynDynOption:
|
|||
def __getattr__(self,
|
||||
name: str) -> Any:
|
||||
return getattr(self.opt,
|
||||
name)
|
||||
name,
|
||||
)
|
||||
|
||||
def __eq__(self,
|
||||
left: BaseOption) -> bool:
|
||||
|
@ -68,7 +69,10 @@ class SynDynOption:
|
|||
return self.suffix
|
||||
|
||||
def impl_getpath(self) -> str:
|
||||
return self.rootpath + '.' + self.impl_getname()
|
||||
path = self.impl_getname()
|
||||
if self.rootpath:
|
||||
path = f'{self.rootpath}.{path}'
|
||||
return path
|
||||
|
||||
def impl_is_dynsymlinkoption(self) -> bool:
|
||||
return True
|
||||
|
|
|
@ -40,9 +40,6 @@ class SynDynOptionDescription:
|
|||
suffix: str,
|
||||
ori_dyn) -> None:
|
||||
self.opt = opt
|
||||
if rootpath is None:
|
||||
rootpath = ''
|
||||
assert isinstance(rootpath, str), 'rootpath must be a string, not {}'.format(type(rootpath))
|
||||
self.rootpath = rootpath
|
||||
self._suffix = suffix
|
||||
# For a Leadership inside a DynOptionDescription
|
||||
|
@ -62,7 +59,8 @@ class SynDynOptionDescription:
|
|||
def get_child(self,
|
||||
name: str,
|
||||
config_bag: ConfigBag,
|
||||
subpath: str) -> BaseOption:
|
||||
subpath: str,
|
||||
) -> BaseOption:
|
||||
suffix = self.ori_dyn.convert_suffix_to_path(self._suffix)
|
||||
if name.endswith(suffix):
|
||||
oname = name[:-len(suffix)]
|
||||
|
@ -105,18 +103,20 @@ class SynDynOptionDescription:
|
|||
bytype: Optional[BaseOption],
|
||||
byname: Optional[str],
|
||||
config_bag: ConfigBag,
|
||||
self_opt: BaseOption=None) -> BaseOption:
|
||||
self_opt: BaseOption=None,
|
||||
) -> BaseOption:
|
||||
for option in self.opt.get_children_recursively(bytype,
|
||||
byname,
|
||||
config_bag,
|
||||
self):
|
||||
self,
|
||||
):
|
||||
yield option
|
||||
|
||||
def impl_getpath(self) -> str:
|
||||
rootpath = self.rootpath
|
||||
if rootpath != '':
|
||||
rootpath += '.'
|
||||
return rootpath + self.impl_getname()
|
||||
path = self.impl_getname()
|
||||
if self.rootpath:
|
||||
path = f'{self.rootpath}.{path}'
|
||||
return path
|
||||
|
||||
def impl_get_display_name(self) -> str:
|
||||
return self.opt.impl_get_display_name() + str(self._suffix)
|
||||
|
@ -126,44 +126,52 @@ class SynDynLeadership(SynDynOptionDescription):
|
|||
def get_leader(self) -> SynDynOption:
|
||||
return self.opt.get_leader().to_dynoption(self.impl_getpath(),
|
||||
self._suffix,
|
||||
self.ori_dyn)
|
||||
self.ori_dyn,
|
||||
)
|
||||
|
||||
def get_followers(self) -> Iterator[SynDynOption]:
|
||||
subpath = self.impl_getpath()
|
||||
for follower in self.opt.get_followers():
|
||||
yield follower.to_dynoption(subpath,
|
||||
self._suffix,
|
||||
self.ori_dyn)
|
||||
self.ori_dyn,
|
||||
)
|
||||
|
||||
def reset_cache(self,
|
||||
path: str,
|
||||
config_bag: 'ConfigBag',
|
||||
resetted_opts: List[str]) -> None:
|
||||
resetted_opts: List[str],
|
||||
) -> None:
|
||||
leader = self.get_leader()
|
||||
followers = self.get_followers()
|
||||
self._reset_cache(path,
|
||||
leader,
|
||||
followers,
|
||||
config_bag,
|
||||
resetted_opts)
|
||||
resetted_opts,
|
||||
)
|
||||
|
||||
def pop(self,
|
||||
*args,
|
||||
**kwargs) -> None:
|
||||
**kwargs,
|
||||
) -> None:
|
||||
self.opt.pop(*args,
|
||||
followers=self.get_followers(),
|
||||
**kwargs)
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
def follower_force_store_value(self,
|
||||
values,
|
||||
value,
|
||||
option_bag,
|
||||
owner) -> None:
|
||||
owner,
|
||||
) -> None:
|
||||
self.opt.follower_force_store_value(values,
|
||||
value,
|
||||
option_bag,
|
||||
owner,
|
||||
dyn=self)
|
||||
dyn=self,
|
||||
)
|
||||
|
||||
def impl_getsuffix(self) -> str:
|
||||
return self._suffix
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# ____________________________________________________________
|
||||
from typing import Union
|
||||
from itertools import chain
|
||||
from .error import PropertiesOptionError, ConstError, ConfigError, LeadershipError, display_list
|
||||
from .i18n import _
|
||||
|
@ -186,7 +187,9 @@ class OptionBag:
|
|||
self.path = path
|
||||
elif option:
|
||||
self.path = option.impl_getpath()
|
||||
if properties is undefined:
|
||||
if '.' not in self.path and option == config_bag.context.get_description():
|
||||
self.properties = None
|
||||
elif properties is undefined:
|
||||
self.properties = config_bag.context.get_settings().getproperties(self, apply_requires=apply_requires)
|
||||
if properties is not undefined:
|
||||
self.properties = properties
|
||||
|
@ -196,7 +199,7 @@ class OptionBag:
|
|||
return self.option
|
||||
elif key == 'apply_requires':
|
||||
return True
|
||||
raise KeyError('unknown key "{}" for OptionBag'.format(key)) # pragma: no cover
|
||||
return undefined
|
||||
|
||||
def __delattr__(self, key):
|
||||
if key in ['properties', 'permissives']:
|
||||
|
@ -208,9 +211,13 @@ class OptionBag:
|
|||
raise KeyError(_('cannot delete key "{}" for OptionBag').format(key)) # pragma: no cover
|
||||
|
||||
def copy(self):
|
||||
option_bag = OptionBag(None, None, None)
|
||||
option_bag = OptionBag(None,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
for key in self.__slots__:
|
||||
if hasattr(self, key):
|
||||
if not hasattr(self, key):
|
||||
continue
|
||||
setattr(option_bag, key, getattr(self, key))
|
||||
return option_bag
|
||||
|
||||
|
@ -573,10 +580,8 @@ class Settings(object):
|
|||
context.reset_cache(None)
|
||||
|
||||
def setproperties(self,
|
||||
path,
|
||||
properties,
|
||||
option_bag,
|
||||
context,
|
||||
properties,
|
||||
):
|
||||
"""save properties for specified path
|
||||
(never save properties if same has option properties)
|
||||
|
@ -597,9 +602,9 @@ class Settings(object):
|
|||
raise LeadershipError(_('a leader ({0}) cannot have '
|
||||
'"force_default_on_freeze" or "force_metaconfig_on_freeze" property without "frozen"'
|
||||
'').format(opt.impl_get_display_name()))
|
||||
self._properties.setdefault(path, {})[option_bag.index] = properties
|
||||
self._properties.setdefault(option_bag.path, {})[option_bag.index] = properties
|
||||
# values too because of follower values could have a PropertiesOptionError has value
|
||||
context.reset_cache(option_bag)
|
||||
option_bag.config_bag.context.reset_cache(option_bag)
|
||||
option_bag.properties = properties
|
||||
|
||||
def set_context_permissives(self,
|
||||
|
@ -644,40 +649,44 @@ class Settings(object):
|
|||
|
||||
#____________________________________________________________
|
||||
# reset methods
|
||||
|
||||
def reset(self,
|
||||
option_bag,
|
||||
config_bag,
|
||||
def _get_path_index_config_option(self,
|
||||
bag: Union[OptionBag, ConfigBag],
|
||||
msg: str,
|
||||
):
|
||||
if option_bag is None:
|
||||
opt = None
|
||||
if isinstance(bag, ConfigBag):
|
||||
path = None
|
||||
index = None
|
||||
config_bag = bag
|
||||
option_bag = None
|
||||
else:
|
||||
opt = option_bag.option
|
||||
assert not opt.impl_is_symlinkoption(), _("can't reset properties to "
|
||||
"the symlinkoption \"{}\""
|
||||
"").format(opt.impl_get_display_name())
|
||||
path = option_bag.path
|
||||
index = option_bag.index
|
||||
assert not bag.option.impl_is_symlinkoption(), \
|
||||
_(msg).format(bag.option.impl_get_display_name())
|
||||
path = bag.path
|
||||
index = bag.index
|
||||
config_bag = bag.config_bag
|
||||
option_bag = bag
|
||||
return path, index, config_bag, option_bag
|
||||
|
||||
def reset(self,
|
||||
bag: Union[OptionBag, ConfigBag],
|
||||
):
|
||||
path, index, config_bag, option_bag = \
|
||||
self._get_path_index_config_option(bag,
|
||||
"can't reset properties to "
|
||||
"the symlinkoption \"{}\"",
|
||||
)
|
||||
if path in self._properties and index in self._properties[path]:
|
||||
del(self._properties[path][index])
|
||||
config_bag.context.reset_cache(option_bag)
|
||||
|
||||
def reset_permissives(self,
|
||||
option_bag,
|
||||
config_bag):
|
||||
if option_bag is None:
|
||||
opt = None
|
||||
path = None
|
||||
index = None
|
||||
else:
|
||||
opt = option_bag.option
|
||||
assert not opt.impl_is_symlinkoption(), _("can't reset permissives to "
|
||||
"the symlinkoption \"{}\""
|
||||
"").format(opt.impl_get_display_name())
|
||||
index = option_bag.index
|
||||
path = option_bag.path
|
||||
bag: Union[OptionBag, ConfigBag],
|
||||
):
|
||||
path, index, config_bag, option_bag = \
|
||||
self._get_path_index_config_option(bag,
|
||||
"can't reset permissives to "
|
||||
"the symlinkoption \"{}\"",
|
||||
)
|
||||
if path in self._permissives and index in self._permissives[path]:
|
||||
del(self._permissives[path][index])
|
||||
config_bag.context.reset_cache(option_bag)
|
||||
|
@ -742,7 +751,8 @@ class Settings(object):
|
|||
|
||||
def validate_mandatory(self,
|
||||
value,
|
||||
option_bag):
|
||||
option_bag,
|
||||
):
|
||||
if 'mandatory' in option_bag.config_bag.properties:
|
||||
values = option_bag.config_bag.context.get_values()
|
||||
if option_bag.option.impl_is_follower():
|
||||
|
@ -758,14 +768,17 @@ class Settings(object):
|
|||
):
|
||||
raise PropertiesOptionError(option_bag,
|
||||
['mandatory'],
|
||||
self)
|
||||
self,
|
||||
)
|
||||
if 'empty' in option_bag.properties and values.isempty(option_bag.option,
|
||||
value,
|
||||
force_allow_empty_list=True,
|
||||
index=option_bag.index):
|
||||
index=option_bag.index,
|
||||
):
|
||||
raise PropertiesOptionError(option_bag,
|
||||
['empty'],
|
||||
self)
|
||||
self,
|
||||
)
|
||||
|
||||
def validate_frozen(self,
|
||||
option_bag):
|
||||
|
|
|
@ -155,7 +155,8 @@ class Requires(object):
|
|||
childapi,
|
||||
path,
|
||||
form,
|
||||
current_action):
|
||||
current_action,
|
||||
):
|
||||
for requires in childapi.option.properties(uncalculated=True):
|
||||
if not isinstance(requires, str):
|
||||
option = requires.params.kwargs['condition'].option
|
||||
|
@ -372,7 +373,8 @@ class TiramisuDict:
|
|||
form,
|
||||
order,
|
||||
updates_status,
|
||||
init=False):
|
||||
init=False,
|
||||
):
|
||||
error = None
|
||||
if init:
|
||||
if form is not None:
|
||||
|
@ -399,21 +401,25 @@ class TiramisuDict:
|
|||
if form is not None:
|
||||
self.requires.add(path,
|
||||
childapi,
|
||||
form)
|
||||
form,
|
||||
)
|
||||
self.consistencies.add(path,
|
||||
childapi,
|
||||
form)
|
||||
form,
|
||||
)
|
||||
self.callbacks.add(path,
|
||||
childapi,
|
||||
schema,
|
||||
'force_store_value' in props_no_requires)
|
||||
'force_store_value' in props_no_requires,
|
||||
)
|
||||
childapi_option = childapi.option
|
||||
if model is not None and childapi.option.isoptiondescription() or not childapi_option.issymlinkoption():
|
||||
self.gen_model(model,
|
||||
childapi,
|
||||
path,
|
||||
leader_len,
|
||||
updates_status)
|
||||
updates_status,
|
||||
)
|
||||
if order is not None:
|
||||
order.append(path)
|
||||
if childapi.option.isoptiondescription():
|
||||
|
@ -434,7 +440,8 @@ class TiramisuDict:
|
|||
model,
|
||||
form,
|
||||
order,
|
||||
updates_status)
|
||||
updates_status,
|
||||
)
|
||||
else:
|
||||
child = childapi_option.get()
|
||||
childtype = child.__class__.__name__
|
||||
|
@ -469,14 +476,16 @@ class TiramisuDict:
|
|||
defaultmulti,
|
||||
is_multi,
|
||||
web_type,
|
||||
form)
|
||||
form,
|
||||
)
|
||||
if form is not None:
|
||||
self.gen_form(form,
|
||||
web_type,
|
||||
path,
|
||||
child,
|
||||
childapi_option,
|
||||
childtype)
|
||||
childtype,
|
||||
)
|
||||
if schema is not None:
|
||||
if web_type != 'symlink':
|
||||
schema[path]['title'] = childapi_option.description()
|
||||
|
@ -511,7 +520,8 @@ class TiramisuDict:
|
|||
defaultmulti,
|
||||
is_multi,
|
||||
web_type,
|
||||
form):
|
||||
form,
|
||||
):
|
||||
schema[path] = {'type': web_type}
|
||||
if childapi_option.issymlinkoption():
|
||||
sym_option = childapi_option.get()
|
||||
|
@ -548,7 +558,8 @@ class TiramisuDict:
|
|||
childapi,
|
||||
is_multi,
|
||||
path,
|
||||
props_no_requires):
|
||||
props_no_requires,
|
||||
):
|
||||
values = childapi.value.list()
|
||||
empty_is_required = not childapi.option.isfollower() and is_multi
|
||||
if '' not in values and ((empty_is_required and not 'empty' in props_no_requires) or \
|
||||
|
@ -562,7 +573,8 @@ class TiramisuDict:
|
|||
path,
|
||||
child,
|
||||
childapi_option,
|
||||
childtype):
|
||||
childtype,
|
||||
):
|
||||
obj_form = {}
|
||||
if path in form:
|
||||
obj_form.update(form[path])
|
||||
|
@ -602,12 +614,13 @@ class TiramisuDict:
|
|||
|
||||
def calc_raises_properties(self,
|
||||
obj,
|
||||
childapi):
|
||||
old_properties = childapi._option_bag.config_bag.properties
|
||||
config = childapi._option_bag.config_bag.context
|
||||
childapi,
|
||||
):
|
||||
old_properties = childapi._config_bag.properties
|
||||
config = childapi._config_bag.context
|
||||
settings = config.get_settings()
|
||||
childapi._option_bag.config_bag.properties = self.config.property.get(default=True) # settings.get_context_properties(config._impl_properties_cache)
|
||||
childapi._option_bag.config_bag.properties -= {'permissive'}
|
||||
childapi._config_bag.properties = self.config.property.get(default=True) # settings.get_context_properties(config._impl_properties_cache)
|
||||
childapi._config_bag.properties -= {'permissive'}
|
||||
properties = childapi.property.get(only_raises=True,
|
||||
uncalculated=True)
|
||||
properties -= childapi.permissive.get()
|
||||
|
@ -618,12 +631,13 @@ class TiramisuDict:
|
|||
properties -= self.config.permissive.get()
|
||||
if properties:
|
||||
obj['hidden'] = True
|
||||
childapi._option_bag.config_bag.properties = old_properties
|
||||
childapi._config_bag.properties = old_properties
|
||||
|
||||
def _gen_model_properties(self,
|
||||
childapi,
|
||||
path,
|
||||
index):
|
||||
index,
|
||||
):
|
||||
isfollower = childapi.option.isfollower()
|
||||
props = set(childapi.property.get())
|
||||
obj = self.gen_properties(props,
|
||||
|
@ -671,7 +685,8 @@ class TiramisuDict:
|
|||
childapi,
|
||||
path,
|
||||
leader_len,
|
||||
updates_status):
|
||||
updates_status,
|
||||
):
|
||||
if childapi.option.isoptiondescription():
|
||||
props = set(childapi.property.get())
|
||||
obj = {}
|
||||
|
@ -687,18 +702,21 @@ class TiramisuDict:
|
|||
else:
|
||||
obj = self._gen_model_properties(childapi,
|
||||
path,
|
||||
None)
|
||||
None,
|
||||
)
|
||||
if childapi.option.isfollower():
|
||||
for index in range(leader_len):
|
||||
follower_childapi = self.config.unrestraint.option(path, index)
|
||||
sobj = self._gen_model_properties(follower_childapi,
|
||||
path,
|
||||
index)
|
||||
index,
|
||||
)
|
||||
self._get_model_value(follower_childapi,
|
||||
path,
|
||||
sobj,
|
||||
index,
|
||||
updates_status)
|
||||
updates_status,
|
||||
)
|
||||
if sobj:
|
||||
model.setdefault(path, {})[str(index)] = sobj
|
||||
else:
|
||||
|
@ -706,7 +724,8 @@ class TiramisuDict:
|
|||
path,
|
||||
obj,
|
||||
None,
|
||||
updates_status)
|
||||
updates_status,
|
||||
)
|
||||
if obj:
|
||||
if not childapi.option.isoptiondescription() and childapi.option.isfollower():
|
||||
model.setdefault(path, {})['null'] = obj
|
||||
|
@ -718,7 +737,8 @@ class TiramisuDict:
|
|||
path,
|
||||
obj,
|
||||
index,
|
||||
updates_status):
|
||||
updates_status,
|
||||
):
|
||||
if path in updates_status and index in updates_status[path]:
|
||||
value = childapi.value.get()
|
||||
self._get_value_with_exception(obj,
|
||||
|
@ -837,7 +857,8 @@ class TiramisuDict:
|
|||
def apply_updates(self,
|
||||
oripath,
|
||||
updates,
|
||||
model_ori):
|
||||
model_ori,
|
||||
):
|
||||
updates_status = {}
|
||||
for update in updates:
|
||||
path = update['name']
|
||||
|
@ -854,11 +875,13 @@ class TiramisuDict:
|
|||
self.mod_value(childapi,
|
||||
path,
|
||||
index,
|
||||
update.get('value', undefined))
|
||||
update.get('value', undefined),
|
||||
)
|
||||
elif update['action'] == 'delete':
|
||||
self.del_value(childapi,
|
||||
path,
|
||||
index)
|
||||
index,
|
||||
)
|
||||
elif update['action'] == 'add':
|
||||
if childapi_option.ismulti():
|
||||
self.add_value(childapi, path, update['value'])
|
||||
|
@ -873,19 +896,22 @@ class TiramisuDict:
|
|||
return updates_status
|
||||
|
||||
def set_updates(self,
|
||||
body):
|
||||
body,
|
||||
):
|
||||
root_path = self.root
|
||||
updates = body.get('updates', [])
|
||||
updates_status = self.apply_updates(root_path,
|
||||
updates,
|
||||
body.get('model'))
|
||||
body.get('model'),
|
||||
)
|
||||
if 'model' in body:
|
||||
order = []
|
||||
old_model = body['model']
|
||||
new_model = self.todict(order=order,
|
||||
build_schema=False,
|
||||
build_form=False,
|
||||
updates_status=updates_status)
|
||||
updates_status=updates_status,
|
||||
)
|
||||
values = {'updates': list_keys(old_model, new_model['model'], order, updates_status),
|
||||
'model': new_model['model']}
|
||||
else:
|
||||
|
@ -898,7 +924,8 @@ class TiramisuDict:
|
|||
build_model=True,
|
||||
build_form=True,
|
||||
order=None,
|
||||
updates_status={}):
|
||||
updates_status={},
|
||||
):
|
||||
rootpath = self.root
|
||||
if build_schema:
|
||||
schema = {}
|
||||
|
@ -920,7 +947,8 @@ class TiramisuDict:
|
|||
form,
|
||||
order,
|
||||
updates_status,
|
||||
init=True)
|
||||
init=True,
|
||||
)
|
||||
if build_form:
|
||||
for form_ in custom_form:
|
||||
if 'key' in form_:
|
||||
|
|
|
@ -247,9 +247,9 @@ class Values:
|
|||
|
||||
#______________________________________________________________________
|
||||
# set value
|
||||
def setvalue(self,
|
||||
value,
|
||||
def set_value(self,
|
||||
option_bag,
|
||||
value,
|
||||
):
|
||||
context = option_bag.config_bag.context
|
||||
owner = self.get_context_owner()
|
||||
|
@ -283,23 +283,29 @@ class Values:
|
|||
|
||||
def setvalue_validation(self,
|
||||
value,
|
||||
option_bag):
|
||||
option_bag,
|
||||
):
|
||||
settings = option_bag.config_bag.context.get_settings()
|
||||
# First validate properties with this value
|
||||
opt = option_bag.option
|
||||
settings.validate_frozen(option_bag)
|
||||
val = self.calc_value(option_bag, value, False)
|
||||
val = self.calc_value(option_bag,
|
||||
value,
|
||||
False,)
|
||||
settings.validate_mandatory(val,
|
||||
option_bag)
|
||||
option_bag,
|
||||
)
|
||||
# Value must be valid for option
|
||||
opt.impl_validate(val,
|
||||
option_bag,
|
||||
check_error=True)
|
||||
check_error=True,
|
||||
)
|
||||
if 'warnings' in option_bag.config_bag.properties:
|
||||
# No error found so emit warnings
|
||||
opt.impl_validate(value,
|
||||
option_bag,
|
||||
check_error=False)
|
||||
check_error=False,
|
||||
)
|
||||
|
||||
def _setvalue(self,
|
||||
option_bag: OptionBag,
|
||||
|
@ -398,7 +404,8 @@ class Values:
|
|||
else:
|
||||
doption_bag.properties = ori_properties
|
||||
parent_owner = parent.get_values().getowner(doption_bag,
|
||||
only_default=True)
|
||||
only_default=True,
|
||||
)
|
||||
if parent_owner != owners.default:
|
||||
return doption_bag
|
||||
|
||||
|
@ -432,7 +439,8 @@ class Values:
|
|||
def getowner(self,
|
||||
option_bag,
|
||||
validate_meta=True,
|
||||
only_default=False):
|
||||
only_default=False,
|
||||
):
|
||||
"""
|
||||
retrieves the option's owner
|
||||
|
||||
|
@ -466,14 +474,15 @@ class Values:
|
|||
moption_bag = self._get_modified_parent(option_bag)
|
||||
if moption_bag is not None:
|
||||
owner = moption_bag.config_bag.context.get_values().getowner(moption_bag,
|
||||
only_default=only_default)
|
||||
only_default=only_default,
|
||||
)
|
||||
elif 'force_metaconfig_on_freeze' in option_bag.properties:
|
||||
return owners.default
|
||||
return owner
|
||||
|
||||
def setowner(self,
|
||||
owner,
|
||||
def set_owner(self,
|
||||
option_bag,
|
||||
owner,
|
||||
):
|
||||
"""
|
||||
sets a owner to an option
|
||||
|
@ -586,9 +595,10 @@ class Values:
|
|||
del self._values[path][index]
|
||||
|
||||
def reset_leadership(self,
|
||||
index,
|
||||
option_bag,
|
||||
subconfig):
|
||||
option_bag: OptionBag,
|
||||
leadership_option_bag: OptionBag,
|
||||
index: int,
|
||||
):
|
||||
current_value = self.get_cached_value(option_bag)
|
||||
length = len(current_value)
|
||||
if index >= length:
|
||||
|
@ -597,12 +607,13 @@ class Values:
|
|||
length,
|
||||
option_bag.option.impl_get_display_name()))
|
||||
current_value.pop(index)
|
||||
subconfig.get_description().pop(self,
|
||||
leadership_option_bag.option.pop(self,
|
||||
index,
|
||||
option_bag)
|
||||
self.setvalue(current_value,
|
||||
option_bag,
|
||||
)
|
||||
self.set_value(option_bag,
|
||||
current_value,
|
||||
)
|
||||
|
||||
#______________________________________________________________________
|
||||
# information
|
||||
|
@ -665,98 +676,6 @@ class Values:
|
|||
):
|
||||
return list(self._informations.get(path, {}).keys())
|
||||
|
||||
#______________________________________________________________________
|
||||
# mandatory warnings
|
||||
def _mandatory_warnings(self,
|
||||
context,
|
||||
config_bag,
|
||||
description_bag,
|
||||
currpath,
|
||||
subconfig,
|
||||
):
|
||||
settings = context.get_settings()
|
||||
for option in description_bag.option.get_children(config_bag):
|
||||
name = option.impl_getname()
|
||||
if option.impl_is_symlinkoption():
|
||||
continue
|
||||
if option.impl_is_optiondescription():
|
||||
try:
|
||||
option_bag = OptionBag(option,
|
||||
None,
|
||||
description_bag.config_bag,
|
||||
)
|
||||
|
||||
subsubconfig = subconfig.get_subconfig(option_bag)
|
||||
except PropertiesOptionError as err:
|
||||
pass
|
||||
else:
|
||||
for option in self._mandatory_warnings(context,
|
||||
config_bag,
|
||||
option_bag,
|
||||
currpath + [name],
|
||||
subsubconfig,
|
||||
):
|
||||
yield option
|
||||
else:
|
||||
try:
|
||||
if not option.impl_is_follower():
|
||||
option_bag = OptionBag(option,
|
||||
None,
|
||||
config_bag,
|
||||
)
|
||||
if 'mandatory' in option_bag.properties or 'empty' in option_bag.properties:
|
||||
subconfig.getattr(name,
|
||||
option_bag)
|
||||
else:
|
||||
for index in range(subconfig.get_length_leadership(description_bag)):
|
||||
option_bag = OptionBag(option,
|
||||
index,
|
||||
config_bag,
|
||||
)
|
||||
if 'mandatory' in option_bag.properties or 'empty' in option_bag.properties:
|
||||
subconfig.getattr(name,
|
||||
option_bag)
|
||||
except PropertiesOptionError as err:
|
||||
if err.proptype in (['mandatory'], ['empty']):
|
||||
yield option.impl_getpath()
|
||||
except ConfigError:
|
||||
pass
|
||||
|
||||
def mandatory_warnings(self,
|
||||
config_bag,
|
||||
):
|
||||
"""convenience function to trace Options that are mandatory and
|
||||
where no value has been set
|
||||
|
||||
:returns: generator of mandatory Option's path
|
||||
"""
|
||||
context = config_bag.context
|
||||
# copy
|
||||
od_setting_properties = config_bag.properties - {'mandatory', 'empty'}
|
||||
setting_properties = set(config_bag.properties) - {'warnings'}
|
||||
setting_properties.update(['mandatory', 'empty'])
|
||||
nconfig_bag = ConfigBag(context=config_bag.context,
|
||||
properties=frozenset(setting_properties),
|
||||
permissives=config_bag.permissives)
|
||||
nconfig_bag.set_permissive()
|
||||
od_config_bag = ConfigBag(context=nconfig_bag.context,
|
||||
properties=frozenset(od_setting_properties),
|
||||
permissives=nconfig_bag.permissives)
|
||||
od_config_bag.set_permissive()
|
||||
|
||||
descr = context.get_description()
|
||||
option_bag = OptionBag(descr,
|
||||
None,
|
||||
od_config_bag,
|
||||
)
|
||||
for option in self._mandatory_warnings(context,
|
||||
nconfig_bag,
|
||||
option_bag,
|
||||
[],
|
||||
context,
|
||||
):
|
||||
yield option
|
||||
|
||||
#____________________________________________________________
|
||||
# default owner methods
|
||||
def set_context_owner(self, owner):
|
||||
|
|
Loading…
Reference in a new issue