corrections in dynoption/masterslaves

This commit is contained in:
Emmanuel Garette 2018-03-24 22:37:48 +01:00
parent d5d826f967
commit 6921e05c0e
17 changed files with 115 additions and 299 deletions

View File

@ -1,206 +0,0 @@
"""test consistencies about multi and submulti"""
from py.test import raises
from .autopath import do_autopath
do_autopath()
from tiramisu.setting import groups
from tiramisu import Config, StrOption, IntOption, OptionDescription, MasterSlaves, getapi, \
submulti, undefined
from tiramisu.error import PropertiesOptionError
def return_val(val=None):
if val is None:
return 'val'
else:
return val
def return_list(value=None):
return ['val', 'val']
def return_list2(value=None):
return [['val', 'val']]
def test_multi_unique():
int_ = IntOption('int', '', multi=True, unique=True)
od_ = OptionDescription('od', '', [int_])
cfg = Config(od_)
api = getapi(cfg)
assert api.option('int').value.get() == []
value = [0]
api.option('int').value.set(value)
assert api.option('int').value.get() == value
value.append(1)
assert api.option('int').value.get() == [0]
raises(ValueError, "api.option('int').value.set([0, 0])")
raises(ValueError, "api.option('int').value.set([1, 0, 2, 3, 4, 5, 6, 0, 7])")
def test_multi_none():
str_ = StrOption('str', '', multi=True)
od_ = OptionDescription('od', '', [str_])
cfg = Config(od_)
cfg.read_only()
api = getapi(cfg)
assert api.option('str').value.get() == []
cfg.read_write()
api.option('str').value.set([None])
assert api.option('str').value.get() == [None]
cfg.read_only()
raises(PropertiesOptionError, "api.option('str').value.get()")
cfg.read_write()
api.option('str').value.set([''])
assert api.option('str').value.get() == ['']
cfg.read_only()
raises(PropertiesOptionError, "api.option('str').value.get()")
# ______________ submulti ______________
def test_append_submulti():
multi = StrOption('multi', '', multi=submulti)
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
od_ = OptionDescription('od', '', [multi, multi2, multi3])
cfg = Config(od_)
api = getapi(cfg)
#FIXME
owner = cfg.cfgimpl_get_settings().getowner()
assert api.option('multi').value.get() == []
assert api.option('multi').value.get() == []
assert api.option('multi').owner.isdefault()
api.option('multi').value.set([undefined])
assert api.option('multi').owner.get() == owner
value = api.option('multi').value.get()
assert value == [[]]
value.append(['no'])
assert api.option('multi').value.get() == [[]]
api.option('multi').value.set(value)
assert api.option('multi').value.get() == [[], ['no']]
#
assert api.option('multi2').value.get() == []
assert api.option('multi2').owner.isdefault()
api.option('multi2').value.set([undefined])
assert api.option('multi2').owner.get() == owner
assert api.option('multi2').value.get() == [['yes']]
api.option('multi2').value.set([['yes'], ['no']])
assert api.option('multi2').value.get() == [['yes'], ['no']]
#
assert api.option('multi3').value.get() == [['yes']]
assert api.option('multi3').owner.isdefault()
api.option('multi3').value.set([['yes'], undefined])
assert api.option('multi3').owner.get() == owner
assert api.option('multi3').value.get() == [['yes'], []]
api.option('multi3').value.set([['yes'], [], ['no']])
assert api.option('multi3').value.get() == [['yes'], [], ['no']]
def test_append_unvalide_submulti():
multi = StrOption('multi', '', multi=submulti)
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
od_ = OptionDescription('od', '', [multi, multi2, multi3])
cfg = Config(od_)
api = getapi(cfg)
assert api.option('multi').value.get() == []
assert api.option('multi').owner.isdefault()
raises(ValueError, "api.option('multi').value.set([1])")
assert api.option('multi').value.get() == []
assert api.option('multi').owner.isdefault()
#
assert api.option('multi2').value.get() == []
raises(ValueError, "api.option('multi2').value.set('no')")
assert api.option('multi2').owner.isdefault()
assert api.option('multi2').value.get() == []
#
assert api.option('multi3').value.get() == [['yes']]
assert api.option('multi3').owner.isdefault()
def test_submulti_unique():
int_ = IntOption('int', '', multi=submulti, unique=True)
od_ = OptionDescription('od', '', [int_])
cfg = Config(od_)
api = getapi(cfg)
assert api.option('int').value.get() == []
api.option('int').value.set([[0]])
assert api.option('int').value.get() == [[0]]
raises(ValueError, "api.option('int').value.set([[0, 0]])")
api.option('int').value.set([[0], [0]])
raises(ValueError, "api.option('int').value.set([[0], [1, 0, 2, 3, 4, 5, 6, 0, 7]])")
def test_callback_reset():
multi = StrOption('multi', '', multi=submulti, callback=return_val)
od_ = OptionDescription('od', '', [multi])
cfg = Config(od_)
cfg.read_write()
api = getapi(cfg)
#FIXME
owner = cfg.cfgimpl_get_settings().getowner()
assert api.option('multi').value.get() == [['val']]
assert api.option('multi').owner.isdefault()
api.option('multi').value.set([['val'], undefined])
assert api.option('multi').owner.get() == owner
assert api.option('multi').value.get() == [['val'], ['val']]
api.option('multi').value.reset()
assert api.option('multi').owner.isdefault()
assert api.option('multi').value.get() == [['val']]
api.option('multi').value.set([['val1']])
assert api.option('multi').owner.get() == owner
assert api.option('multi').value.get() == [['val1']]
def test_callback_submulti_list():
multi = StrOption('multi', '', multi=submulti, callback=return_list)
od_ = OptionDescription('od', '', [multi])
cfg = Config(od_)
cfg.read_write()
api = getapi(cfg)
owner = cfg.cfgimpl_get_settings().getowner()
assert api.option('multi').value.get() == [['val', 'val']]
assert api.option('multi').owner.isdefault()
api.option('multi').value.set([['val', 'val'], undefined])
assert api.option('multi').owner.get() == owner
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val']]
api.option('multi').value.set([['val', 'val'], undefined, undefined])
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val'], ['val', 'val']]
api.option('multi').value.reset()
assert api.option('multi').owner.isdefault()
def test_callback_submulti_list_list():
multi = StrOption('multi', '', multi=submulti, callback=return_list2)
od = OptionDescription('od', '', [multi])
cfg = Config(od)
cfg.read_write()
api = getapi(cfg)
owner = api.owner.get()
assert owner == 'user'
assert api.option('multi').value.get() == [['val', 'val']]
assert api.option('multi').owner.isdefault()
api.option('multi').value.set([['val', 'val'], undefined])
assert api.option('multi').owner.get() == owner
assert api.option('multi').value.get() == [['val', 'val'], []]
api.option('multi').value.reset()
assert api.option('multi').owner.isdefault()
#FIXME
#def test_multi_submulti_meta():
# multi = StrOption('multi', '', multi=submulti)
# od = OptionDescription('od', '', [multi])
# conf1 = Config(od, session_id='conf1')
# conf1.read_write()
# conf2 = Config(od, session_id='conf2')
# conf2.read_write()
# meta = MetaConfig([conf1, conf2])
# meta.read_write()
# meta.multi = [['val']]
# assert meta.multi == [['val']]
# multi = conf1.multi[0]
# multi.append()
# assert conf1.multi == [['val', None]]
# assert meta.multi == [['val']]

