calculation with options not in same dynoptiondescription

This commit is contained in:
egarette@silique.fr 2023-04-12 11:42:27 +02:00
parent 7fad2b5d7d
commit 4b41fd89fb
2 changed files with 62 additions and 11 deletions

View file

@ -881,6 +881,51 @@ async def test_requires_dyndescription_in_dyn():
assert not await list_sessions() assert not await list_sessions()
def calc_value_not_same(param, condition, expected, default, suffix):
if suffix == 'val1':
index = 0
else:
index = 1
return calc_value(param, condition=condition[index], expected=expected, default=default)
@pytest.mark.asyncio
async def test_requires_dyndescription_in_dyn_not_same():
boolean = BoolOption('boolean', '', True)
disabled_property = Calculation(calc_value_not_same,
Params(ParamValue('disabled'),
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False),
'default': ParamValue(None),
'suffix': ParamSuffix()}))
st = StrOption('st', '', properties=(disabled_property,))
dod1 = DynOptionDescription('dod1', '', [boolean], suffixes=Calculation(return_list))
dod2 = DynOptionDescription('dod2', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod1, dod2])
od2 = OptionDescription('od', '', [od])
async with await Config(od2) as cfg:
await cfg.property.read_write()
assert await cfg.option('od.dod2val1.stval1').value.get() is None
assert await cfg.option('od.dod2val2.stval2').value.get() is None
#
await cfg.option('od.dod1val1.booleanval1').value.set(False)
props = []
try:
await cfg.option('od.dod2val1.stval1').value.get()
except PropertiesOptionError as err:
props = err.proptype
assert props == frozenset(['disabled'])
props = []
await cfg.option('od.dod2val2.stval2').value.get()
#
await cfg.option('od.dod1val1.booleanval1').value.set(True)
assert await cfg.option('od.dod2val1.stval1').value.get() is None
assert await cfg.option('od.dod2val2.stval2').value.get() is None
assert not await list_sessions()
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_requires_dyndescription2(): async def test_requires_dyndescription2():
boolean = BoolOption('boolean', '', True) boolean = BoolOption('boolean', '', True)

View file

@ -359,6 +359,7 @@ async def manager_callback(callbk: Param,
callbk_option = callbk.option callbk_option = callbk.option
callbk_options = None callbk_options = None
if callbk_option.issubdyn(): if callbk_option.issubdyn():
found = False
if isinstance(callbk, ParamDynOption): if isinstance(callbk, ParamDynOption):
subdyn = callbk.dynoptiondescription subdyn = callbk.dynoptiondescription
rootpath = subdyn.impl_getpath() + callbk.suffix rootpath = subdyn.impl_getpath() + callbk.suffix
@ -366,7 +367,22 @@ async def manager_callback(callbk: Param,
callbk_option = callbk_option.to_dynoption(rootpath, callbk_option = callbk_option.to_dynoption(rootpath,
suffix, suffix,
subdyn) subdyn)
elif not option.impl_is_dynsymlinkoption(): found = True
elif option.impl_is_dynsymlinkoption():
rootpath = option.rootpath
call_path = callbk_option.impl_getpath()
if call_path.startswith(option.opt.impl_getpath().rsplit('.', 1)[0]):
# in same dynoption
if len(callbk_option.impl_getpath().split('.')) == len(rootpath.split('.')):
rootpath = rootpath.rsplit('.', 1)[0]
suffix = option.impl_getsuffix()
subdyn = callbk_option.getsubdyn()
callbk_option = callbk_option.to_dynoption(rootpath,
suffix,
subdyn,
)
found = True
if not found:
callbk_options = [] callbk_options = []
dynopt = callbk_option.getsubdyn() dynopt = callbk_option.getsubdyn()
rootpath = dynopt.impl_getpath() rootpath = dynopt.impl_getpath()
@ -378,16 +394,6 @@ async def manager_callback(callbk: Param,
suffix, suffix,
dynopt) dynopt)
callbk_options.append(doption) callbk_options.append(doption)
else:
#FIXME in same dynamic option?
rootpath = option.rootpath
if len(callbk_option.impl_getpath().split('.')) == len(rootpath.split('.')):
rootpath = rootpath.rsplit('.', 1)[0]
suffix = option.impl_getsuffix()
subdyn = callbk_option.getsubdyn()
callbk_option = callbk_option.to_dynoption(rootpath,
suffix,
subdyn)
if leadership_must_have_index and callbk_option.impl_is_follower() and index is None: if leadership_must_have_index and callbk_option.impl_is_follower() and index is None:
raise Break() raise Break()
if config_bag is undefined: if config_bag is undefined: