copy the context in carry_out_calculation
This commit is contained in:
parent
e71beac4dc
commit
18d6976183
|
@ -1,3 +1,6 @@
|
|||
Wed Jan 11 22:56:30 2017 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
* copy the context in carry_out_calculation
|
||||
|
||||
Thu Jan 10 11:55:02 2017 +0200 Gwenael Remond <gremond@cadoles.com>
|
||||
* converts the doc informations into unicode
|
||||
|
||||
|
|
|
@ -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')")
|
||||
|
|
|
@ -148,7 +148,7 @@ def carry_out_calculation(option, context, callback, callback_params,
|
|||
return undefined
|
||||
if callbk[0] is None: # pragma: optional cover
|
||||
#Not an option, set full context
|
||||
tcparams.setdefault(key, []).append((context, False))
|
||||
tcparams.setdefault(key, []).append((context.duplicate(), False))
|
||||
else:
|
||||
# callbk is something link (opt, True|False)
|
||||
opt, force_permissive = callbk
|
||||
|
|
|
@ -678,11 +678,14 @@ class _CommonConfig(SubConfig):
|
|||
return fake_config
|
||||
|
||||
def duplicate(self):
|
||||
config = Config(self._impl_descr)
|
||||
config = Config(self._impl_descr, _duplicate=True)
|
||||
session = self.cfgimpl_get_values()._p_.getsession()
|
||||
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(session))
|
||||
config.cfgimpl_get_settings()._p_._properties = self.cfgimpl_get_settings()._p_.get_modified_properties()
|
||||
config.cfgimpl_get_settings()._p_._permissives = self.cfgimpl_get_settings()._p_.get_modified_permissives()
|
||||
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(
|
||||
session))
|
||||
config.cfgimpl_get_settings()._p_._properties = self.cfgimpl_get_settings(
|
||||
)._p_.get_modified_properties()
|
||||
config.cfgimpl_get_settings()._p_._permissives = self.cfgimpl_get_settings(
|
||||
)._p_.get_modified_permissives()
|
||||
return config
|
||||
|
||||
|
||||
|
@ -692,7 +695,8 @@ class Config(_CommonConfig):
|
|||
__slots__ = ('__weakref__', '_impl_test', '_impl_name')
|
||||
|
||||
def __init__(self, descr, session_id=None, persistent=False,
|
||||
name=undefined, force_values=None, force_settings=None):
|
||||
name=undefined, force_values=None, force_settings=None,
|
||||
_duplicate=False):
|
||||
""" Configuration option management master class
|
||||
|
||||
:param descr: describes the configuration schema
|
||||
|
@ -722,7 +726,7 @@ class Config(_CommonConfig):
|
|||
self._impl_meta = None
|
||||
#undocumented option used only in test script
|
||||
self._impl_test = False
|
||||
if force_settings is None or force_values is None:
|
||||
if _duplicate is False and (force_settings is None or force_values is None):
|
||||
self._impl_build_all_caches()
|
||||
self._impl_name = name
|
||||
|
||||
|
|
|
@ -560,7 +560,8 @@ class Option(OnlyOption):
|
|||
self.impl_get_display_name())
|
||||
return ValueError(msg)
|
||||
error = None
|
||||
if (display_error and not self._is_warnings_only()) or (display_warnings and self._is_warnings_only()):
|
||||
if ((display_error and not self._is_warnings_only()) or
|
||||
(display_warnings and self._is_warnings_only())):
|
||||
error = calculation_validator(_value)
|
||||
if not error:
|
||||
error = self._second_level_validation(_value, self._is_warnings_only())
|
||||
|
|
Loading…
Reference in New Issue