check with option as parameter

This commit is contained in:
Emmanuel Garette 2015-09-17 21:25:32 +02:00
parent 5ea92d3460
commit 3aad913868
3 changed files with 19 additions and 9 deletions

View file

@ -1,3 +1,6 @@
Thu Sep 17 21:23:34 2015 +0200 Emmanuel Garette <egarette@cadoles.com>
* check with option as parameter
Sun Jul 26 19:09:29 2015 +0200 Emmanuel Garette <egarette@cadoles.com> Sun Jul 26 19:09:29 2015 +0200 Emmanuel Garette <egarette@cadoles.com>
* add global 'empty' property, this property raise mandatory * add global 'empty' property, this property raise mandatory
PropertiesOptionError if multi or master have empty value PropertiesOptionError if multi or master have empty value

View file

@ -14,6 +14,7 @@ from tiramisu.i18n import _
def return_true(value, param=None): def return_true(value, param=None):
if value == 'val' and param in [None, 'yes']: if value == 'val' and param in [None, 'yes']:
return True return True
raise ValueError('error')
def return_false(value, param=None): def return_false(value, param=None):
@ -59,9 +60,13 @@ def test_validator_params_key():
def test_validator_params_option(): def test_validator_params_option():
opt0 = StrOption('opt0', '', default='val') opt0 = StrOption('opt0', '', default='yes')
opt0 opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val')
raises(ValueError, "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(): def test_validator_multi():

View file

@ -25,7 +25,8 @@ import warnings
from tiramisu.i18n import _ from tiramisu.i18n import _
from tiramisu.setting import log, undefined from tiramisu.setting import log, undefined
from tiramisu.autolib import carry_out_calculation 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 from tiramisu.storage import get_storages_option
@ -77,8 +78,6 @@ def validate_callback(callback, callback_params, type_):
'as length')) 'as length'))
else: else:
option, force_permissive = callbk 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 \ if not isinstance(option, Option) and not \
isinstance(option, SymLinkOption): # pragma: optional cover isinstance(option, SymLinkOption): # pragma: optional cover
raise ValueError(_('{0}_params must have an option' raise ValueError(_('{0}_params must have an option'
@ -531,9 +530,12 @@ class Option(OnlyOption):
else: else:
validator_params_ = {'': (val,)} validator_params_ = {'': (val,)}
# Raise ValueError if not valid # Raise ValueError if not valid
try:
carry_out_calculation(self, context=context, carry_out_calculation(self, context=context,
callback=validator, callback=validator,
callback_params=validator_params_) callback_params=validator_params_)
except ContextError:
pass
def do_validation(_value, _index, submulti_index): def do_validation(_value, _index, submulti_index):
if _value is None: if _value is None: