error in external function should returns explicit error message
This commit is contained in:
@ -53,6 +53,14 @@ def is_config(config, **kwargs):
|
||||
return 'no'
|
||||
|
||||
|
||||
def return_raise(*arg):
|
||||
raise Exception('test')
|
||||
|
||||
|
||||
def return_valueerror(*arg):
|
||||
raise ValueError('test')
|
||||
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
## dummy 1
|
||||
@ -973,3 +981,21 @@ def test_re_set_callback():
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st2.impl_set_callback(return_value, {'': ((st1, False),)})
|
||||
raises(ConfigError, "st2.impl_set_callback(return_value, {'': ((st1, False),)})")
|
||||
|
||||
|
||||
def test_callback_raise():
|
||||
opt1 = BoolOption('opt1', 'Option 1', callback=return_raise)
|
||||
opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror)
|
||||
od1 = OptionDescription('od1', '', [opt1])
|
||||
od2 = OptionDescription('od2', '', [opt2])
|
||||
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
try:
|
||||
cfg.od1.opt1
|
||||
except Exception, err:
|
||||
assert '"Option 1"' in str(err)
|
||||
try:
|
||||
cfg.od2.opt2
|
||||
except ValueError, err:
|
||||
assert '"Option 2"' in str(err)
|
||||
|
@ -17,12 +17,12 @@ msg_err = _('attention, "{0}" could be an invalid {1} for "{2}", {3}')
|
||||
def return_true(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
return True
|
||||
return ValueError('test error')
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def return_false(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
return ValueError('test error')
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def return_val(value, param=None):
|
||||
@ -31,7 +31,7 @@ def return_val(value, param=None):
|
||||
|
||||
def return_if_val(value):
|
||||
if value != 'val':
|
||||
return ValueError('test error')
|
||||
raise ValueError('test error')
|
||||
|
||||
|
||||
def is_context(value, context):
|
||||
@ -95,6 +95,11 @@ def test_validator():
|
||||
cfg = Config(root)
|
||||
assert cfg.opt1 == 'val'
|
||||
raises(ValueError, "cfg.opt2 = 'val'")
|
||||
try:
|
||||
cfg.opt2 = 'val'
|
||||
except ValueError, err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}", {3}').format('val', _('string'), 'opt2', 'test error')
|
||||
assert str(err) == msg
|
||||
|
||||
|
||||
def test_validator_params():
|
||||
|
Reference in New Issue
Block a user