View File

@ -343,7 +343,7 @@ def test_validator_warning():
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt2').value.set('val') api.option('opt2').value.set('val')
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt == opt2 assert w[0].message.opt() == opt2
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false') assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
@ -353,7 +353,7 @@ def test_validator_warning():
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('opt3').value.set(['val', 'val1']) api.option('opt3').value.set(['val', 'val1'])
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt == opt3 assert w[0].message.opt() == opt3
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error') assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
@ -364,9 +364,9 @@ def test_validator_warning():
api.option('opt2').value.set('val') api.option('opt2').value.set('val')
api.option('opt3').value.set(['val', 'val1', 'val']) api.option('opt3').value.set(['val', 'val1', 'val'])
assert len(w) == 2 assert len(w) == 2
assert w[0].message.opt == opt2 assert w[0].message.opt() == opt2
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false') assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
assert w[1].message.opt == opt3 assert w[1].message.opt() == opt3
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error') assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
@ -420,27 +420,27 @@ def test_validator_warning_master_slave():
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1') api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt == netmask_admin_eth0 assert w[0].message.opt() == netmask_admin_eth0
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask, 'test error') assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask, 'test error')
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
assert len(w) == 1 assert len(w) == 1
assert w[0].message.opt == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false') assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
#FIXME #FIXME
#assert len(w) == 1 #assert len(w) == 1
assert w[0].message.opt == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false') assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
# #
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
#FIXME #FIXME
#assert len(w) == 1 #assert len(w) == 1
assert w[0].message.opt == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false') assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
# #
warnings.resetwarnings() warnings.resetwarnings()
@ -448,7 +448,7 @@ def test_validator_warning_master_slave():
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val']) api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
#FIXME #FIXME
#assert len(w) == 1 #assert len(w) == 1
assert w[0].message.opt == ip_admin_eth0 assert w[0].message.opt() == ip_admin_eth0
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false') assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')

