Better support for slave with callback:

- callback must return single value, not a list
- if default value, append slave values with master len
- if not default and append, set default value
This commit is contained in:
2013-06-11 15:10:38 +02:00
parent 22f0aab0a8
commit 6d1cf308b2
2 changed files with 72 additions and 16 deletions

View File

@ -1,12 +1,17 @@
import autopath
from py.test import raises
from tiramisu.setting import groups
from tiramisu.config import Config
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, IPOption, OptionDescription
StrOption, OptionDescription
from tiramisu.error import PropertiesOptionError, ConflictError
def return_value():
return 'val'
def make_description():
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
gcdummy = BoolOption('dummy', 'dummy', default=False)
@ -269,3 +274,37 @@ def test_freeze_and_has_callback():
dummy = config.unwrap_from_path('gc.dummy')
setting[dummy].append('frozen')
raises(PropertiesOptionError, "config.gc.dummy = True")
def test_callback_master_and_slaves():
val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value)
interface1 = OptionDescription('val1', '', [val1, val2])
interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1])
cfg = Config(maconfig)
cfg.read_write()
assert cfg.val1.val1 == []
assert cfg.val1.val2 == []
#
cfg.val1.val1 = ['val1']
assert cfg.val1.val1 == ['val1']
assert cfg.val1.val2 == ['val']
#
cfg.val1.val1.append('val2')
assert cfg.val1.val1 == ['val1', 'val2']
assert cfg.val1.val2 == ['val', 'val']
#
cfg.val1.val1 = ['val1', 'val2', 'val3']
assert cfg.val1.val1 == ['val1', 'val2', 'val3']
assert cfg.val1.val2 == ['val', 'val', 'val']
#
cfg.val1.val1.pop(2)
assert cfg.val1.val1 == ['val1', 'val2']
assert cfg.val1.val2 == ['val', 'val']
#
cfg.val1.val2 = ['val2', 'val2']
assert cfg.val1.val2 == ['val2', 'val2']
#
cfg.val1.val1.append('val3')
assert cfg.val1.val2 == ['val2', 'val2', 'val']