From 2c5bbb7bc00f24c838e51cf3c8a46958f127cba2 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 26 Apr 2013 14:40:44 +0200 Subject: [PATCH] Requires need option, not path Valid requires --- test/test_freeze.py | 4 ++-- test/test_option_consistency.py | 22 +++++++++++----------- test/test_option_setting.py | 23 +++++++---------------- test/test_option_type.py | 4 ++-- tiramisu/option.py | 11 ++++++++++- tiramisu/setting.py | 8 +++++--- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/test/test_freeze.py b/test/test_freeze.py index ab02f62..277768e 100644 --- a/test/test_freeze.py +++ b/test/test_freeze.py @@ -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, diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index 9da0df0..0d39d5b 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -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, diff --git a/test/test_option_setting.py b/test/test_option_setting.py index 56892a0..56ba2cb 100644 --- a/test/test_option_setting.py +++ b/test/test_option_setting.py @@ -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(): diff --git a/test/test_option_type.py b/test/test_option_type.py index 8456663..b678ebb 100644 --- a/test/test_option_type.py +++ b/test/test_option_type.py @@ -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) diff --git a/tiramisu/option.py b/tiramisu/option.py index 9a11e0d..e973489 100644 --- a/tiramisu/option.py +++ b/tiramisu/option.py @@ -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 diff --git a/tiramisu/setting.py b/tiramisu/setting.py index abeb4a7..aac0806 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -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}' "