exected could be a list

This commit is contained in:
Emmanuel Garette 2021-02-06 15:18:28 +01:00
parent d3d4de7ae3
commit 0bb066a8b8
3 changed files with 37 additions and 3 deletions

View File

@ -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)

View File

@ -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

View File

@ -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: