From aa11e3b79cf8a74fbaacf49c3d14578da1475201 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 5 Jun 2019 14:37:58 +0200 Subject: [PATCH] can retrieve metaconfig/mixconfig/config in a metaconfig/mixconfig --- tests/test_metaconfig.py | 9 +++++++++ tests/test_mixconfig.py | 11 +++++++++++ tiramisu/api.py | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/tests/test_metaconfig.py b/tests/test_metaconfig.py index d463a9f..02f049e 100644 --- a/tests/test_metaconfig.py +++ b/tests/test_metaconfig.py @@ -1140,3 +1140,12 @@ def test_metaconfig_force_metaconfig_on_freeze_option(): config.option('dummy1').property.pop('frozen') assert config.option('dummy1').value.get() == 'config' assert config.option('dummy1').owner.get() == 'config' + + +def test_meta_get_config(): + od = make_description() + meta = MetaConfig(['name1', 'name2'], optiondescription=od) + meta.config.new('meta1', type='metaconfig') + assert isinstance(meta.config.get('meta1'), MetaConfig) + assert isinstance(meta.config.get('name1'), Config) + raises(ConfigError, "meta.config.get('unknown')") diff --git a/tests/test_mixconfig.py b/tests/test_mixconfig.py index 259e973..aadbc51 100644 --- a/tests/test_mixconfig.py +++ b/tests/test_mixconfig.py @@ -1129,3 +1129,14 @@ def test_meta_new_mixconfig(): conf = Config(od, session_id='conf1') meta = MetaConfig([conf]) assert isinstance(meta.config.new('mixconfig', type="mixconfig"), MixConfig) + + +def test_meta_get_mixconfig(): + od = make_description() + conf = Config(od, session_id='conf1') + meta = MetaConfig([conf]) + meta.config.new('mixconfig', type="mixconfig") + assert isinstance(meta.config.get('mixconfig'), MixConfig) + raises(ConfigError, "meta.config.get('unknown')") + meta.config.get('mixconfig').config.add(MixConfig(od, [], session_id='mixconfig2')) + assert isinstance(meta.config.get('mixconfig').config.get('mixconfig2'), MixConfig) diff --git a/tiramisu/api.py b/tiramisu/api.py index 485fde3..6662ec4 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -1339,6 +1339,10 @@ class _TiramisuContextGroupConfig(TiramisuContext): def path(self): return self._config_bag.context.cfgimpl_get_config_path() + def get(self, + name: str) -> 'Config': + return self._return_config(self._config_bag.context.getconfig(name)) + class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextConfigReset): """Actions to MixConfig"""