require with inverse
This commit is contained in:
parent
4b01eb6497
commit
2db15e193e
|
@ -176,6 +176,22 @@ def test_multi_with_requires_in_another_group():
|
||||||
assert 'hidden' in setting[stroption]
|
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():
|
def test_apply_requires_from_config():
|
||||||
s = StrOption("string", "", default=["string"], multi=True)
|
s = StrOption("string", "", default=["string"], multi=True)
|
||||||
intoption = IntOption('int', 'Test int option', default=0)
|
intoption = IntOption('int', 'Test int option', default=0)
|
||||||
|
@ -232,6 +248,14 @@ def test_multi_with_requires_that_is_multi():
|
||||||
raises(ValueError, "Config(descr)")
|
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():
|
def test_multi_with_requires_that_is_masterslave():
|
||||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
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)
|
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
|
assert config.str1[0] is None
|
||||||
raises(PropertiesOptionError, 'config.str1[1]')
|
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():
|
def test_multi_with_requires_that_is_not_same_masterslave():
|
||||||
b = IntOption('int', 'Test int option', default=[0], multi=True)
|
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)
|
c = StrOption('str', 'Test string option', requires=[{'option': b, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||||
|
|
|
@ -651,6 +651,8 @@ class Settings(object):
|
||||||
" '{0}' with requirement on: "
|
" '{0}' with requirement on: "
|
||||||
"'{1}'").format(path, reqpath))
|
"'{1}'").format(path, reqpath))
|
||||||
if option.impl_is_multi():
|
if option.impl_is_multi():
|
||||||
|
if index is None:
|
||||||
|
continue
|
||||||
idx = index
|
idx = index
|
||||||
else:
|
else:
|
||||||
idx = None
|
idx = None
|
||||||
|
@ -683,8 +685,7 @@ class Settings(object):
|
||||||
raise value
|
raise value
|
||||||
else:
|
else:
|
||||||
orig_value = value
|
orig_value = value
|
||||||
if (not inverse and
|
if (not inverse and value in expected or
|
||||||
value in expected or
|
|
||||||
inverse and value not in expected):
|
inverse and value not in expected):
|
||||||
if debug:
|
if debug:
|
||||||
if isinstance(orig_value, PropertiesOptionError):
|
if isinstance(orig_value, PropertiesOptionError):
|
||||||
|
|
Loading…
Reference in New Issue