Requires need option, not path
Valid requires
This commit is contained in:
parent
509f41e14c
commit
2c5bbb7bc0
@ -21,10 +21,10 @@ def make_description_freeze():
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=[True], multi=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False, properties=('force_store_value',),
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((booloption, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((booloption, True, 'hidden'),))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('tiramisu', '', [gcgroup, booloption, objspaceoption,
|
||||
|
@ -18,10 +18,10 @@ def make_description():
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
@ -42,10 +42,10 @@ def make_description_duplicates():
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# dummy2 (same path)
|
||||
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
||||
# dummy3 (same name)
|
||||
@ -80,11 +80,11 @@ def make_description2():
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
boolop.enable_multi()
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
# second multi
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option.enable_multi()
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
@ -153,7 +153,7 @@ def make_description_requires():
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
@ -186,7 +186,7 @@ def test_hidden_if_in_with_group():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=(('int', 1, 'hidden'),))
|
||||
requires=((intoption, 1, 'hidden'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
@ -209,7 +209,7 @@ def test_disabled_with_group():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
||||
requires=(('int', 1, 'disabled'),))
|
||||
requires=((intoption, 1, 'disabled'),))
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
||||
objspaceoption, stroption, intoption])
|
||||
cfg = Config(descr)
|
||||
@ -231,10 +231,10 @@ def make_description_callback():
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('boolop', True, 'hidden'),))
|
||||
requires=((boolop, True, 'hidden'),))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
|
@ -131,7 +131,7 @@ def test_multi_with_requires():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[('int', 1, 'hidden')], multi=True)
|
||||
requires=[(intoption, 1, 'hidden')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
@ -146,7 +146,7 @@ def test__requires_with_inverted():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[('int', 1, 'hide', 'inverted')], multi=True)
|
||||
requires=[(intoption, 1, 'hide', 'inverted')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
@ -160,7 +160,7 @@ def test_multi_with_requires_in_another_group():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'hidden')], multi=True)
|
||||
requires=[(intoption, 1, 'hidden')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
@ -177,7 +177,7 @@ def test_apply_requires_from_config():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'hidden')], multi=True)
|
||||
requires=[(intoption, 1, 'hidden')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
@ -194,7 +194,7 @@ def test_apply_requires_with_disabled():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'disabled')], multi=True)
|
||||
requires=[(intoption, 1, 'disabled')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
@ -211,7 +211,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
descr = OptionDescription("options", "", [intoption])
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', 1, 'disabled')], multi=True)
|
||||
requires=[(intoption, 1, 'disabled')], multi=True)
|
||||
descr = OptionDescription("opt", "", [stroption])
|
||||
descr2 = OptionDescription("opt2", "", [intoption, s, descr])
|
||||
config = Config(descr2)
|
||||
@ -226,16 +226,7 @@ def test_multi_with_requires_with_disabled_in_another_group():
|
||||
def test_multi_with_requires_that_is_multi():
|
||||
s = StrOption("string", "", default=["string"], multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=[0], multi=True)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"],
|
||||
requires=[('int', [1, 1], 'hidden')], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
assert not 'hidden' in setting[stroption]
|
||||
config.int = [1, 1]
|
||||
raises(PropertiesOptionError, "config.str = ['a', 'b']")
|
||||
assert 'hidden' in setting[stroption]
|
||||
raises(ValueError, "StrOption('str', 'Test string option', default=['abc'], requires=[(intoption, 1, 'hidden')], multi=True)")
|
||||
|
||||
|
||||
def test_multi_with_bool():
|
||||
|
@ -20,10 +20,10 @@ def make_description():
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=(('gc.name', 'ref', 'hidden'),))
|
||||
requires=((gcoption, 'ref', 'hidden'),))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=(('gc.name', 'framework', 'hidden'),))
|
||||
requires=((gcoption, 'framework', 'hidden'),))
|
||||
|
||||
# ____________________________________________________________
|
||||
booloptiontwo = BoolOption('booltwo', 'Test boolean option two', default=False)
|
||||
|
@ -749,7 +749,16 @@ def validate_requires_arg(requires, name):
|
||||
for req in requires:
|
||||
if not type(req) == tuple:
|
||||
raise ValueError(_("malformed requirements type for option:"
|
||||
" {0}, must be a tuple").format(name))
|
||||
" {0}, must be a tuple").format(name))
|
||||
if not isinstance(req[0], Option):
|
||||
raise ValueError(_('malformed requirements first argument '
|
||||
'must be an option in option {0}').format(name))
|
||||
if req[0].optimpl_is_multi():
|
||||
raise ValueError(_('malformed requirements option {0} '
|
||||
'should not be a multi').format(name))
|
||||
if not req[0]._validate(req[1]):
|
||||
raise ValueError(_('malformed requirements second argument '
|
||||
'must be valid for option {0}').format(name))
|
||||
if len(req) == 3:
|
||||
action = req[2]
|
||||
inverse = False
|
||||
|
@ -359,15 +359,17 @@ def apply_requires(opt, config):
|
||||
settings = config.cfgimpl_get_settings()
|
||||
setting = Property(settings, settings._get_properties(opt, False), opt)
|
||||
trigger_actions = build_actions(opt._requires)
|
||||
optpath = config.cfgimpl_get_context().cfgimpl_get_description().optimpl_get_path_by_opt(opt)
|
||||
descr = config.cfgimpl_get_context().cfgimpl_get_description()
|
||||
optpath = descr.optimpl_get_path_by_opt(opt)
|
||||
for requires in trigger_actions.values():
|
||||
matches = False
|
||||
for require in requires:
|
||||
if len(require) == 3:
|
||||
path, expected, action = require
|
||||
option, expected, action = require
|
||||
inverse = False
|
||||
elif len(require) == 4:
|
||||
path, expected, action, inverse = require
|
||||
option, expected, action, inverse = require
|
||||
path = descr.optimpl_get_path_by_opt(option)
|
||||
if path == optpath or path.startswith(optpath + '.'):
|
||||
raise RequirementRecursionError(_("malformed requirements "
|
||||
"imbrication detected for option: '{0}' "
|
||||
|
Loading…
Reference in New Issue
Block a user