View File

@ -222,6 +222,33 @@ def test_groups_with_master_hidden_in_config2():
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
def test_groups_with_master_reset_empty():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
api = getapi(Config(od_))
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
def test_groups_with_master_reset_out_of_range():
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
od_ = OptionDescription('root', '', [interface1])
api = getapi(Config(od_))
api.property.read_write()
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
def test_groups_with_master_hidden_in_config3(): def test_groups_with_master_hidden_in_config3():
#if master is hidden, slave are hidden too #if master is hidden, slave are hidden too
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',)) ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))

View File

@ -33,7 +33,7 @@ except:
COUNT_TIME = False COUNT_TIME = False
COUNT_TIME = {} #COUNT_TIME = {}
def count(func): def count(func):
@ -120,9 +120,11 @@ class CommonTiramisuOption(CommonTiramisu):
def _test_slave_index(self): def _test_slave_index(self):
option = self._get_option() option = self._get_option()
if not option.impl_is_optiondescription() and self.index is None and \ if not option.impl_is_optiondescription():
option.impl_is_master_slaves('slave'): if self.index is None and option.impl_is_master_slaves('slave'):
raise APIError('index must be set with a slave option') raise APIError('index must be set with a slave option')
elif self.index is not None and not option.impl_is_master_slaves('slave'):
raise APIError('index must be set only with a slave option')
def _unrestraint_not_allowed(self, force_unrestraint): def _unrestraint_not_allowed(self, force_unrestraint):
if force_unrestraint: if force_unrestraint:

View File

@ -83,7 +83,7 @@ class SubConfig(object):
self._impl_length = len(value) self._impl_length = len(value)
def cfgimpl_get_length(self): def cfgimpl_get_length(self):
return getattr(self, '_impl_length') return self._impl_length
def reset_one_option_cache(self, def reset_one_option_cache(self,
values, values,
@ -334,9 +334,6 @@ class SubConfig(object):
name, name,
index, index,
config_bag): config_bag):
context = self._cfgimpl_get_context()
if '.' in name: # pragma: optional cover if '.' in name: # pragma: optional cover
self, name = self.cfgimpl_get_home_by_path(name, self, name = self.cfgimpl_get_home_by_path(name,
config_bag) config_bag)
@ -358,6 +355,12 @@ class SubConfig(object):
index, index,
config_bag) config_bag)
elif option.impl_is_master_slaves('slave'): elif option.impl_is_master_slaves('slave'):
length = self.cfgimpl_get_length()
if index >= length:
raise SlaveError(_('index "{}" is higher than the master length "{}" '
'for option "{}"').format(index,
length,
option.impl_get_display_name()))
values.reset_slave(subpath, values.reset_slave(subpath,
index, index,
config_bag) config_bag)
@ -387,7 +390,6 @@ class SubConfig(object):
otherwise otherwise
""" """
if '.' in name: if '.' in name:
# raise Exception('je suis desole ...')
self, name = self.cfgimpl_get_home_by_path(name, self, name = self.cfgimpl_get_home_by_path(name,
config_bag) config_bag)
@ -425,7 +427,7 @@ class SubConfig(object):
if option.impl_is_master_slaves('slave'): if option.impl_is_master_slaves('slave'):
if index is None and not iter_slave: if index is None and not iter_slave:
raise IndexError(_('index is mandatory for the slave "{}"' raise SlaveError(_('index is mandatory for the slave "{}"'
'').format(subpath)) '').format(subpath))
length = self.cfgimpl_get_length() length = self.cfgimpl_get_length()
if index is not None and index >= length: if index is not None and index >= length:
@ -441,7 +443,7 @@ class SubConfig(object):
length, length,
subpath)) subpath))
elif index: elif index:
raise IndexError(_('index is forbidden for the not slave "{}"' raise SlaveError(_('index is forbidden for the not slave "{}"'
'').format(subpath)) '').format(subpath))
if option.impl_is_master_slaves('slave') and index is None: if option.impl_is_master_slaves('slave') and index is None:
value = [] value = []
@ -649,8 +651,8 @@ class SubConfig(object):
if withoption is None and withvalue is not undefined: # pragma: optional cover if withoption is None and withvalue is not undefined: # pragma: optional cover
raise ValueError(_("make_dict can't filtering with value without " raise ValueError(_("make_dict can't filtering with value without "
"option")) "option"))
context = self._cfgimpl_get_context()
if withoption is not None: if withoption is not None:
context = self._cfgimpl_get_context()
for path in context._find(bytype=None, for path in context._find(bytype=None,
byname=withoption, byname=withoption,
byvalue=withvalue, byvalue=withvalue,
@ -685,7 +687,7 @@ class SubConfig(object):
fullpath=fullpath) fullpath=fullpath)
#withoption can be set to None below ! #withoption can be set to None below !
if withoption is None: if withoption is None:
for opt in self.cfgimpl_get_description().impl_getchildren(config_bag): for opt in self.cfgimpl_get_description().impl_getchildren(config_bag, context):
sconfig_bag = config_bag.copy('nooption') sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt sconfig_bag.option = opt
path = opt.impl_getname() path = opt.impl_getname()

