From 99a422dad7654771650bb5f9180c2cc9bfd79c99 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 6 Feb 2021 15:18:28 +0100 Subject: [PATCH] exected could be a list --- tests/test_requires.py | 32 ++++++++++++++++++++++++++++++++ tiramisu/autolib.py | 3 +-- tiramisu/function.py | 5 ++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/tests/test_requires.py b/tests/test_requires.py index 47aa8b8..5df470a 100644 --- a/tests/test_requires.py +++ b/tests/test_requires.py @@ -1070,6 +1070,38 @@ async def test_requires_different_inverse_unicode(config_type): assert not await list_sessions() +@pytest.mark.asyncio +async def test_requires_different_inverse_unicode2(config_type): + a = BoolOption('activate_service', '', False) + d = StrOption('activate_other_service', '', 'val2') + disabled_property = Calculation(calc_value, + Params(ParamValue('disabled'), + kwargs={'condition_0': ParamOption(a), + 'condition_1': ParamOption(d), + 'expected_0': ParamValue(True), + 'expected_1': ParamValue(['val2', 'val3']), + 'condition_operator': ParamValue('OR'), + 'reverse_condition_1': ParamValue(True)})) + b = IPOption('ip_address_service', '', properties=(disabled_property,)) + od = OptionDescription('service', '', [a, d, b]) + async with await Config(od) as cfg: + await cfg.property.read_write() + cfg = await get_config(cfg, config_type) + assert await cfg.option('ip_address_service').value.get() == None + await cfg.option('activate_service').value.set(True) + with pytest.raises(PropertiesOptionError): + await cfg.option('ip_address_service').value.get() + await cfg.option('activate_service').value.set(False) + assert await cfg.option('ip_address_service').value.get() == None + await cfg.option('activate_other_service').value.set('val1') + with pytest.raises(PropertiesOptionError): + await cfg.option('ip_address_service').value.get() + await cfg.option('activate_service').value.set(True) + with pytest.raises(PropertiesOptionError): + await cfg.option('ip_address_service').value.get() + assert not await list_sessions() + + @pytest.mark.asyncio async def test_optiondescription_requires(): a = BoolOption('activate_service', '', True) diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index cfbdb14..71ebf43 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -501,5 +501,4 @@ async def calculate(option, '').format(str(error), callback.__name__, option.impl_get_display_name()) - del error - raise ConfigError(msg) + raise ConfigError(msg) from error diff --git a/tiramisu/function.py b/tiramisu/function.py index 1779bcb..0cd037f 100644 --- a/tiramisu/function.py +++ b/tiramisu/function.py @@ -400,7 +400,10 @@ class CalcValue: for idx, calculated_condition in calculated_conditions.items(): if isinstance(calculated_expected, dict): if idx is not None: - current_matches = calculated_condition == calculated_expected[idx] + if isinstance(calculated_expected[idx], list): + current_matches = calculated_condition in calculated_expected[idx] + else: + current_matches = calculated_condition == calculated_expected[idx] else: current_matches = calculated_condition in calculated_expected.values() else: