Merge modification made for 1.0's branch
This commit is contained in:
commit
a1f0c29713
|
@ -444,6 +444,22 @@ def test_callback_master_and_slaves_master():
|
|||
assert cfg.val1.val2 == [None, None]
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master2():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, default_multi='val2')
|
||||
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
|
||||
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)})
|
||||
interface1 = OptionDescription('val1', '', [val1, val2, val3, val4])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.val1.val1.append('val')
|
||||
assert cfg.val1.val4 == ['val2']
|
||||
assert cfg.val1.val3 == ['val2']
|
||||
assert cfg.val1.val2 == ['val2']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_list():
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
|
@ -499,6 +515,16 @@ def test_callback_master_and_slaves_slave():
|
|||
assert cfg.val1.val2 == ['val2', 'val2', 'val']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_slave_cal():
|
||||
val3 = StrOption('val3', "", multi=True)
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)})
|
||||
|
|
|
@ -154,8 +154,15 @@ def carry_out_calculation(option, config, callback, callback_params,
|
|||
).impl_get_path_by_opt(opt)
|
||||
# get value
|
||||
try:
|
||||
if option.impl_is_multi() and \
|
||||
(option.impl_get_multitype() == multitypes.master or
|
||||
(option.impl_get_multitype() == multitypes.slave and
|
||||
option.impl_get_master_slaves() != opt)):
|
||||
validate = True
|
||||
else:
|
||||
validate = False
|
||||
value = config.getattr(path, force_permissive=True,
|
||||
validate=False)
|
||||
validate=validate)
|
||||
# convert to list, not modifie this multi
|
||||
if value.__class__.__name__ == 'Multi':
|
||||
value = list(value)
|
||||
|
@ -192,7 +199,7 @@ def carry_out_calculation(option, config, callback, callback_params,
|
|||
# if no index, return a list
|
||||
if one_is_multi:
|
||||
ret = []
|
||||
if index:
|
||||
if index is not None:
|
||||
range_ = [index]
|
||||
else:
|
||||
range_ = range(len_multi)
|
||||
|
@ -211,7 +218,7 @@ def carry_out_calculation(option, config, callback, callback_params,
|
|||
else:
|
||||
kwargs[key] = val
|
||||
calc = calculate(callback, args, kwargs)
|
||||
if index:
|
||||
if index is not None:
|
||||
ret = calc
|
||||
else:
|
||||
ret.append(calc)
|
||||
|
@ -234,7 +241,7 @@ def carry_out_calculation(option, config, callback, callback_params,
|
|||
ret = ret[:max_len]
|
||||
if len(ret) < max_len:
|
||||
ret = ret + [None] * (max_len - len(ret))
|
||||
if isinstance(ret, list) and index:
|
||||
if isinstance(ret, list) and index is not None:
|
||||
if len(ret) < index + 1:
|
||||
ret = None
|
||||
else:
|
||||
|
|
|
@ -208,7 +208,7 @@ class Values(object):
|
|||
if (opt.impl_is_multi() and
|
||||
opt.impl_get_multitype() == multitypes.slave):
|
||||
masterp = self._get_opt_path(opt.impl_get_master_slaves())
|
||||
mastervalue = context.getattr(masterp, validate=validate)
|
||||
mastervalue = context.getattr(masterp, validate=False)
|
||||
lenmaster = len(mastervalue)
|
||||
if lenmaster == 0:
|
||||
value = []
|
||||
|
@ -232,8 +232,6 @@ class Values(object):
|
|||
if config_error is None:
|
||||
if opt.impl_is_multi():
|
||||
value = Multi(value, self.context, opt, path, validate)
|
||||
# suppress value if already set
|
||||
self.reset(opt, path)
|
||||
# frozen and force default
|
||||
elif is_frozen and 'force_default_on_freeze' in setting[opt]:
|
||||
value = self._getdefault(opt)
|
||||
|
|
Loading…
Reference in New Issue