do not change Config contexts properties when reload in MetaConfig (fixes #7)

This commit is contained in:
Emmanuel Garette 2019-04-05 22:11:54 +02:00
parent 06f501ad05
commit 97b75660c5
3 changed files with 23 additions and 4 deletions

View file

@ -1,4 +1,6 @@
Fri Apr 5 20:57:05 2019 +0200 Emmanuel Garette <egarette@cadoles.com>
* 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 <egarette@cadoles.com>

View file

@ -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])

View file

@ -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)