copy the context in carry_out_calculation

This commit is contained in:
Emmanuel Garette 2017-01-11 22:58:01 +01:00
parent e71beac4dc
commit 18d6976183
5 changed files with 31 additions and 8 deletions

View File

@ -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> Thu Jan 10 11:55:02 2017 +0200 Gwenael Remond <gremond@cadoles.com>
* converts the doc informations into unicode * converts the doc informations into unicode

View File

@ -34,6 +34,12 @@ def return_if_val(value):
return ValueError('test error') 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(): def test_validator():
opt1 = StrOption('opt1', '', validator=return_true, default='val') opt1 = StrOption('opt1', '', validator=return_true, default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, default='val')")
@ -54,6 +60,15 @@ def test_validator_params():
raises(ValueError, "cfg.opt2 = 'val'") 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(): def test_validator_params_key():
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val') 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')") raises(TypeError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')")

View File

@ -148,7 +148,7 @@ def carry_out_calculation(option, context, callback, callback_params,
return undefined return undefined
if callbk[0] is None: # pragma: optional cover if callbk[0] is None: # pragma: optional cover
#Not an option, set full context #Not an option, set full context
tcparams.setdefault(key, []).append((context, False)) tcparams.setdefault(key, []).append((context.duplicate(), False))
else: else:
# callbk is something link (opt, True|False) # callbk is something link (opt, True|False)
opt, force_permissive = callbk opt, force_permissive = callbk

View File

@ -678,11 +678,14 @@ class _CommonConfig(SubConfig):
return fake_config return fake_config
def duplicate(self): def duplicate(self):
config = Config(self._impl_descr) config = Config(self._impl_descr, _duplicate=True)
session = self.cfgimpl_get_values()._p_.getsession() session = self.cfgimpl_get_values()._p_.getsession()
config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(session)) config.cfgimpl_get_values()._p_.importation(self.cfgimpl_get_values()._p_.exportation(
config.cfgimpl_get_settings()._p_._properties = self.cfgimpl_get_settings()._p_.get_modified_properties() session))
config.cfgimpl_get_settings()._p_._permissives = self.cfgimpl_get_settings()._p_.get_modified_permissives() 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 return config
@ -692,7 +695,8 @@ class Config(_CommonConfig):
__slots__ = ('__weakref__', '_impl_test', '_impl_name') __slots__ = ('__weakref__', '_impl_test', '_impl_name')
def __init__(self, descr, session_id=None, persistent=False, 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 """ Configuration option management master class
:param descr: describes the configuration schema :param descr: describes the configuration schema
@ -722,7 +726,7 @@ class Config(_CommonConfig):
self._impl_meta = None self._impl_meta = None
#undocumented option used only in test script #undocumented option used only in test script
self._impl_test = False 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_build_all_caches()
self._impl_name = name self._impl_name = name

View File

@ -560,7 +560,8 @@ class Option(OnlyOption):
self.impl_get_display_name()) self.impl_get_display_name())
return ValueError(msg) return ValueError(msg)
error = None 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) error = calculation_validator(_value)
if not error: if not error:
error = self._second_level_validation(_value, self._is_warnings_only()) error = self._second_level_validation(_value, self._is_warnings_only())