manage callback with unrestraint
This commit is contained in:
parent
2f173af70f
commit
200562d23c
|
@ -1298,6 +1298,21 @@ async def test_callback_calculating_invalid():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_callback_unrestraint():
|
||||||
|
opt1 = IntOption('opt1', '', 1)
|
||||||
|
opt2 = IntOption('opt2', '', Calculation(return_value, Params(ParamOption(opt1))))
|
||||||
|
od1 = OptionDescription('od1', '', [opt1], properties=('disabled',))
|
||||||
|
od2 = OptionDescription('od2', '', [opt2])
|
||||||
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
||||||
|
async with await Config(maconfig) as cfg:
|
||||||
|
await cfg.property.read_write()
|
||||||
|
with pytest.raises(ConfigError):
|
||||||
|
await cfg.option('od2.opt2').value.get()
|
||||||
|
assert await cfg.unrestraint.option('od2.opt2').value.get() == 1
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_callback_calculating_disabled():
|
async def test_callback_calculating_disabled():
|
||||||
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
||||||
|
|
|
@ -170,8 +170,9 @@ class Calculation:
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
leadership_must_have_index: bool=False,
|
leadership_must_have_index: bool=False,
|
||||||
orig_value: Any=undefined,
|
orig_value: Any=undefined,
|
||||||
allow_value_error=False,
|
allow_value_error: bool=False,
|
||||||
force_value_warning=False,
|
force_value_warning: bool=False,
|
||||||
|
for_settings: bool=False,
|
||||||
) -> Any:
|
) -> Any:
|
||||||
return await carry_out_calculation(option_bag.option,
|
return await carry_out_calculation(option_bag.option,
|
||||||
callback=self.function,
|
callback=self.function,
|
||||||
|
@ -182,20 +183,27 @@ class Calculation:
|
||||||
orig_value=orig_value,
|
orig_value=orig_value,
|
||||||
allow_value_error=allow_value_error,
|
allow_value_error=allow_value_error,
|
||||||
force_value_warning=force_value_warning,
|
force_value_warning=force_value_warning,
|
||||||
|
for_settings=for_settings,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def help(self,
|
async def help(self,
|
||||||
option_bag: OptionBag,
|
option_bag: OptionBag,
|
||||||
leadership_must_have_index: bool=False) -> str:
|
leadership_must_have_index: bool=False,
|
||||||
|
for_settings: bool=False,
|
||||||
|
) -> str:
|
||||||
if not self.help_function:
|
if not self.help_function:
|
||||||
return await self.execute(option_bag,
|
return await self.execute(option_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index)
|
leadership_must_have_index=leadership_must_have_index,
|
||||||
|
for_settings=for_settings,
|
||||||
|
)
|
||||||
return await carry_out_calculation(option_bag.option,
|
return await carry_out_calculation(option_bag.option,
|
||||||
callback=self.help_function,
|
callback=self.help_function,
|
||||||
callback_params=self.params,
|
callback_params=self.params,
|
||||||
index=option_bag.index,
|
index=option_bag.index,
|
||||||
config_bag=option_bag.config_bag,
|
config_bag=option_bag.config_bag,
|
||||||
leadership_must_have_index=leadership_must_have_index)
|
leadership_must_have_index=leadership_must_have_index,
|
||||||
|
for_settings=for_settings,
|
||||||
|
)
|
||||||
|
|
||||||
def has_index(self, current_option):
|
def has_index(self, current_option):
|
||||||
if hasattr(self, '_has_index'):
|
if hasattr(self, '_has_index'):
|
||||||
|
@ -218,7 +226,9 @@ async def manager_callback(callbk: Param,
|
||||||
index: Optional[int],
|
index: Optional[int],
|
||||||
orig_value,
|
orig_value,
|
||||||
config_bag: ConfigBag,
|
config_bag: ConfigBag,
|
||||||
leadership_must_have_index: bool) -> Any:
|
leadership_must_have_index: bool,
|
||||||
|
for_settings: bool,
|
||||||
|
) -> Any:
|
||||||
"""replace Param by true value"""
|
"""replace Param by true value"""
|
||||||
def calc_index(callbk, index, same_leadership):
|
def calc_index(callbk, index, same_leadership):
|
||||||
if index is not None:
|
if index is not None:
|
||||||
|
@ -280,9 +290,11 @@ async def manager_callback(callbk: Param,
|
||||||
self_calc):
|
self_calc):
|
||||||
# don't validate if option is option that we tried to validate
|
# don't validate if option is option that we tried to validate
|
||||||
config_bag = config_bag.copy()
|
config_bag = config_bag.copy()
|
||||||
config_bag.properties = config_bag.true_properties - {'warnings'}
|
if for_settings:
|
||||||
|
config_bag.properties = config_bag.true_properties - {'warnings'}
|
||||||
config_bag.set_permissive()
|
config_bag.set_permissive()
|
||||||
#config_bag.properties -= {'warnings'}
|
if not for_settings:
|
||||||
|
config_bag.properties -= {'warnings'}
|
||||||
option_bag = OptionBag()
|
option_bag = OptionBag()
|
||||||
option_bag.set_option(opt,
|
option_bag.set_option(opt,
|
||||||
index_,
|
index_,
|
||||||
|
@ -401,6 +413,7 @@ async def carry_out_calculation(option,
|
||||||
leadership_must_have_index: bool=False,
|
leadership_must_have_index: bool=False,
|
||||||
allow_value_error: bool=False,
|
allow_value_error: bool=False,
|
||||||
force_value_warning: bool=False,
|
force_value_warning: bool=False,
|
||||||
|
for_settings: bool=False,
|
||||||
):
|
):
|
||||||
"""a function that carries out a calculation for an option's value
|
"""a function that carries out a calculation for an option's value
|
||||||
|
|
||||||
|
@ -430,7 +443,9 @@ async def carry_out_calculation(option,
|
||||||
index,
|
index,
|
||||||
orig_value,
|
orig_value,
|
||||||
config_bag,
|
config_bag,
|
||||||
leadership_must_have_index)
|
leadership_must_have_index,
|
||||||
|
for_settings,
|
||||||
|
)
|
||||||
if value is undefined:
|
if value is undefined:
|
||||||
return undefined
|
return undefined
|
||||||
if key is None:
|
if key is None:
|
||||||
|
|
|
@ -459,10 +459,14 @@ class Settings(object):
|
||||||
elif apply_requires:
|
elif apply_requires:
|
||||||
if not help_property:
|
if not help_property:
|
||||||
new_prop = await prop.execute(option_bag,
|
new_prop = await prop.execute(option_bag,
|
||||||
leadership_must_have_index=True)
|
leadership_must_have_index=True,
|
||||||
|
for_settings=True,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
new_prop = await prop.help(option_bag,
|
new_prop = await prop.help(option_bag,
|
||||||
leadership_must_have_index=True)
|
leadership_must_have_index=True,
|
||||||
|
for_settings=True,
|
||||||
|
)
|
||||||
if isinstance(new_prop, str):
|
if isinstance(new_prop, str):
|
||||||
new_prop = (new_prop, new_prop)
|
new_prop = (new_prop, new_prop)
|
||||||
if new_prop is None:
|
if new_prop is None:
|
||||||
|
|
Loading…
Reference in New Issue