Important behavior change : to add default_multi value, now use Multi.append(), not Multi.append(None)
This commit is contained in:
parent
bb1f6947e3
commit
73745be440
|
@ -239,3 +239,18 @@ def test_cannot_assign_value_to_option_description():
|
||||||
descr = make_description()
|
descr = make_description()
|
||||||
cfg = Config(descr)
|
cfg = Config(descr)
|
||||||
raises(TypeError, "cfg.gc = 3")
|
raises(TypeError, "cfg.gc = 3")
|
||||||
|
|
||||||
|
|
||||||
|
def test_config_multi():
|
||||||
|
i1 = IntOption('test1', '', multi=True)
|
||||||
|
i2 = IntOption('test2', '', multi=True, default_multi=1)
|
||||||
|
i3 = IntOption('test3', '', default=[2], multi=True, default_multi=1)
|
||||||
|
od = OptionDescription('test', '', [i1, i2, i3])
|
||||||
|
config = Config(od)
|
||||||
|
assert config.test1 == []
|
||||||
|
assert config.test2 == []
|
||||||
|
config.test2.append()
|
||||||
|
assert config.test2 == [1]
|
||||||
|
assert config.test3 == [2]
|
||||||
|
config.test3.append()
|
||||||
|
assert config.test3 == [2, 1]
|
||||||
|
|
|
@ -393,7 +393,7 @@ def test_callback_master_and_slaves_master():
|
||||||
cfg = Config(maconfig)
|
cfg = Config(maconfig)
|
||||||
cfg.read_write()
|
cfg.read_write()
|
||||||
assert cfg.val1.val1 == ['val']
|
assert cfg.val1.val1 == ['val']
|
||||||
cfg.val1.val1.append(None)
|
cfg.val1.val1.append()
|
||||||
assert cfg.val1.val1 == ['val', 'val']
|
assert cfg.val1.val1 == ['val', 'val']
|
||||||
assert cfg.val1.val2 == [None, None]
|
assert cfg.val1.val2 == [None, None]
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ def test_callback_master_and_slaves_master_list():
|
||||||
cfg.read_write()
|
cfg.read_write()
|
||||||
assert cfg.val1.val1 == ['val', 'val']
|
assert cfg.val1.val1 == ['val', 'val']
|
||||||
assert cfg.val1.val2 == [None, None]
|
assert cfg.val1.val2 == [None, None]
|
||||||
cfg.val1.val1.append(None)
|
cfg.val1.val1.append()
|
||||||
assert cfg.val1.val1 == ['val', 'val', None]
|
assert cfg.val1.val1 == ['val', 'val', None]
|
||||||
assert cfg.val1.val2 == [None, None, None]
|
assert cfg.val1.val2 == [None, None, None]
|
||||||
del(cfg.val1.val1)
|
del(cfg.val1.val1)
|
||||||
|
|
|
@ -242,6 +242,12 @@ multitypes = MultiTypeModule()
|
||||||
populate_multitypes()
|
populate_multitypes()
|
||||||
|
|
||||||
|
|
||||||
|
# ____________________________________________________________
|
||||||
|
class Undefined():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
undefined = Undefined()
|
||||||
# ____________________________________________________________
|
# ____________________________________________________________
|
||||||
class Property(object):
|
class Property(object):
|
||||||
"a property is responsible of the option's value access rules"
|
"a property is responsible of the option's value access rules"
|
||||||
|
|
|
@ -22,7 +22,7 @@ from copy import copy
|
||||||
import sys
|
import sys
|
||||||
import weakref
|
import weakref
|
||||||
from tiramisu.error import ConfigError, SlaveError
|
from tiramisu.error import ConfigError, SlaveError
|
||||||
from tiramisu.setting import owners, multitypes, expires_time
|
from tiramisu.setting import owners, multitypes, expires_time, undefined
|
||||||
from tiramisu.autolib import carry_out_calculation
|
from tiramisu.autolib import carry_out_calculation
|
||||||
from tiramisu.i18n import _
|
from tiramisu.i18n import _
|
||||||
from tiramisu.option import SymLinkOption
|
from tiramisu.option import SymLinkOption
|
||||||
|
@ -452,8 +452,7 @@ class Multi(list):
|
||||||
values._getcallback_value(slave, index=index),
|
values._getcallback_value(slave, index=index),
|
||||||
force=True)
|
force=True)
|
||||||
else:
|
else:
|
||||||
value_slave.append(slave.impl_getdefault_multi(),
|
value_slave.append(undefined, force=True)
|
||||||
force=True)
|
|
||||||
|
|
||||||
def __setitem__(self, index, value):
|
def __setitem__(self, index, value):
|
||||||
self._validate(value, index)
|
self._validate(value, index)
|
||||||
|
@ -461,7 +460,7 @@ class Multi(list):
|
||||||
super(Multi, self).__setitem__(index, value)
|
super(Multi, self).__setitem__(index, value)
|
||||||
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path, self)
|
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path, self)
|
||||||
|
|
||||||
def append(self, value, force=False):
|
def append(self, value=undefined, force=False):
|
||||||
"""the list value can be updated (appened)
|
"""the list value can be updated (appened)
|
||||||
only if the option is a master
|
only if the option is a master
|
||||||
"""
|
"""
|
||||||
|
@ -471,12 +470,14 @@ class Multi(list):
|
||||||
" which is a slave").format(self.opt._name))
|
" which is a slave").format(self.opt._name))
|
||||||
elif self.opt.impl_get_multitype() == multitypes.master:
|
elif self.opt.impl_get_multitype() == multitypes.master:
|
||||||
values = self.context().cfgimpl_get_values()
|
values = self.context().cfgimpl_get_values()
|
||||||
if value is None and self.opt.impl_has_callback():
|
if value is undefined and self.opt.impl_has_callback():
|
||||||
value = values._getcallback_value(self.opt)
|
value = values._getcallback_value(self.opt)
|
||||||
#Force None il return a list
|
#Force None il return a list
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
value = None
|
value = None
|
||||||
index = self.__len__()
|
index = self.__len__()
|
||||||
|
if value is undefined:
|
||||||
|
value = self.opt.impl_getdefault_multi()
|
||||||
self._validate(value, index)
|
self._validate(value, index)
|
||||||
super(Multi, self).append(value)
|
super(Multi, self).append(value)
|
||||||
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path,
|
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path,
|
||||||
|
|
Loading…
Reference in New Issue