Important behavior change : to add default_multi value, now use Multi.append(), not Multi.append(None)

This commit is contained in:
Emmanuel Garette 2013-12-09 17:59:39 +01:00
parent bb1f6947e3
commit 73745be440
4 changed files with 29 additions and 7 deletions

View File

@ -239,3 +239,18 @@ def test_cannot_assign_value_to_option_description():
descr = make_description()
cfg = Config(descr)
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]

View File

@ -393,7 +393,7 @@ def test_callback_master_and_slaves_master():
cfg = Config(maconfig)
cfg.read_write()
assert cfg.val1.val1 == ['val']
cfg.val1.val1.append(None)
cfg.val1.val1.append()
assert cfg.val1.val1 == ['val', 'val']
assert cfg.val1.val2 == [None, None]
@ -408,7 +408,7 @@ def test_callback_master_and_slaves_master_list():
cfg.read_write()
assert cfg.val1.val1 == ['val', 'val']
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.val2 == [None, None, None]
del(cfg.val1.val1)

View File

@ -242,6 +242,12 @@ multitypes = MultiTypeModule()
populate_multitypes()
# ____________________________________________________________
class Undefined():
pass
undefined = Undefined()
# ____________________________________________________________
class Property(object):
"a property is responsible of the option's value access rules"

View File

@ -22,7 +22,7 @@ from copy import copy
import sys
import weakref
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.i18n import _
from tiramisu.option import SymLinkOption
@ -452,8 +452,7 @@ class Multi(list):
values._getcallback_value(slave, index=index),
force=True)
else:
value_slave.append(slave.impl_getdefault_multi(),
force=True)
value_slave.append(undefined, force=True)
def __setitem__(self, index, value):
self._validate(value, index)
@ -461,7 +460,7 @@ class Multi(list):
super(Multi, self).__setitem__(index, value)
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)
only if the option is a master
"""
@ -471,12 +470,14 @@ class Multi(list):
" which is a slave").format(self.opt._name))
elif self.opt.impl_get_multitype() == multitypes.master:
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)
#Force None il return a list
if isinstance(value, list):
value = None
index = self.__len__()
if value is undefined:
value = self.opt.impl_getdefault_multi()
self._validate(value, index)
super(Multi, self).append(value)
self.context().cfgimpl_get_values()._setvalue(self.opt, self.path,