View File

@ -159,7 +159,7 @@ class ValueWarning(UserWarning): # pragma: optional cover
>>> with warnings.catch_warnings(record=True) as w: >>> with warnings.catch_warnings(record=True) as w:
... c.s = 'val' ... c.s = 'val'
... ...
>>> w[0].message.opt == s >>> w[0].message.opt() == s
True True
>>> print(str(w[0].message)) >>> print(str(w[0].message))
invalid value val for option s: pouet invalid value val for option s: pouet

View File

@ -175,5 +175,5 @@ class MasterSlaves(OptionDescription):
raise SlaveError(_('cannot reduce length of the master "{}"' raise SlaveError(_('cannot reduce length of the master "{}"'
'').format(option.impl_get_display_name())) '').format(option.impl_get_display_name()))
def impl_is_master_slaves(self): def impl_is_master_slaves(self, *args, **kwargs):
return True return True

View File

@ -340,7 +340,7 @@ class Option(OnlyOption):
if check_error: if check_error:
raise ValueError(msg) raise ValueError(msg)
else: else:
warnings.warn_explicit(ValueWarning(msg, self), warnings.warn_explicit(ValueWarning(msg, weakref.ref(self)),
ValueWarning, ValueWarning,
self.__class__.__name__, 0) self.__class__.__name__, 0)
@ -646,7 +646,7 @@ class Option(OnlyOption):
self._display_name, self._display_name,
current_opt.impl_get_display_name(), current_opt.impl_get_display_name(),
err) err)
warnings.warn_explicit(ValueWarning(msg, self), warnings.warn_explicit(ValueWarning(msg, weakref.ref(self)),
ValueWarning, ValueWarning,
self.__class__.__name__, 0) self.__class__.__name__, 0)
else: else:

View File

@ -381,15 +381,23 @@ class OptionDescriptionWalk(CacheOptionDescription):
def impl_getchildren(self, def impl_getchildren(self,
config_bag, config_bag,
context=None,
dyn=True): dyn=True):
cname = None
for child in self._impl_st_getchildren(): for child in self._impl_st_getchildren():
cname = child.impl_getname()
if dyn and child.impl_is_dynoptiondescription(): if dyn and child.impl_is_dynoptiondescription():
if context is None:
raise ConfigError(_('need context'))
if cname is None:
if context.cfgimpl_get_description() == self:
cname = ''
else:
cname = self.impl_getpath(context)
sconfig_bag = config_bag.copy('nooption') sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = child sconfig_bag.option = child
for value in child._impl_get_suffixes(sconfig_bag): for value in child._impl_get_suffixes(sconfig_bag):
yield SynDynOptionDescription(child, yield SynDynOptionDescription(child,
cname + value, cname,
value) value)
else: else:
yield child yield child
@ -478,7 +486,7 @@ class OptionDescription(OptionDescriptionWalk):
# the group_type is useful for filtering OptionDescriptions in a config # the group_type is useful for filtering OptionDescriptions in a config
self._group_type = groups.default self._group_type = groups.default
def impl_is_master_slaves(self): def impl_is_master_slaves(self, *args, **kwargs):
return False return False
def impl_getdoc(self): def impl_getdoc(self):

View File

