From 4310d59991b90be9dd743d0a4c1a15045909cb3e Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sun, 26 Oct 2014 10:26:23 +0100 Subject: [PATCH] add force_permissive to config __iter__ --- ChangeLog | 1 + test/test_config.py | 2 +- test/test_parsing_group.py | 27 +++++++++++++++++++++++---- tiramisu/config.py | 5 +++-- tiramisu/value.py | 2 +- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 04dcd46..174d011 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ Sun Oct 26 08:50:38 2014 +0200 Emmanuel Garette must be 'default' check property when tried to change owner * bad characters in DomainnameOption could be in warning level * frozen with force_default_on_freeze can change owner + * add force_permissive to config __iter__ Sat Oct 25 22:48:08 2014 +0200 Emmanuel Garette * cannot add unvalaible consistency for an option diff --git a/test/test_config.py b/test/test_config.py index 6ac48d4..8c41305 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -236,7 +236,7 @@ def test_values_not_setitem(): d1 = OptionDescription('od', '', [g1, g2, g3, g4, g5]) root = OptionDescription('root', '', [d1]) config = Config(root) - raises(ValueError, "config.cfgimpl_get_values()[g1] = 2") + raises(ConfigError, "config.cfgimpl_get_values()[g1] = 2") def test_duplicated_option(): diff --git a/test/test_parsing_group.py b/test/test_parsing_group.py index 3c3175d..62c162f 100644 --- a/test/test_parsing_group.py +++ b/test/test_parsing_group.py @@ -18,12 +18,15 @@ def make_description(): default=False) mode_conteneur_actif = BoolOption('mode_conteneur_actif', "le serveur est en mode conteneur", default=False) + mode_conteneur_actif2 = BoolOption('mode_conteneur_actif2', "le serveur est en mode conteneur2", + default=False, properties=('hidden',)) + adresse_serveur_ntp = StrOption('serveur_ntp', "adresse serveur ntp", multi=True) time_zone = ChoiceOption('time_zone', 'fuseau horaire du serveur', ('Paris', 'Londres'), 'Paris') - ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé") - netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau") + ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", properties=('test_perm',)) + netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", properties=('test_perm',)) master = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = OptionDescription('interface1', '', [master]) @@ -31,8 +34,8 @@ def make_description(): general = OptionDescription('general', '', [numero_etab, nom_machine, nombre_interfaces, activer_proxy_client, - mode_conteneur_actif, adresse_serveur_ntp, - time_zone]) + mode_conteneur_actif, mode_conteneur_actif2, + adresse_serveur_ntp, time_zone]) general.impl_set_group_type(groups.family) new = OptionDescription('new', '', [], properties=('hidden',)) new.impl_set_group_type(groups.family) @@ -102,6 +105,22 @@ def test_iter_on_groups(): def test_iter_on_groups_force_permissive(): + descr = make_description() + config = Config(descr) + config.read_write() + config.cfgimpl_get_settings().setpermissive(('hidden',)) + result = list(config.creole.general.__iter__(force_permissive=True)) + group_names = [res[0] for res in result] + ass = ['numero_etab', 'nom_machine', 'nombre_interfaces', + 'activer_proxy_client', 'mode_conteneur_actif', + 'mode_conteneur_actif2', 'serveur_ntp', 'time_zone'] + assert group_names == ass + group_names = [res[0] for res in config.creole.general] + ass.remove('mode_conteneur_actif2') + assert group_names == ass + + +def test_iter_group_on_groups_force_permissive(): descr = make_description() config = Config(descr) config.read_write() diff --git a/tiramisu/config.py b/tiramisu/config.py index d6347c8..da97f9e 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -97,7 +97,7 @@ class SubConfig(object): # return not self == other # ______________________________________________________________________ - def __iter__(self): + def __iter__(self, force_permissive=False): """Pythonesque way of parsing group's ordered options. iteration only on Options (not OptionDescriptions)""" for child in self.cfgimpl_get_description()._impl_getchildren( @@ -105,7 +105,8 @@ class SubConfig(object): if not child.impl_is_optiondescription(): try: name = child.impl_getname() - yield name, getattr(self, name) + yield name, self.getattr(name, + force_permissive=force_permissive) except GeneratorExit: # pragma: optional cover raise StopIteration except PropertiesOptionError: # pragma: optional cover diff --git a/tiramisu/value.py b/tiramisu/value.py index 4575cbf..6d0ea70 100644 --- a/tiramisu/value.py +++ b/tiramisu/value.py @@ -300,7 +300,7 @@ class Values(object): return value def __setitem__(self, opt, value): # pragma: optional cover - raise ValueError(_('you should only set value with config')) + raise ConfigError(_('you should only set value with config')) def setitem(self, opt, value, path, force_permissive=False, is_write=True):