check with option as parameter
This commit is contained in:
parent
5ea92d3460
commit
3aad913868
|
@ -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>
|
||||
* add global 'empty' property, this property raise mandatory
|
||||
PropertiesOptionError if multi or master have empty value
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue