From 18d69761835e3ab3f285f2985708c5c16040465b Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 11 Jan 2017 22:58:01 +0100 Subject: [PATCH] copy the context in carry_out_calculation --- ChangeLog | 3 +++ test/test_option_validator.py | 15 +++++++++++++++ tiramisu/autolib.py | 2 +- tiramisu/config.py | 16 ++++++++++------ tiramisu/option/baseoption.py | 3 ++- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 792ab36..ba6bfc9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Wed Jan 11 22:56:30 2017 +0200 Emmanuel Garette + * copy the context in carry_out_calculation + Thu Jan 10 11:55:02 2017 +0200 Gwenael Remond * converts the doc informations into unicode diff --git a/test/test_option_validator.py b/test/test_option_validator.py index eedffb6..27d060f 100644 --- a/test/test_option_validator.py +++ b/test/test_option_validator.py @@ -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')") diff --git a/tiramisu/autolib.py b/tiramisu/autolib.py index 31ab32f..0ddf1f9 100644 --- a/tiramisu/autolib.py +++ b/tiramisu/autolib.py @@ -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 diff --git a/tiramisu/config.py b/tiramisu/config.py index 43ac14d..3e398ec 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -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 diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index 091d46a..d45f6a4 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -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())