good value for callback for a slave that return a list
This commit is contained in:
parent
8bd1b27f73
commit
58a90a3707
|
@ -489,6 +489,96 @@ def test_callback_master_and_slaves_master2():
|
||||||
assert cfg.val1.val2 == ['val2']
|
assert cfg.val1.val2 == ['val2']
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_master_and_slaves_master_mandatory():
|
||||||
|
val = StrOption('val', "", default='val')
|
||||||
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),)}, properties=('mandatory',))
|
||||||
|
val3 = StrOption('val3', "", multi=True, callback=return_value2, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
val4 = StrOption('val4', "", multi=True, callback=return_value2, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3 == ['val']
|
||||||
|
assert cfg.val1.val4 == ['val']
|
||||||
|
assert cfg.val1.val1 == ['val']
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.val1.val1.append('val3')
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val1 == ['val', 'val3']
|
||||||
|
assert cfg.val1.val3[0] == 'val'
|
||||||
|
raises(PropertiesOptionError, 'cfg.val1.val3[1]')
|
||||||
|
raises(PropertiesOptionError, 'cfg.val1.val4[1]')
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_master_and_slaves_master_mandatory2():
|
||||||
|
val = StrOption('val', "", default='val')
|
||||||
|
val_ = StrOption('val_', "", default='val_')
|
||||||
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),), 'val': ((val_, False),)}, properties=('mandatory',))
|
||||||
|
val3 = StrOption('val3', "", multi=True, callback=return_value2, callback_params={'': ((val1, False),), 'val': ((val_, False),)}, properties=('mandatory',))
|
||||||
|
val4 = StrOption('val4', "", multi=True, callback=return_value2, callback_params={'': ((val1, False),), 'val': ((val_, False),)}, properties=('mandatory',))
|
||||||
|
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3 == ['val', 'val_']
|
||||||
|
assert cfg.val1.val4 == ['val', 'val_']
|
||||||
|
assert cfg.val1.val1 == ['val', 'val_']
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.val1.val1.append('val3')
|
||||||
|
assert cfg.val1.val1 == ['val', 'val_', 'val3']
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3[:2] == ['val', 'val_']
|
||||||
|
assert cfg.val1.val4[:2] == ['val', 'val_']
|
||||||
|
raises(PropertiesOptionError, "cfg.val1.val3[2]")
|
||||||
|
raises(PropertiesOptionError, "cfg.val1.val4[2]")
|
||||||
|
assert cfg.val1.val1 == ['val', 'val_', 'val3']
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_master_and_slaves_master_mandatory3():
|
||||||
|
val = StrOption('val', "", default='val')
|
||||||
|
val_ = StrOption('val_', "", default='val_')
|
||||||
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),), 'val': ((val_, False),)}, properties=('mandatory',))
|
||||||
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3 == ['val', 'val_']
|
||||||
|
assert cfg.val1.val4 == ['val', 'val_']
|
||||||
|
assert cfg.val1.val1 == ['val', 'val_']
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.val1.val1.append('val3')
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3 == ['val', 'val_', 'val3']
|
||||||
|
assert cfg.val1.val4 == ['val', 'val_', 'val3']
|
||||||
|
assert cfg.val1.val1 == ['val', 'val_', 'val3']
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_master_and_slaves_master_mandatory4():
|
||||||
|
val = StrOption('val', "", default='val')
|
||||||
|
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),)}, properties=('mandatory',))
|
||||||
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
||||||
|
interface1 = OptionDescription('val1', '', [val1, val3, val4])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val3 == ['val']
|
||||||
|
assert cfg.val1.val4 == ['val']
|
||||||
|
assert cfg.val1.val1 == ['val']
|
||||||
|
cfg.read_write()
|
||||||
|
cfg.val1.val1.append('val3')
|
||||||
|
cfg.read_only()
|
||||||
|
assert cfg.val1.val1 == ['val', 'val3']
|
||||||
|
assert cfg.val1.val3 == ['val', 'val3']
|
||||||
|
assert cfg.val1.val4 == ['val', 'val3']
|
||||||
|
|
||||||
|
|
||||||
def test_callback_master_and_slaves_master3():
|
def test_callback_master_and_slaves_master3():
|
||||||
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
||||||
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
||||||
|
|
|
@ -71,6 +71,8 @@ class Values(object):
|
||||||
if opt.impl_is_submulti() and submulti_index is undefined and \
|
if opt.impl_is_submulti() and submulti_index is undefined and \
|
||||||
(len(value) == 0 or not isinstance(value[0], list)):
|
(len(value) == 0 or not isinstance(value[0], list)):
|
||||||
return value
|
return value
|
||||||
|
if not opt.impl_is_submulti() and len(value) > index:
|
||||||
|
return value[index]
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
if with_meta:
|
if with_meta:
|
||||||
|
|
Loading…
Reference in New Issue