diff --git a/tests/test_dyn_optiondescription.py b/tests/test_dyn_optiondescription.py index 481f7dc..d6f1a4f 100644 --- a/tests/test_dyn_optiondescription.py +++ b/tests/test_dyn_optiondescription.py @@ -642,6 +642,73 @@ async def test_dyndescription_root(): 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 async def test_requires_dyndescription(): boolean = BoolOption('boolean', '', True) diff --git a/tiramisu/option/dynoptiondescription.py b/tiramisu/option/dynoptiondescription.py index fc462af..f341f5c 100644 --- a/tiramisu/option/dynoptiondescription.py +++ b/tiramisu/option/dynoptiondescription.py @@ -80,6 +80,8 @@ class DynOptionDescription(OptionDescription): None, config_bag) values = await self._suffixes.execute(option_bag) + if values is None: + values = [] if __debug__: if not isinstance(values, list): raise ValueError(_('DynOptionDescription suffixes for option "{}", is not a list ({})'