Merge branch 'master' into orm
Conflicts: test/test_config_api.py tiramisu/autolib.py tiramisu/config.py tiramisu/option.py tiramisu/value.py
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import autopath
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
StrOption, OptionDescription, SymLinkOption
|
||||
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
|
||||
@ -44,6 +44,13 @@ def return_calc(i, j, k):
|
||||
return i + j + k
|
||||
|
||||
|
||||
def is_config(config, **kwargs):
|
||||
if isinstance(config, Config):
|
||||
return 'yes'
|
||||
else:
|
||||
return 'no'
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
@ -254,6 +261,29 @@ def test_callback_invalid():
|
||||
raises(ValueError, "StrOption('val2', '', callback=return_value, callback_params={'': 'string'})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': (('string', False),)})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, 'string'),)})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1, False, 'unknown'),)})")
|
||||
raises(ValueError, "StrOption('val4', '', callback=return_value, callback_params={'value': ((val1,),)})")
|
||||
|
||||
|
||||
def test_callback_with_context():
|
||||
val1 = StrOption("val1", "", callback=is_config, callback_params={'': ((None,),), 'value': ('string',)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.val1 == 'yes'
|
||||
|
||||
|
||||
def test_callback_with_context_named():
|
||||
val1 = StrOption("val1", "", callback=is_config, callback_params={'config': ((None,),)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.val1 == 'yes'
|
||||
|
||||
|
||||
def test_callback_with_error():
|
||||
val1 = StrOption("val1", "", callback=is_config, callback_params={'': ('string',), 'value': ('string',)})
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
cfg = Config(maconfig)
|
||||
assert cfg.val1 == 'no'
|
||||
|
||||
|
||||
def test_callback_value():
|
||||
@ -401,6 +431,17 @@ def test_callback_multi_list_extend():
|
||||
assert cfg.val1 == ['1', '2', '3', '4', '5']
|
||||
|
||||
|
||||
def test_callback_multi_callback():
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_val)
|
||||
interface1 = OptionDescription('val1', '', [val1])
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val1.val1 == ['val']
|
||||
cfg.val1.val1.append()
|
||||
assert cfg.val1.val1 == ['val', 'val']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master():
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_val)
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
@ -415,6 +456,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)
|
||||
@ -470,6 +527,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),)})
|
||||
@ -486,8 +553,6 @@ def test_callback_master_and_slaves_slave_cal():
|
||||
cfg.val3 = ['val1']
|
||||
assert cfg.val1.val1 == ['val1']
|
||||
assert cfg.val1.val2 == ['val']
|
||||
assert cfg.val1.val1 == ['val1']
|
||||
assert cfg.val1.val2 == ['val']
|
||||
del(cfg.val1.val1)
|
||||
cfg.val1.val2 = ['val']
|
||||
cfg.val3 = ['val1', 'val2']
|
||||
@ -516,8 +581,8 @@ def test_callback_master_and_slaves_slave_cal2():
|
||||
assert cfg.val1.val1 == ['val', 'val']
|
||||
assert cfg.val1.val2 == ['val2', 'val2']
|
||||
cfg.val3.pop(1)
|
||||
# # cannot remove slave's value because master is calculated
|
||||
# # so raise
|
||||
# cannot remove slave's value because master is calculated
|
||||
# so raise
|
||||
raises(SlaveError, "cfg.val1.val1")
|
||||
raises(SlaveError, "cfg.val1.val2")
|
||||
cfg.val3 = ['val', 'val']
|
||||
@ -530,6 +595,88 @@ def test_callback_master_and_slaves_slave_cal2():
|
||||
assert cfg.val1.val2 == ['val2', 'val2']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_disabled():
|
||||
#properties must be transitive
|
||||
val1 = StrOption('val1', "", multi=True, properties=('disabled',))
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(PropertiesOptionError, "cfg.val1.val1")
|
||||
raises(PropertiesOptionError, "cfg.val1.val1.append('yes')")
|
||||
raises(PropertiesOptionError, "cfg.val1.val2")
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_master_callback_disabled():
|
||||
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
||||
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val0, False),)})
|
||||
val2 = StrOption('val2', "", multi=True)
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
raises(ConfigError, "cfg.val1.val1")
|
||||
raises(ConfigError, "cfg.val1.val2")
|
||||
cfg.cfgimpl_get_settings().remove('disabled')
|
||||
cfg.val1.val1 = []
|
||||
cfg.cfgimpl_get_settings().append('disabled')
|
||||
assert cfg.val1.val1 == []
|
||||
assert cfg.val1.val2 == []
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_slave_disabled():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
|
||||
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 == []
|
||||
raises(PropertiesOptionError, "cfg.val1.val2")
|
||||
cfg.val1.val1.append('yes')
|
||||
assert cfg.val1.val1 == ['yes']
|
||||
cfg.cfgimpl_get_settings().remove('disabled')
|
||||
assert cfg.val1.val2 == [None]
|
||||
cfg.val1.val2 = ['no']
|
||||
cfg.val1.val1.append('yes2')
|
||||
cfg.val1.val1.append('yes3')
|
||||
cfg.val1.val2[2] = 'no1'
|
||||
assert cfg.val1.val2 == ['no', None, 'no1']
|
||||
cfg.cfgimpl_get_settings().append('disabled')
|
||||
cfg.val1.val1.pop(0)
|
||||
assert cfg.val1.val1 == ['yes2', 'yes3']
|
||||
cfg.cfgimpl_get_settings().remove('disabled')
|
||||
assert cfg.val1.val2 == [None, 'no1']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_slave_callback_disabled():
|
||||
val0 = StrOption('val0', "", multi=True, properties=('disabled',))
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val0, False),)})
|
||||
interface1 = OptionDescription('val1', '', [val1, val2])
|
||||
interface1.impl_set_group_type(groups.master)
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val1.val1 == []
|
||||
raises(ConfigError, "cfg.val1.val2")
|
||||
cfg.val1.val1.append('yes')
|
||||
assert cfg.val1.val1 == ['yes']
|
||||
cfg.cfgimpl_get_settings().remove('disabled')
|
||||
assert cfg.val1.val2 == [None]
|
||||
cfg.val1.val2 = ['no']
|
||||
cfg.val1.val1.append('yes1')
|
||||
cfg.val1.val2[1] = 'no1'
|
||||
cfg.cfgimpl_get_settings().append('disabled')
|
||||
cfg.val1.val1.pop(0)
|
||||
assert cfg.val1.val1 == ['yes1']
|
||||
assert cfg.val1.val2 == ['no1']
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_slave_list():
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_list)
|
||||
@ -538,20 +685,20 @@ def test_callback_master_and_slaves_slave_list():
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val1.val2 == []
|
||||
#len is equal to 2 for slave and 0 for master
|
||||
raises(SlaveError, "cfg.val1.val2")
|
||||
cfg.val1.val1 = ['val1', 'val2']
|
||||
assert cfg.val1.val1 == ['val1', 'val2']
|
||||
assert cfg.val1.val2 == ['val', 'val']
|
||||
cfg.val1.val1 = ['val1']
|
||||
#wrong len
|
||||
raises(SlaveError, 'cfg.val1.val2')
|
||||
raises(SlaveError, "cfg.val1.val1 = ['val1']")
|
||||
|
||||
|
||||
def test_callback_master_and_slaves_value():
|
||||
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
|
||||
val1 = StrOption('val1', "", multi=True)
|
||||
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
|
||||
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)})
|
||||
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
|
||||
val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params={'': ((val4, False),)})
|
||||
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params={'': ((val5, False),)})
|
||||
interface1 = OptionDescription('val1', '', [val1, val2, val3, val5, val6])
|
||||
@ -559,27 +706,24 @@ def test_callback_master_and_slaves_value():
|
||||
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val1.val1 == []
|
||||
assert cfg.val1.val2 == []
|
||||
assert cfg.val1.val3 == []
|
||||
assert cfg.val1.val5 == []
|
||||
assert cfg.val1.val6 == []
|
||||
cfg.val4 == ['val10', 'val11']
|
||||
raises(SlaveError, "cfg.val1.val1")
|
||||
raises(SlaveError, "cfg.val1.val2")
|
||||
raises(SlaveError, "cfg.val1.val3")
|
||||
raises(SlaveError, "cfg.val1.val5")
|
||||
raises(SlaveError, "cfg.val1.val6")
|
||||
#
|
||||
cfg.val1.val1 = ['val1']
|
||||
assert cfg.val1.val1 == ['val1']
|
||||
assert cfg.val1.val2 == ['val1']
|
||||
assert cfg.val1.val3 == ['yes']
|
||||
assert cfg.val1.val5 == ['val10']
|
||||
assert cfg.val1.val6 == ['val10']
|
||||
#default calculation has greater length
|
||||
raises(SlaveError, "cfg.val1.val1 = ['val1']")
|
||||
#
|
||||
cfg.val1.val1.append('val2')
|
||||
cfg.val1.val1 = ['val1', 'val2']
|
||||
assert cfg.val1.val1 == ['val1', 'val2']
|
||||
assert cfg.val1.val2 == ['val1', 'val2']
|
||||
assert cfg.val1.val3 == ['yes', 'yes']
|
||||
assert cfg.val1.val5 == ['val10', 'val11']
|
||||
assert cfg.val1.val6 == ['val10', 'val11']
|
||||
#
|
||||
cfg.val1.val1 = ['val1', 'val2', 'val3']
|
||||
cfg.val1.val1.append('val3')
|
||||
assert cfg.val1.val1 == ['val1', 'val2', 'val3']
|
||||
assert cfg.val1.val2 == ['val1', 'val2', 'val3']
|
||||
assert cfg.val1.val3 == ['yes', 'yes', 'yes']
|
||||
@ -650,9 +794,16 @@ def test_callback_master_and_other_master_slave():
|
||||
assert cfg.val4.val6 == ['no', None]
|
||||
cfg.val1.val1 = ['yes', 'yes', 'yes']
|
||||
cfg.val1.val2 = ['no', 'no', 'no']
|
||||
assert cfg.val4.val4 == ['val10', 'val11']
|
||||
assert cfg.val4.val5 == ['yes', 'yes']
|
||||
assert cfg.val4.val6 == ['no', 'no']
|
||||
raises(SlaveError, "cfg.val4.val4")
|
||||
raises(SlaveError, "cfg.val4.val5")
|
||||
raises(SlaveError, "cfg.val4.val6")
|
||||
cfg.val4.getattr('val4', validate=False).append('val12')
|
||||
assert cfg.val4.val4 == ['val10', 'val11', 'val12']
|
||||
assert cfg.val4.val5 == ['yes', 'yes', 'yes']
|
||||
assert cfg.val4.val6 == ['no', 'no', 'no']
|
||||
|
||||
|
||||
#FIXME: slave est un symlink
|
||||
|
||||
|
||||
def test_callback_different_type():
|
||||
@ -702,6 +853,19 @@ def test_callback_two_disabled():
|
||||
raises(PropertiesOptionError, 'cfg.od2.opt2')
|
||||
|
||||
|
||||
def test_callback_two_disabled2():
|
||||
opt1 = BoolOption('opt1', '', properties=('hidden',))
|
||||
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('hidden',))
|
||||
od1 = OptionDescription('od1', '', [opt1])
|
||||
od2 = OptionDescription('od2', '', [opt2])
|
||||
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
||||
raises(PropertiesOptionError, 'cfg.od2.opt2')
|
||||
assert cfg.getowner(opt2, force_permissive=True) == owners.default
|
||||
|
||||
|
||||
def test_callback_calculating_disabled():
|
||||
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
||||
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
|
||||
@ -724,6 +888,17 @@ def test_callback_calculating_mandatory():
|
||||
raises(ConfigError, 'cfg.od2.opt2')
|
||||
|
||||
|
||||
def test_callback_calculating_mandatory_multi():
|
||||
opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',))
|
||||
opt2 = BoolOption('opt2', '', multi=True, callback=return_value, callback_params={'': ((opt1, False),)}, properties=('mandatory',))
|
||||
od1 = OptionDescription('od1', '', [opt1])
|
||||
od2 = OptionDescription('od2', '', [opt2])
|
||||
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_only()
|
||||
raises(ConfigError, 'cfg.od2.opt2')
|
||||
|
||||
|
||||
def test_callback_two_disabled_multi():
|
||||
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
||||
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',), multi=True)
|
||||
|
Reference in New Issue
Block a user