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()
|
||||
|
||||
|
||||
@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
|
||||
async def test_callback_calculating_disabled():
|
||||
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
||||
|
|
|
@ -170,8 +170,9 @@ class Calculation:
|
|||
option_bag: OptionBag,
|
||||
leadership_must_have_index: bool=False,
|
||||
orig_value: Any=undefined,
|
||||
allow_value_error=False,
|
||||
force_value_warning=False,
|
||||
allow_value_error: bool=False,
|
||||
force_value_warning: bool=False,
|
||||
for_settings: bool=False,
|
||||
) -> Any:
|
||||
return await carry_out_calculation(option_bag.option,
|
||||
callback=self.function,
|
||||
|
@ -182,20 +183,27 @@ class Calculation:
|
|||
orig_value=orig_value,
|
||||
allow_value_error=allow_value_error,
|
||||
force_value_warning=force_value_warning,
|
||||
for_settings=for_settings,
|
||||
)
|
||||
|
||||
async def help(self,
|
||||
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:
|
||||
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,
|
||||
callback=self.help_function,
|
||||
callback_params=self.params,
|
||||
index=option_bag.index,
|
||||
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):
|
||||
if hasattr(self, '_has_index'):
|
||||
|
@ -218,7 +226,9 @@ async def manager_callback(callbk: Param,
|
|||
index: Optional[int],
|
||||
orig_value,
|
||||
config_bag: ConfigBag,
|
||||
leadership_must_have_index: bool) -> Any:
|
||||
leadership_must_have_index: bool,
|
||||
for_settings: bool,
|
||||
) -> Any:
|
||||
"""replace Param by true value"""
|
||||
def calc_index(callbk, index, same_leadership):
|
||||
if index is not None:
|
||||
|
@ -280,9 +290,11 @@ async def manager_callback(callbk: Param,
|
|||
self_calc):
|
||||
# don't validate if option is option that we tried to validate
|
||||
config_bag = config_bag.copy()
|
||||
if for_settings:
|
||||
config_bag.properties = config_bag.true_properties - {'warnings'}
|
||||
config_bag.set_permissive()
|
||||
#config_bag.properties -= {'warnings'}
|
||||
if not for_settings:
|
||||
config_bag.properties -= {'warnings'}
|
||||
option_bag = OptionBag()
|
||||
option_bag.set_option(opt,
|
||||
index_,
|
||||
|
@ -401,6 +413,7 @@ async def carry_out_calculation(option,
|
|||
leadership_must_have_index: bool=False,
|
||||
allow_value_error: bool=False,
|
||||
force_value_warning: bool=False,
|
||||
for_settings: bool=False,
|
||||
):
|
||||
"""a function that carries out a calculation for an option's value
|
||||
|
||||
|
@ -430,7 +443,9 @@ async def carry_out_calculation(option,
|
|||
index,
|
||||
orig_value,
|
||||
config_bag,
|
||||
leadership_must_have_index)
|
||||
leadership_must_have_index,
|
||||
for_settings,
|
||||
)
|
||||
if value is undefined:
|
||||
return undefined
|
||||
if key is None:
|
||||
|
|
|
@ -459,10 +459,14 @@ class Settings(object):
|
|||
elif apply_requires:
|
||||
if not help_property:
|
||||
new_prop = await prop.execute(option_bag,
|
||||
leadership_must_have_index=True)
|
||||
leadership_must_have_index=True,
|
||||
for_settings=True,
|
||||
)
|
||||
else:
|
||||
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):
|
||||
new_prop = (new_prop, new_prop)
|
||||
if new_prop is None:
|
||||
|
|
Loading…
Reference in New Issue