diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 299b6b8..9034d4e 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -176,6 +176,22 @@ def test_multi_with_requires_in_another_group(): assert 'hidden' in setting[stroption] +def test_multi_with_requires_in_another_group_inverse(): + s = StrOption("string", "", default=["string"], multi=True) + intoption = IntOption('int', 'Test int option', default=0) + stroption = StrOption('str', 'Test string option', default=["abc"], + requires=[{'option': intoption, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True) + descr = OptionDescription("opt", "", [stroption]) + descr2 = OptionDescription("opt2", "", [intoption, s, descr]) + config = Config(descr2) + setting = config.cfgimpl_get_settings() + config.read_write() + assert not 'hidden' in setting[stroption] + config.int = 1 + raises(PropertiesOptionError, "config.opt.str = ['a', 'b']") + assert 'hidden' in setting[stroption] + + def test_apply_requires_from_config(): s = StrOption("string", "", default=["string"], multi=True) intoption = IntOption('int', 'Test int option', default=0) @@ -232,6 +248,14 @@ def test_multi_with_requires_that_is_multi(): raises(ValueError, "Config(descr)") +def test_multi_with_requires_that_is_multi_inverse(): + b = IntOption('int', 'Test int option', default=[0], multi=True) + c = StrOption('str', 'Test string option', default=['abc'], requires=[{'option': b, 'expected': 0, 'action': 'hidden', 'inverse': True}], multi=True) + descr = OptionDescription("opt", "", [b, c]) + descr + raises(ValueError, "Config(descr)") + + def test_multi_with_requires_that_is_masterslave(): b = IntOption('int', 'Test int option', default=[0], multi=True) c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True) @@ -270,6 +294,30 @@ def test_multi_with_requires_that_is_masterslave_slave(): assert config.str1[0] is None raises(PropertiesOptionError, 'config.str1[1]') + +def test_multi_with_requires_that_is_masterslave_slave_inverse(): + b = IntOption('int', 'Test int option', default=[0], multi=True) + c = StrOption('str', 'Test string option', multi=True) + d = StrOption('str1', 'Test string option', requires=[{'option': c, 'expected': None, 'action': 'hidden', 'inverse': True}], multi=True) + descr = OptionDescription("int", "", [b, c, d]) + descr.impl_set_group_type(groups.master) + config = Config(descr) + config.read_write() + assert config.int == [0] + assert config.str == [None] + assert config.str1 == [None] + config.int = [0, 1] + assert config.int == [0, 1] + assert config.str == [None, None] + assert config.str1 == [None, None] + config.str = [None, '1'] + config.read_only() + assert config.str1 == [None, None] + config.read_write() + assert config.str1[0] is None + raises(PropertiesOptionError, 'config.str1[1]') + + def test_multi_with_requires_that_is_not_same_masterslave(): b = IntOption('int', 'Test int option', default=[0], multi=True) c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True) diff --git a/tiramisu/setting.py b/tiramisu/setting.py index b1ca092..ab6bede 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -651,6 +651,8 @@ class Settings(object): " '{0}' with requirement on: " "'{1}'").format(path, reqpath)) if option.impl_is_multi(): + if index is None: + continue idx = index else: idx = None @@ -683,8 +685,7 @@ class Settings(object): raise value else: orig_value = value - if (not inverse and - value in expected or + if (not inverse and value in expected or inverse and value not in expected): if debug: if isinstance(orig_value, PropertiesOptionError):