@ -68,10 +68,11 @@ class SynDynOptionDescription(object):
config_bag, config_bag,
dyn=True): dyn=True):
children = [] children = []
subpath = self.impl_getpath()
for child in self._opt.impl_getchildren(config_bag): for child in self._opt.impl_getchildren(config_bag):
yield(self._opt._impl_get_dynchild(child, yield(self._opt._impl_get_dynchild(child,
self._suffix, self._suffix,
self._subpath)) subpath))
def impl_getpath(self): def impl_getpath(self):
subpath = self._subpath subpath = self._subpath
@ -93,13 +94,8 @@ class SynDynOptionDescription(object):
self._suffix) self._suffix)
def pop(self, def pop(self,
values, *args,
index, **kwargs):
setting_properties, self._opt.pop(*args,
force_permissive, slaves=self.getslaves(),
slaves=undefined): **kwargs)
self._opt.pop(values,
index,
setting_properties,
force_permissive,
slaves=self.getslaves())

View File

@ -567,7 +567,6 @@ class Settings(object):
if self._getcontext().cfgimpl_get_meta() is not None: if self._getcontext().cfgimpl_get_meta() is not None:
raise ConfigError(_('cannot change property with metaconfig')) raise ConfigError(_('cannot change property with metaconfig'))
if path is not None and config_bag.option.impl_getrequires() is not None: if path is not None and config_bag.option.impl_getrequires() is not None:
print(properties, getattr(config_bag.option, '_calc_properties', static_set))
not_allowed_props = properties & getattr(config_bag.option, '_calc_properties', static_set) not_allowed_props = properties & getattr(config_bag.option, '_calc_properties', static_set)
if not_allowed_props: if not_allowed_props:
if len(not_allowed_props) == 1: if len(not_allowed_props) == 1:
@ -608,7 +607,6 @@ class Settings(object):
raise ConfigError(_('cannot add this property: "{0}"').format( raise ConfigError(_('cannot add this property: "{0}"').format(
' '.join(property_))) ' '.join(property_)))
print('add', property_)
self_properties = config_bag.properties self_properties = config_bag.properties
if self_properties is None: if self_properties is None:
index = None index = None

View File

@ -76,7 +76,7 @@ class Values(Cache):
a specified value must be associated to an owner a specified value must be associated to an owner
""" """
if DEBUG: if DEBUG:
print('setvalue', path, value, index) print('setvalue', path, value, owner, index, id(self))
values = [] values = []
vidx = None vidx = None
@ -100,7 +100,7 @@ class Values(Cache):
if path.startswith('subod.subodval'): if path.startswith('subod.subodval'):
raise Exception('arf ...') raise Exception('arf ...')
if DEBUG: if DEBUG:
print('hasvalue', path, index, has_path) print('hasvalue', path, index, has_path, id(self))
if index is None: if index is None:
return has_path return has_path
elif has_path: elif has_path:
@ -114,7 +114,7 @@ class Values(Cache):
_values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2)) _values == ((path1, path2), ((idx1_1, idx1_2), None), ((value1_1, value1_2), value2), ((owner1_1, owner1_2), owner2))
""" """
if DEBUG: if DEBUG:
print('reduce_index', path, index) print('reduce_index', path, index, id(self))
path_idx = self._values[0].index(path) path_idx = self._values[0].index(path)
indexes = self._values[1][path_idx] indexes = self._values[1][path_idx]
if index in indexes: if index in indexes:
@ -129,7 +129,7 @@ class Values(Cache):
def resetvalue_index(self, path, index): def resetvalue_index(self, path, index):
if DEBUG: if DEBUG:
print('resetvalue_index', path, index) print('resetvalue_index', path, index, id(self))
def _resetvalue(nb): def _resetvalue(nb):
values_idx = list(values[nb]) values_idx = list(values[nb])
del(values_idx[path_idx]) del(values_idx[path_idx])
@ -162,7 +162,7 @@ class Values(Cache):
"""remove value means delete value in storage """remove value means delete value in storage
""" """
if DEBUG: if DEBUG:
print('resetvalue', path) print('resetvalue', path, id(self))
def _resetvalue(nb): def _resetvalue(nb):
lst = list(self._values[nb]) lst = list(self._values[nb])
lst.pop(idx) lst.pop(idx)
@ -232,7 +232,7 @@ class Values(Cache):
if owner is undefined: if owner is undefined:
owner = default owner = default
if DEBUG: if DEBUG:
print('getvalue', path, index, value) print('getvalue', path, index, value, owner, id(self))
if with_value: if with_value:
return owner, value return owner, value
else: else:

View File

