From 3aad91386822760a7e387029f44a76ac38709753 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 17 Sep 2015 21:25:32 +0200 Subject: [PATCH] check with option as parameter --- ChangeLog | 3 +++ test/test_option_validator.py | 11 ++++++++--- tiramisu/option/baseoption.py | 14 ++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68f2dbc..f5ec88f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Thu Sep 17 21:23:34 2015 +0200 Emmanuel Garette + * check with option as parameter + Sun Jul 26 19:09:29 2015 +0200 Emmanuel Garette * add global 'empty' property, this property raise mandatory PropertiesOptionError if multi or master have empty value diff --git a/test/test_option_validator.py b/test/test_option_validator.py index 168aed5..2ba9aec 100644 --- a/test/test_option_validator.py +++ b/test/test_option_validator.py @@ -14,6 +14,7 @@ from tiramisu.i18n import _ def return_true(value, param=None): if value == 'val' and param in [None, 'yes']: return True + raise ValueError('error') def return_false(value, param=None): @@ -59,9 +60,13 @@ def test_validator_params_key(): def test_validator_params_option(): - opt0 = StrOption('opt0', '', default='val') - opt0 - raises(ValueError, "opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val')") + opt0 = StrOption('opt0', '', default='yes') + opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val') + r = OptionDescription('root', '', [opt0, opt1]) + cfg = Config(r) + cfg.opt1 + cfg.opt0 = 'val' + raises(ValueError, "cfg.opt1") def test_validator_multi(): diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 6f0564e..7895661 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -25,7 +25,8 @@ import warnings from tiramisu.i18n import _ from tiramisu.setting import log, undefined from tiramisu.autolib import carry_out_calculation -from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError +from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError,\ + ContextError from tiramisu.storage import get_storages_option @@ -77,8 +78,6 @@ def validate_callback(callback, callback_params, type_): 'as length')) else: option, force_permissive = callbk - if type_ == 'validator' and not force_permissive: # pragma: optional cover - raise ValueError(_('validator not support tuple')) if not isinstance(option, Option) and not \ isinstance(option, SymLinkOption): # pragma: optional cover raise ValueError(_('{0}_params must have an option' @@ -531,9 +530,12 @@ class Option(OnlyOption): else: validator_params_ = {'': (val,)} # Raise ValueError if not valid - carry_out_calculation(self, context=context, - callback=validator, - callback_params=validator_params_) + try: + carry_out_calculation(self, context=context, + callback=validator, + callback_params=validator_params_) + except ContextError: + pass def do_validation(_value, _index, submulti_index): if _value is None: