From 97b75660c5c82332adbf83ed058e7fdbbf099baa Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 5 Apr 2019 22:11:54 +0200 Subject: [PATCH] do not change Config contexts properties when reload in MetaConfig (fixes #7) --- ChangeLog | 2 ++ test/test_storage.py | 17 ++++++++++++++++- tiramisu/config.py | 8 +++++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb21118..fa17527 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ Fri Apr 5 20:57:05 2019 +0200 Emmanuel Garette + * do not change Config contexts properties when reload in MetaConfig + (fixes #7) * add/remove config in mixconfig or metaconfig (fixes #6) Sun Mar 24 20:24:34 2019 +0200 Emmanuel Garette diff --git a/test/test_storage.py b/test/test_storage.py index eac36d4..f1611b3 100644 --- a/test/test_storage.py +++ b/test/test_storage.py @@ -6,7 +6,7 @@ from py.test import raises from tiramisu.error import ConfigError from tiramisu import Config, BoolOption, OptionDescription, Leadership, \ - list_sessions, delete_session, default_storage + list_sessions, delete_session, default_storage, MetaConfig from tiramisu.setting import groups, owners @@ -323,6 +323,21 @@ def test_create_persistent_context_property(): delete_session('test_persistent') +def test_create_persistent_context_property_metaconfig(): + b = BoolOption('b', '') + o = OptionDescription('od', '', [b]) + if default_storage.is_persistent(): + c = Config(o, session_id='test_persistent', persistent=True) + c.property.add('persistent') + del c + # + m = MetaConfig([], optiondescription=o) + c = m.config.new(session_id='test_persistent', persistent=True) + assert 'persistent' in c.property.get() + del c + delete_session('test_persistent') + + def test_create_persistent_property(): b = BoolOption('b', '') o = OptionDescription('od', '', [b]) diff --git a/tiramisu/config.py b/tiramisu/config.py index 95129d1..8e1c222 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -28,7 +28,7 @@ from .error import PropertiesOptionError, ConfigError, ConflictError, \ from .option import SynDynOptionDescription, DynOptionDescription, Leadership from .option.baseoption import BaseOption, valid_name from .setting import OptionBag, ConfigBag, Settings, undefined -from .storage import get_storages, gen_storage_id, get_default_values_storages +from .storage import get_storages, gen_storage_id, get_default_values_storages, list_sessions from .value import Values from .i18n import _ @@ -1247,6 +1247,7 @@ class KernelMetaConfig(KernelMixConfig): raise ConflictError(_('config name must be uniq in ' 'groupconfig for {0}').format(session_id)) assert type_ in ('config', 'metaconfig'), _('unknown type {}').format(type_) + new = not persistent or session_id not in list_sessions() if type_ == 'config': config = KernelConfig(self._impl_descr, session_id=session_id, @@ -1257,8 +1258,9 @@ class KernelMetaConfig(KernelMixConfig): session_id=session_id, persistent=persistent) # Copy context properties/permissives - config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config) - config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives()) + if new: + config.cfgimpl_get_settings().set_context_properties(self.cfgimpl_get_settings().get_context_properties(), config) + config.cfgimpl_get_settings().set_context_permissives(self.cfgimpl_get_settings().get_context_permissives()) config._impl_meta = weakref.ref(self) self._impl_children.append(config)