@ -15,7 +15,6 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________ # ____________________________________________________________
FIXME = 0
def POUET(obj): def POUET(obj):
return(obj.__class__.__name__.lower()) return(obj.__class__.__name__.lower())
@ -35,41 +34,23 @@ class Cache(object):
"""add val in cache for a specified path """add val in cache for a specified path
if slave, add index if slave, add index
""" """
if DEBUG: if DEBUG and path == 'odmaster.third':
global FIXME print('ca set cache', path, val, POUET(self), id(self))
FIXME += 1
print('ca set cache', path, val, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 111:
# raise Exception('rah')
self._cache.setdefault(path, {})[index] = (val, time) self._cache.setdefault(path, {})[index] = (val, time)
def getcache(self, path, exp, index): def getcache(self, path, exp, index):
value, created = self._cache[path][index] value, created = self._cache[path][index]
if created is None or exp <= created: if created is None or exp <= created:
if DEBUG: if DEBUG and path == 'odmaster.third':
global FIXME print('ca trouve dans le cache', path, value, POUET(self), id(self), index, exp)
FIXME += 1
print('ca trouve dans le cache', path, value, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 45:
# raise Exception('rah')
return True, value return True, value
return False, None # pragma: no cover return False, None # pragma: no cover
def delcache(self, path): def delcache(self, path):
"""remove cache for a specified path """remove cache for a specified path
""" """
if DEBUG: if DEBUG and path == 'odmaster.third':
global FIXME print('ca del cache', path, POUET(self), id(self))
FIXME += 1
print('ca del cache', path, POUET(self), FIXME, id(self))
#if path is not None and (path.startswith('od.st.') or path.startswith('od.dod.')):
# raise Exception('mais ... mais ... mais')
#if FIXME == 23:
# raise Exception('rah')
if path in self._cache: if path in self._cache:
del self._cache[path] del self._cache[path]
@ -78,7 +59,7 @@ class Cache(object):
:param path: the path's option :param path: the path's option
""" """
if DEBUG: if DEBUG and path == 'odmaster.third':
print('ca cherche dans le cache', path, POUET(self), id(self)) print('ca cherche dans le cache', path, POUET(self), id(self))
return path in self._cache and index in self._cache[path] return path in self._cache and index in self._cache[path]

View File

@ -601,23 +601,26 @@ class Values(object):
index, index,
config_bag): config_bag):
context = self._getcontext() if self._p_.hasvalue(path, index=index):
if config_bag.validate and 'validator' in config_bag.setting_properties: context = self._getcontext()
fake_context = context._gen_fake_values() if config_bag.validate and 'validator' in config_bag.setting_properties:
fake_value = fake_context.cfgimpl_get_values() fake_context = context._gen_fake_values()
sconfig_bag = config_bag.copy() fake_value = fake_context.cfgimpl_get_values()
sconfig_bag.validate = False sconfig_bag = config_bag.copy()
fake_value.reset_slave(path, sconfig_bag.validate = False
index, fake_value.reset_slave(path,
sconfig_bag) index,
value = fake_value._getdefaultvalue(path, sconfig_bag)
index, value = fake_value._getdefaultvalue(path,
config_bag) index,
fake_value.setvalue_validation(path, config_bag)
index, fake_value.setvalue_validation(path,
value, index,
config_bag) value,
self._p_.resetvalue_index(path, index) config_bag)
self._p_.resetvalue_index(path, index)
context.cfgimpl_reset_cache(opt=config_bag.option,
path=path)
def reset_master(self, def reset_master(self,
subconfig, subconfig,
@ -628,6 +631,12 @@ class Values(object):
current_value = self.get_cached_value(path, current_value = self.get_cached_value(path,
None, None,
config_bag) config_bag)
length = len(current_value)
if index >= length:
raise IndexError(_('index "{}" is higher than the length "{}" '
'for option "{}"').format(index,
length,
config_bag.option.impl_get_display_name()))
current_value.pop(index) current_value.pop(index)
self.setvalue(path, self.setvalue(path,
None, None,
@ -638,7 +647,6 @@ class Values(object):
index, index,
config_bag) config_bag)
def setowner_validation(self, def setowner_validation(self,
path, path,
index, index,
@ -709,7 +717,7 @@ class Values(object):
lenmaster = None lenmaster = None
optmaster = None optmaster = None
pathmaster = None pathmaster = None
for option in description.impl_getchildren(config_bag): for option in description.impl_getchildren(config_bag, context):
sconfig_bag = config_bag.copy('nooption') sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = option sconfig_bag.option = option
name = option.impl_getname() name = option.impl_getname()