add test to dyn optiondescription
This commit is contained in:
parent
9576809543
commit
6084487d08
|
@ -642,6 +642,73 @@ async def test_dyndescription_root():
|
||||||
assert not await list_sessions()
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_dyndescription_disable_suffix_root():
|
||||||
|
boolean = BoolOption('boolean', '', True)
|
||||||
|
disabled_property = Calculation(calc_value,
|
||||||
|
Params(ParamValue('disabled'),
|
||||||
|
kwargs={'condition': ParamOption(boolean),
|
||||||
|
'expected': ParamValue(False),
|
||||||
|
'default': ParamValue(None)}))
|
||||||
|
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
|
||||||
|
st1 = StrOption('st', '')
|
||||||
|
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
|
||||||
|
od = OptionDescription('root', 'root', [boolean, val, dod])
|
||||||
|
config = await Config(od, session_id='test')
|
||||||
|
await config.property.read_write()
|
||||||
|
assert await config.value.dict() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.stext1': None, 'dodext2.stext2': None}
|
||||||
|
#
|
||||||
|
await config.option('boolean').value.set(False)
|
||||||
|
assert await config.value.dict() == {'boolean': False}
|
||||||
|
await delete_session('test')
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_dyndescription_disable_suffix_root_2():
|
||||||
|
boolean = BoolOption('boolean', '', False)
|
||||||
|
disabled_property = Calculation(calc_value,
|
||||||
|
Params(ParamValue('disabled'),
|
||||||
|
kwargs={'condition': ParamOption(boolean),
|
||||||
|
'expected': ParamValue(False),
|
||||||
|
'default': ParamValue(None)}))
|
||||||
|
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
|
||||||
|
st1 = StrOption('st', '')
|
||||||
|
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
|
||||||
|
od = OptionDescription('root', 'root', [boolean, val, dod])
|
||||||
|
config = await Config(od, session_id='test')
|
||||||
|
await config.property.read_write()
|
||||||
|
assert await config.value.dict() == {'boolean': False}
|
||||||
|
#
|
||||||
|
await config.option('boolean').value.set(True)
|
||||||
|
assert await config.value.dict() == {'boolean': True, 'val': ['ext1', 'ext2'], 'dodext1.stext1': None, 'dodext2.stext2': None}
|
||||||
|
await delete_session('test')
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_dyndescription_disable_suffix():
|
||||||
|
boolean = BoolOption('boolean', '', True)
|
||||||
|
disabled_property = Calculation(calc_value,
|
||||||
|
Params(ParamValue('disabled'),
|
||||||
|
kwargs={'condition': ParamOption(boolean),
|
||||||
|
'expected': ParamValue(False),
|
||||||
|
'default': ParamValue(None)}))
|
||||||
|
val = StrOption('val', '', ['ext1', 'ext2'], properties=(disabled_property,), multi=True)
|
||||||
|
st1 = StrOption('st', '')
|
||||||
|
dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(calc_value, Params(ParamOption(val, notraisepropertyerror=True))), properties=(disabled_property,))
|
||||||
|
od = OptionDescription('root', 'root', [boolean, val, dod])
|
||||||
|
od2 = OptionDescription('root', 'root', [od])
|
||||||
|
config = await Config(od2, session_id='test')
|
||||||
|
await config.property.read_write()
|
||||||
|
assert await config.value.dict() == {'root.boolean': True, 'root.val': ['ext1', 'ext2'], 'root.dodext1.stext1': None, 'root.dodext2.stext2': None}
|
||||||
|
#
|
||||||
|
await config.option('root.boolean').value.set(False)
|
||||||
|
assert await config.value.dict() == {'root.boolean': False}
|
||||||
|
await delete_session('test')
|
||||||
|
assert not await list_sessions()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_requires_dyndescription():
|
async def test_requires_dyndescription():
|
||||||
boolean = BoolOption('boolean', '', True)
|
boolean = BoolOption('boolean', '', True)
|
||||||
|
|
|
@ -80,6 +80,8 @@ class DynOptionDescription(OptionDescription):
|
||||||
None,
|
None,
|
||||||
config_bag)
|
config_bag)
|
||||||
values = await self._suffixes.execute(option_bag)
|
values = await self._suffixes.execute(option_bag)
|
||||||
|
if values is None:
|
||||||
|
values = []
|
||||||
if __debug__:
|
if __debug__:
|
||||||
if not isinstance(values, list):
|
if not isinstance(values, list):
|
||||||
raise ValueError(_('DynOptionDescription suffixes for option "{}", is not a list ({})'
|
raise ValueError(_('DynOptionDescription suffixes for option "{}", is not a list ({})'
|
||||||
|
|
Loading…
Reference in New Issue