add path to config

This commit is contained in:
Emmanuel Garette 2019-02-06 21:47:11 +01:00
parent 08bae1d131
commit 0a5e7c5886
4 changed files with 38 additions and 1 deletions

View File

@ -56,6 +56,13 @@ def test_unknown_config():
raises(ConfigError, "meta.config('unknown')")
def test_path():
meta = make_metaconfig()
assert meta.config.path() == 'meta'
assert meta.config('conf1').config.path() == 'meta.conf1'
assert meta.config('conf2').config.path() == 'meta.conf2'
#FIXME ne pas mettre 2 meta dans une config
#FIXME ne pas mettre 2 OD differents dans un meta
def test_none():
@ -335,6 +342,20 @@ def test_group_group():
assert grp2.config('grp.conf9').option('od1.i1').owner.get() is owners.user
def test_group_group_path():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])
od2 = OptionDescription('od2', '', [od1])
conf1 = Config(od2, session_id='conf9')
conf2 = Config(od2, session_id='conf10')
grp = GroupConfig([conf1, conf2], 'grp')
grp2 = GroupConfig([grp], 'grp2')
assert grp2.config.path() == 'grp2'
assert grp2.config('grp').config.path() == 'grp'
assert grp2.config('grp.conf9').config.path() == 'conf9'
assert grp2.config('grp.conf10').config.path() == 'conf10'
def test_meta_unconsistent():
i1 = IntOption('i1', '')
i2 = IntOption('i2', '', default=1)

View File

@ -90,6 +90,14 @@ def make_mixconfig(double=False):
return mix
def test_mix_name():
mix = make_mixconfig(True)
assert mix.config.path() == 'doublemix'
assert mix.config('mix').config.path() == 'doublemix.mix'
assert mix.config('mix.conf1').config.path() == 'doublemix.mix.conf1'
assert mix.config('mix.conf2').config.path() == 'doublemix.mix.conf2'
def test_mix_not_group():
i1 = IntOption('i1', '')
od1 = OptionDescription('od1', '', [i1])

View File

@ -1167,6 +1167,9 @@ class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
def metaconfig(self):
return Config(self._config_bag.context.cfgimpl_get_meta())
def path(self):
return self._config_bag.context.cfgimpl_get_path()
class _TiramisuContextGroupConfig(TiramisuContext):
"""Actions to GroupConfig"""
@ -1198,6 +1201,9 @@ class _TiramisuContextGroupConfig(TiramisuContext):
config = config.getconfig(spath)
return Config(config)
def path(self):
return self._config_bag.context.cfgimpl_get_path()
class _TiramisuContextMixConfig(_TiramisuContextGroupConfig, _TiramisuContextConfigReset):
"""Actions to MixConfig"""

View File

@ -618,7 +618,9 @@ class _CommonConfig(SubConfig):
descr.impl_build_force_store_values(config_bag)
def cfgimpl_get_path(self, dyn=True):
return None
if self._impl_meta is None or self._impl_meta() is None:
return self._impl_name
return self._impl_meta().cfgimpl_get_path() + '.' + self._impl_name
def cfgimpl_get_meta(self):
if self._impl_meta is not None: