Add ParamInformation and callback can be a coroutine
This commit is contained in:
@ -10,7 +10,7 @@ from tiramisu.setting import groups, owners
|
||||
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, Leadership, \
|
||||
undefined, Calculation, Params, ParamOption, ParamValue, ParamIndex, calc_value, \
|
||||
valid_ip_netmask, ParamSelfOption
|
||||
valid_ip_netmask, ParamSelfOption, ParamInformation
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError, LeadershipError, ConfigError
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.storage import list_sessions
|
||||
@ -43,6 +43,10 @@ def return_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
async def return_async_value(value=None):
|
||||
return value
|
||||
|
||||
|
||||
def return_value2(*args, **kwargs):
|
||||
value = list(args)
|
||||
value.extend(kwargs.values())
|
||||
@ -333,6 +337,50 @@ async def test_callback_value(config_type):
|
||||
assert not await list_sessions()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_callback_async_value(config_type):
|
||||
val1 = StrOption('val1', "", 'val')
|
||||
val2 = StrOption('val2', "", Calculation(return_async_value, Params(ParamOption(val1))))
|
||||
val3 = StrOption('val3', "", Calculation(return_async_value, Params(ParamValue('yes'))))
|
||||
val4 = StrOption('val4', "", Calculation(return_async_value, Params(kwargs={'value': ParamOption(val1)})))
|
||||
val5 = StrOption('val5', "", Calculation(return_async_value, Params(ParamValue('yes'))))
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
||||
async with await Config(maconfig) as cfg:
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
assert await cfg.option('val1').value.get() == 'val'
|
||||
assert await cfg.option('val2').value.get() == 'val'
|
||||
assert await cfg.option('val4').value.get() == 'val'
|
||||
await cfg.option('val1').value.set('new-val')
|
||||
assert await cfg.option('val1').value.get() == 'new-val'
|
||||
assert await cfg.option('val2').value.get() == 'new-val'
|
||||
assert await cfg.option('val4').value.get() == 'new-val'
|
||||
await cfg.option('val1').value.reset()
|
||||
assert await cfg.option('val1').value.get() == 'val'
|
||||
assert await cfg.option('val2').value.get() == 'val'
|
||||
assert await cfg.option('val3').value.get() == 'yes'
|
||||
assert await cfg.option('val4').value.get() == 'val'
|
||||
assert await cfg.option('val5').value.get() == 'yes'
|
||||
assert not await list_sessions()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_callback_information(config_type):
|
||||
val1 = StrOption('val1', "", Calculation(return_value, Params(ParamInformation('information', 'no_value'))))
|
||||
val2 = StrOption('val2', "", Calculation(return_value, Params(ParamInformation('information'))))
|
||||
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
||||
async with await Config(maconfig) as cfg:
|
||||
await cfg.property.read_write()
|
||||
cfg = await get_config(cfg, config_type)
|
||||
assert await cfg.option('val1').value.get() == 'no_value'
|
||||
with pytest.raises(ConfigError):
|
||||
await cfg.option('val2').value.get()
|
||||
await cfg.information.set('information', 'new_value')
|
||||
assert await cfg.option('val1').value.get() == 'new_value'
|
||||
assert await cfg.option('val2').value.get() == 'new_value'
|
||||
assert not await list_sessions()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_callback_value_tuple(config_type):
|
||||
val1 = StrOption('val1', "", 'val1')
|
||||
|
Reference in New Issue
Block a user