From 620eaa646131a75a8b825d209d36d5f9c07c8cea Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Thu, 13 Sep 2018 07:00:12 +0200 Subject: [PATCH] can remove config from a metaconfig --- ChangeLog | 4 ++++ test/test_metaconfig.py | 11 +++++++++++ tiramisu/api.py | 4 ++++ tiramisu/config.py | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index ee61e37..b6872e7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Sep 8 22:54:12 2018 +0200 Emmanuel Garette + * propose a new API to access to Tiramisu Option + This new API is totally incompatible with older's one + Sat Jul 8 15:57:13 2017 +0200 Emmanuel Garette * better cache, only remove value/property from cache for value modified and for all value affected by this modification diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index ebecafd..1da4887 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -185,6 +185,17 @@ def test_meta_new_config(): assert len(list(meta.config.list())) == 3 +def test_meta_pop_config(): + od = make_description() + meta = MetaConfig(['name1', 'name2'], optiondescription=od) + assert len(list(meta.config.list())) == 2 + meta.config.new('newconf1') + assert len(list(meta.config.list())) == 3 + meta.config.pop('newconf1') + assert len(list(meta.config.list())) == 2 + raises(ConfigError, "meta.config.pop('newconf1')") + + def test_meta_new_config_wrong_name(): od = make_description() meta = MetaConfig(['name1', 'name2'], optiondescription=od) diff --git a/tiramisu/api.py b/tiramisu/api.py index d7377e5..3ff308c 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -1002,6 +1002,10 @@ class TiramisuContextConfig(TiramisuContext): persistent=False): return Config(self.config_bag.context.new_config(session_id=session_id, persistent=persistent)) + def _m_pop(self, + session_id): + return Config(self.config_bag.context.pop_config(session_id=session_id)) + def _m_list(self): return self._g_list() diff --git a/tiramisu/config.py b/tiramisu/config.py index 4803cde..aa04f50 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -1140,3 +1140,10 @@ class KernelMetaConfig(KernelGroupConfig): config._impl_meta = weakref.ref(self) self._impl_children.append(config) return config + + def pop_config(self, + session_id): + for idx, child in enumerate(self._impl_children): # pragma: no cover + if session_id == child._impl_name: + return self._impl_children.pop(idx) + raise ConfigError(_('cannot find the config {}').format(session_id))