copy the context in carry_out_calculation
This commit is contained in:
@ -34,6 +34,12 @@ def return_if_val(value):
|
||||
return ValueError('test error')
|
||||
|
||||
|
||||
def is_context(value, context):
|
||||
context.cfgimpl_get_settings().remove('validator')
|
||||
if not isinstance(context, Config):
|
||||
raise ValueError('not context')
|
||||
|
||||
|
||||
def test_validator():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, default='val')
|
||||
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
|
||||
@ -54,6 +60,15 @@ def test_validator_params():
|
||||
raises(ValueError, "cfg.opt2 = 'val'")
|
||||
|
||||
|
||||
def test_validator_params_context():
|
||||
opt1 = StrOption('opt1', '', validator=is_context, validator_params={'': ((None,),)}, default='val')
|
||||
root = OptionDescription('root', '', [opt1])
|
||||
cfg = Config(root)
|
||||
assert 'validator' in cfg.cfgimpl_get_settings()
|
||||
assert cfg.opt1 == 'val'
|
||||
assert 'validator' in cfg.cfgimpl_get_settings()
|
||||
|
||||
|
||||
def test_validator_params_key():
|
||||
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val')
|
||||
raises(TypeError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')")
|
||||
|
Reference in New Issue
Block a user