add force_permissive to config __iter__
This commit is contained in:
parent
a130cff4bf
commit
4310d59991
@ -3,6 +3,7 @@ Sun Oct 26 08:50:38 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||
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 <egarette@cadoles.com>
|
||||
* cannot add unvalaible consistency for an option
|
||||
|
@ -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():
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user