diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index 38d3053..b29ef38 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -40,7 +40,7 @@ def make_metaconfig(double=False): meta = MetaConfig([conf1, conf2], session_id='meta') if double: meta.owner.set(owners.meta2) - meta = MetaConfig([meta]) + meta = MetaConfig([meta], session_id='doublemeta') meta.property.read_write() meta.owner.set(owners.meta1) return meta @@ -199,16 +199,28 @@ def test_meta_meta_set(): errors2 = meta.value.set('od1.i6', 7, only_config=True) assert len(errors1) == 0 assert len(errors2) == 2 - meta = meta._config.getconfig('meta') - conf1 = meta.getconfig('conf1') - conf2 = meta.getconfig('conf2') + conf1 = meta.config('meta.conf1')._config.context + conf2 = meta.config('meta.conf2')._config.context assert meta.config('meta.conf1').option('od1.i1').value.get() == meta.config('meta.conf2').option('od1.i1').value.get() == 7 - assert [conf1, conf2] == meta.config.find('i1', value=7, first=True).cfgimpl_get_children() + # + dconfigs = [] + for conf in meta.config.find('i1', value=7, first=True).config.list(): + dconfigs.append(conf._config) + assert [conf1, conf2] == dconfigs meta.config('meta.conf1').option('od1.i1').value.set(8) - assert [conf1, conf2] == meta.config.find('i1', first=True).cfgimpl_get_children() - assert [conf2] == meta.config.find('i1', value=7, first=True).cfgimpl_get_children() - assert [conf1] == meta.config.find('i1', value=8, first=True).cfgimpl_get_children() - assert [conf1, conf2] == meta.config.find('i5', value=2, first=True).cfgimpl_get_children() + # + dconfigs = [] + for conf in meta.config.find('i1', first=True).config.list(): + dconfigs.append(conf._config) + assert [conf1, conf2] == dconfigs + assert conf2 == list(meta.config.find('i1', value=7, first=True).config.list())[0]._config + assert conf1 == list(meta.config.find('i1', value=8, first=True).config.list())[0]._config + # + dconfigs = [] + for conf in meta.config.find('i5', value=2, first=True).config.list(): + dconfigs.append(conf._config) + assert [conf1, conf2] == dconfigs + # raises(AttributeError, "meta.config.find('i1', value=10, first=True)") raises(AttributeError, "meta.config.find('not', value=10, first=True)") raises(AttributeError, "meta.config.find('i6', first=True)") @@ -245,7 +257,9 @@ def test_group_find_firsts(): conf1 = Config(od2, session_id='conf1') conf2 = Config(od2, session_id='conf2') grp = GroupConfig([conf1, conf2]) - assert [conf1._config, conf2._config] == grp.config.find('i1', first=True).cfgimpl_get_children() + itr = grp.config.find('i1', first=True).config.list() + conf1._config == next(itr)._config + conf2._config == next(itr)._config def test_group_group(): @@ -293,13 +307,21 @@ def test_meta_master_slaves(): conf2 = Config(od, session_id='conf2') meta = MetaConfig([conf1, conf2]) meta.property.read_only() - assert [conf1._config, conf2._config] == meta.config.find('ip_admin_eth0', first=True).cfgimpl_get_children() - assert [conf1._config, conf2._config] == meta.config.find('netmask_admin_eth0', first=True).cfgimpl_get_children() + itr = meta.config.find('ip_admin_eth0', first=True).config.list() + assert conf1._config == next(itr)._config + assert conf2._config == next(itr)._config + itr = meta.config.find('netmask_admin_eth0', first=True).config.list() + assert conf1._config == next(itr)._config + assert conf2._config == next(itr)._config meta.property.read_write() raises(AttributeError, "meta.config.find('netmask_admin_eth0', first=True)") - assert [conf1._config, conf2._config] == meta.unrestraint.config.find('netmask_admin_eth0', first=True).cfgimpl_get_children() + itr = meta.unrestraint.config.find('netmask_admin_eth0', first=True).config.list() + assert conf1._config == next(itr)._config + assert conf2._config == next(itr)._config meta.property.read_only() - assert [conf1._config, conf2._config] == meta.config.find('netmask_admin_eth0', first=True).cfgimpl_get_children() + itr = meta.config.find('netmask_admin_eth0', first=True).config.list() + assert conf1._config == next(itr)._config + assert conf2._config == next(itr)._config def test_meta_master_slaves_value2(): diff --git a/tiramisu/api.py b/tiramisu/api.py index f6ed3d9..5eb0063 100644 --- a/tiramisu/api.py +++ b/tiramisu/api.py @@ -850,8 +850,12 @@ class TiramisuContextOption(TiramisuContext): withoption=None, fullpath=False): """return dict with path as key and value""" - config_bag = self.config_bag.copy() - config_bag._setting_properties = self.config_bag.setting_properties - {'warnings'} + #config_bag = self.config_bag + if self.config_bag.setting_properties is None: + config_bag = self.config_bag + else: + config_bag = self.config_bag.copy() + config_bag._setting_properties = self.config_bag.setting_properties - {'warnings'} return config_bag.context.make_dict(config_bag, flatten=flatten, fullpath=fullpath, @@ -919,9 +923,9 @@ class TiramisuContextConfig(TiramisuContext): first: bool=False): """find a path from option name and optionnaly a value to MetaConfig or GroupConfig""" if first: - return self.config_bag.context.find_firsts(byname=name, - byvalue=value, - config_bag=self.config_bag) + return TiramisuAPI(self.config_bag.context.find_firsts(byname=name, + byvalue=value, + config_bag=self.config_bag)) else: raise APIError('not implemented yet') diff --git a/tiramisu/setting.py b/tiramisu/setting.py index 78fbace..46bd6c5 100644 --- a/tiramisu/setting.py +++ b/tiramisu/setting.py @@ -181,7 +181,8 @@ class ConfigBag: return 'validator' in self._setting_properties return self._validate if key == 'setting_properties': - if self.force_unrestraint or not self._validate: + #if self.force_unrestraint or not self._validate: + if self.force_unrestraint: return None return self._setting_properties if key == '_setting_properties': @@ -196,6 +197,11 @@ class ConfigBag: def __setattr__(self, key, value): if key == 'validate': self._validate = value + #FIXME + try: + del self._setting_properties + except AttributeError: + pass else: super().__setattr__(key, value)