2015-07-24 17:54:10 +02:00
|
|
|
from autopath import do_autopath
|
|
|
|
do_autopath()
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
from py.test import raises
|
|
|
|
|
|
|
|
from tiramisu.config import Config
|
2014-04-12 11:53:58 +02:00
|
|
|
from tiramisu.setting import groups, owners
|
2013-05-08 18:14:42 +02:00
|
|
|
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
2013-09-19 21:38:46 +02:00
|
|
|
StrOption, OptionDescription, SymLinkOption
|
2013-09-16 20:51:13 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def return_val():
|
2013-06-11 15:10:38 +02:00
|
|
|
return 'val'
|
|
|
|
|
|
|
|
|
2013-09-19 21:38:46 +02:00
|
|
|
def return_concat(*args):
|
|
|
|
return '.'.join(list(args))
|
|
|
|
|
|
|
|
|
|
|
|
def return_list(value=None):
|
2013-06-12 10:22:50 +02:00
|
|
|
return ['val', 'val']
|
|
|
|
|
|
|
|
|
2013-09-19 21:38:46 +02:00
|
|
|
def return_list2(*args):
|
2013-12-09 15:08:14 +01:00
|
|
|
l = []
|
|
|
|
for arg in args:
|
|
|
|
if isinstance(arg, list):
|
|
|
|
l.extend(arg)
|
|
|
|
else:
|
|
|
|
l.append(arg)
|
|
|
|
return l
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def return_value(value=None):
|
2013-06-12 10:22:50 +02:00
|
|
|
return value
|
|
|
|
|
|
|
|
|
2013-09-23 22:40:10 +02:00
|
|
|
def return_value2(*args, **kwargs):
|
|
|
|
value = list(args)
|
|
|
|
value.extend(kwargs.values())
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
2013-12-09 15:08:14 +01:00
|
|
|
def return_calc(i, j, k):
|
|
|
|
return i + j + k
|
|
|
|
|
|
|
|
|
2014-03-26 19:44:49 +01:00
|
|
|
def is_config(config, **kwargs):
|
|
|
|
if isinstance(config, Config):
|
|
|
|
return 'yes'
|
|
|
|
else:
|
|
|
|
return 'no'
|
|
|
|
|
|
|
|
|
2013-05-08 18:14:42 +02:00
|
|
|
def make_description_duplicates():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
## dummy 1
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
# dummy2 (same path)
|
|
|
|
gcdummy2 = BoolOption('dummy', 'dummy2', default=True)
|
|
|
|
# dummy3 (same name)
|
|
|
|
gcdummy3 = BoolOption('dummy', 'dummy2', default=True)
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, gcdummy2, floatoption])
|
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop, gcdummy3])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def test_identical_paths():
|
|
|
|
"""If in the schema (the option description) there is something that
|
|
|
|
have the same name, an exection is raised
|
|
|
|
"""
|
|
|
|
raises(ConflictError, "make_description_duplicates()")
|
|
|
|
|
|
|
|
|
|
|
|
def make_description_requires():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc",
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
stroption, intoption])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def test_hidden_if_in():
|
|
|
|
descr = make_description_requires()
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
cfg.read_write()
|
|
|
|
stroption = cfg.unwrap_from_path('str')
|
|
|
|
assert not 'hidden' in setting[stroption]
|
|
|
|
cfg.int = 1
|
|
|
|
raises(PropertiesOptionError, "cfg.str")
|
|
|
|
raises(PropertiesOptionError, 'cfg.str="uvw"')
|
|
|
|
assert 'hidden' in setting[stroption]
|
|
|
|
|
|
|
|
|
|
|
|
def test_hidden_if_in_with_group():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': intoption, 'expected': 1, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
|
|
|
objspaceoption, stroption, intoption])
|
|
|
|
cfg = Config(descr)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
cfg.read_write()
|
|
|
|
assert not 'hidden' in setting[stroption]
|
|
|
|
cfg.int = 1
|
|
|
|
raises(PropertiesOptionError, "cfg.gc.name")
|
|
|
|
|
|
|
|
|
|
|
|
def test_disabled_with_group():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
|
|
|
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption],
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': intoption, 'expected': 1, 'action': 'disabled'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption,
|
|
|
|
objspaceoption, stroption, intoption])
|
|
|
|
cfg = Config(descr)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.gc.name
|
|
|
|
cfg.int = 1
|
|
|
|
raises(PropertiesOptionError, "cfg.gc.name")
|
|
|
|
#____________________________________________________________
|
|
|
|
|
|
|
|
|
|
|
|
def make_description_callback():
|
|
|
|
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
|
|
|
gcdummy = BoolOption('dummy', 'dummy')
|
|
|
|
objspaceoption = ChoiceOption('objspace', 'Object space',
|
|
|
|
('std', 'thunk'), 'std')
|
|
|
|
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
|
|
|
intoption = IntOption('int', 'Test int option', default=0)
|
|
|
|
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
|
|
|
stroption = StrOption('str', 'Test string option', default="abc")
|
|
|
|
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
|
|
|
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
wantframework_option = BoolOption('wantframework', 'Test requires',
|
|
|
|
default=False,
|
2013-06-29 18:41:14 +02:00
|
|
|
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
2013-05-08 18:14:42 +02:00
|
|
|
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption])
|
|
|
|
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
|
|
|
wantref_option, stroption,
|
|
|
|
wantframework_option,
|
|
|
|
intoption, boolop])
|
|
|
|
return descr
|
|
|
|
|
|
|
|
|
|
|
|
def test_has_callback():
|
|
|
|
descr = make_description_callback()
|
|
|
|
# here the owner is 'default'
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
config.bool = False
|
|
|
|
# because dummy has a callback
|
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
|
|
|
setting.append('freeze')
|
|
|
|
setting[dummy].append('frozen')
|
|
|
|
raises(PropertiesOptionError, "config.gc.dummy = True")
|
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_and_has_callback():
|
|
|
|
descr = make_description_callback()
|
|
|
|
config = Config(descr)
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
config.read_write()
|
|
|
|
config.bool = False
|
|
|
|
setting = config.cfgimpl_get_settings()
|
|
|
|
setting.append('freeze')
|
|
|
|
dummy = config.unwrap_from_path('gc.dummy')
|
|
|
|
setting[dummy].append('frozen')
|
|
|
|
raises(PropertiesOptionError, "config.gc.dummy = True")
|
2013-06-11 15:10:38 +02:00
|
|
|
|
|
|
|
|
2013-06-11 15:36:08 +02:00
|
|
|
def test_callback():
|
2013-06-12 10:22:50 +02:00
|
|
|
val1 = StrOption('val1', "", callback=return_val)
|
2013-06-11 15:36:08 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == 'val'
|
|
|
|
cfg.val1 = 'new-val'
|
|
|
|
assert cfg.val1 == 'new-val'
|
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == 'val'
|
|
|
|
|
|
|
|
|
2013-12-09 18:56:29 +01:00
|
|
|
def test_callback_params_without_callback():
|
|
|
|
raises(ValueError, "StrOption('val2', '', callback_params={'': ('yes',)})")
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_invalid():
|
|
|
|
raises(ValueError, 'val1 = StrOption("val1", "", callback="string")')
|
|
|
|
raises(ValueError, 'val1 = StrOption("val1", "", callback=return_val, callback_params="string")')
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
2015-10-26 15:39:07 +01:00
|
|
|
val1
|
2013-12-09 18:56:29 +01:00
|
|
|
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'),)})")
|
2014-03-26 19:44:49 +01:00
|
|
|
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'
|
2013-12-09 18:56:29 +01:00
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def test_callback_value():
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
2013-09-19 21:38:46 +02:00
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)})
|
|
|
|
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)})
|
|
|
|
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == 'val'
|
|
|
|
assert cfg.val2 == 'val'
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val4 == 'val'
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg.val1 = 'new-val'
|
|
|
|
assert cfg.val1 == 'new-val'
|
|
|
|
assert cfg.val2 == 'new-val'
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val4 == 'new-val'
|
2013-06-12 10:22:50 +02:00
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == 'val'
|
|
|
|
assert cfg.val2 == 'val'
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val3 == 'yes'
|
|
|
|
assert cfg.val4 == 'val'
|
|
|
|
assert cfg.val5 == 'yes'
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_tuple():
|
|
|
|
val1 = StrOption('val1', "", 'val1')
|
|
|
|
val2 = StrOption('val2', "", 'val2')
|
|
|
|
val3 = StrOption('val3', "", callback=return_concat, callback_params={'': ((val1, False), (val2, False))})
|
|
|
|
val4 = StrOption('val4', "", callback=return_concat, callback_params={'': ('yes', 'no')})
|
|
|
|
raises(ValueError, "StrOption('val4', '', callback=return_concat, callback_params={'value': ('yes', 'no')})")
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == 'val1'
|
|
|
|
assert cfg.val2 == 'val2'
|
|
|
|
assert cfg.val3 == 'val1.val2'
|
|
|
|
assert cfg.val4 == 'yes.no'
|
|
|
|
cfg.val1 = 'new-val'
|
|
|
|
assert cfg.val3 == 'new-val.val2'
|
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val3 == 'val1.val2'
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_value_force_permissive():
|
|
|
|
val1 = StrOption('val1', "", 'val', properties=('disabled',))
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val1, True),)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_only()
|
|
|
|
raises(ConfigError, "cfg.val2")
|
|
|
|
assert cfg.val3 is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_symlink():
|
|
|
|
val1 = StrOption('val1', "", 'val')
|
|
|
|
val2 = SymLinkOption('val2', val1)
|
|
|
|
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val2, False),)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == 'val'
|
2013-11-23 23:34:17 +01:00
|
|
|
assert cfg.val2 == 'val'
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val3 == 'val'
|
|
|
|
cfg.val1 = 'new-val'
|
|
|
|
assert cfg.val1 == 'new-val'
|
|
|
|
assert cfg.val3 == 'new-val'
|
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == 'val'
|
|
|
|
assert cfg.val3 == 'val'
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list():
|
|
|
|
val1 = StrOption('val1', "", callback=return_list)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
raises(ValueError, "cfg.val1")
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi():
|
|
|
|
val1 = StrOption('val1', "", callback=return_val, multi=True)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == ['val']
|
|
|
|
cfg.val1 = ['new-val']
|
|
|
|
assert cfg.val1 == ['new-val']
|
|
|
|
cfg.val1.append('new-val2')
|
|
|
|
assert cfg.val1 == ['new-val', 'new-val2']
|
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == ['val']
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_value():
|
|
|
|
val1 = StrOption('val1', "", ['val'], multi=True)
|
2013-09-19 21:38:46 +02:00
|
|
|
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, callback=return_list2, callback_params={'': ((val1, False), 'yes')})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == ['val']
|
|
|
|
assert cfg.val2 == ['val']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val4 == ['val', 'yes']
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg.val1 = ['new-val']
|
|
|
|
assert cfg.val1 == ['new-val']
|
|
|
|
assert cfg.val2 == ['new-val']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val4 == ['new-val', 'yes']
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg.val1.append('new-val2')
|
|
|
|
assert cfg.val1 == ['new-val', 'new-val2']
|
|
|
|
assert cfg.val2 == ['new-val', 'new-val2']
|
2013-12-09 15:08:14 +01:00
|
|
|
assert cfg.val4 == ['new-val', 'new-val2', 'yes']
|
2013-06-12 10:22:50 +02:00
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == ['val']
|
|
|
|
assert cfg.val2 == ['val']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val3 == ['yes']
|
|
|
|
assert cfg.val4 == ['val', 'yes']
|
2014-02-02 18:20:01 +01:00
|
|
|
cfg.val2.append('new')
|
|
|
|
assert cfg.val1 == ['val']
|
|
|
|
assert cfg.val2 == ['val', 'new']
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list():
|
|
|
|
val1 = StrOption('val1', "", callback=return_list, multi=True)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == ['val', 'val']
|
|
|
|
cfg.val1 = ['new-val']
|
|
|
|
assert cfg.val1 == ['new-val']
|
|
|
|
cfg.val1.append('new-val2')
|
|
|
|
assert cfg.val1 == ['new-val', 'new-val2']
|
|
|
|
del(cfg.val1)
|
|
|
|
assert cfg.val1 == ['val', 'val']
|
|
|
|
|
|
|
|
|
2013-12-09 15:08:14 +01:00
|
|
|
def test_callback_multi_list_extend():
|
|
|
|
val1 = StrOption('val1', "", callback=return_list2, callback_params={'': (['1', '2', '3'], ['4', '5'])}, multi=True)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1 == ['1', '2', '3', '4', '5']
|
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
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']
|
2014-04-25 22:57:08 +02:00
|
|
|
cfg.val1.val1 = ['val1']
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val1.val1.append()
|
2014-04-25 22:57:08 +02:00
|
|
|
assert cfg.val1.val1 == ['val1', 'val']
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def test_callback_master_and_slaves_master():
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_val)
|
|
|
|
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()
|
|
|
|
assert cfg.val1.val1 == ['val']
|
2013-12-09 17:59:39 +01:00
|
|
|
cfg.val1.val1.append()
|
2013-06-12 10:22:50 +02:00
|
|
|
assert cfg.val1.val1 == ['val', 'val']
|
|
|
|
assert cfg.val1.val2 == [None, None]
|
|
|
|
|
|
|
|
|
2014-04-02 12:04:50 +02:00
|
|
|
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']
|
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def test_callback_master_and_slaves_master_list():
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_list)
|
|
|
|
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()
|
|
|
|
assert cfg.val1.val1 == ['val', 'val']
|
|
|
|
assert cfg.val1.val2 == [None, None]
|
2013-12-09 17:59:39 +01:00
|
|
|
cfg.val1.val1.append()
|
2013-06-12 10:22:50 +02:00
|
|
|
assert cfg.val1.val1 == ['val', 'val', None]
|
|
|
|
assert cfg.val1.val2 == [None, None, None]
|
|
|
|
del(cfg.val1.val1)
|
|
|
|
assert cfg.val1.val1 == ['val', 'val']
|
|
|
|
assert cfg.val1.val2 == [None, None]
|
|
|
|
assert cfg.val1.val1.pop(1)
|
|
|
|
assert cfg.val1.val1 == ['val']
|
|
|
|
assert cfg.val1.val2 == [None]
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_master_and_slaves_slave():
|
2013-06-11 15:10:38 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
2013-06-12 10:22:50 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
2013-06-11 15:10:38 +02:00
|
|
|
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']
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
2014-04-02 12:04:50 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2014-02-02 18:20:01 +01:00
|
|
|
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),)})
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_val)
|
|
|
|
interface1 = OptionDescription('val1', '', [val1, val2])
|
|
|
|
interface1.impl_set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val3 == []
|
|
|
|
assert cfg.val1.val1 == []
|
|
|
|
assert cfg.val1.val2 == []
|
|
|
|
cfg.val1.val1 = ['val1']
|
|
|
|
cfg.val3 = ['val1']
|
|
|
|
assert cfg.val1.val1 == ['val1']
|
|
|
|
assert cfg.val1.val2 == ['val']
|
|
|
|
del(cfg.val1.val1)
|
|
|
|
cfg.val1.val2 = ['val']
|
|
|
|
cfg.val3 = ['val1', 'val2']
|
|
|
|
assert cfg.val1.val2 == ['val', 'val']
|
|
|
|
assert cfg.val1.val1 == ['val1', 'val2']
|
|
|
|
cfg.val1.val2 = ['val1', 'val2']
|
|
|
|
cfg.val3.pop(1)
|
|
|
|
# cannot remove slave's value because master is calculated
|
|
|
|
# so raise
|
|
|
|
raises(SlaveError, "cfg.val1.val1")
|
|
|
|
raises(SlaveError, "cfg.val1.val2")
|
|
|
|
cfg.val3 = ['val1', 'val2', 'val3']
|
|
|
|
assert cfg.val1.val2 == ['val1', 'val2', 'val']
|
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
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 == []
|
2015-11-19 22:25:00 +01:00
|
|
|
assert cfg.val1.val2 == []
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val1.val1.append('yes')
|
|
|
|
assert cfg.val1.val1 == ['yes']
|
|
|
|
cfg.cfgimpl_get_settings().remove('disabled')
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val2")
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val1.val2 = ['no']
|
|
|
|
cfg.val1.val1.append('yes1')
|
|
|
|
raises(SlaveError, "cfg.val1.val2")
|
2015-11-19 22:25:00 +01:00
|
|
|
cfg.cfgimpl_get_settings().append('disabled')
|
|
|
|
raises(ConfigError, "cfg.val1.val1.pop(0)")
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_master_and_slaves_value():
|
2014-04-12 11:53:58 +02:00
|
|
|
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
|
2013-06-12 10:22:50 +02:00
|
|
|
val1 = StrOption('val1', "", multi=True)
|
2013-09-19 21:38:46 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)})
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)})
|
|
|
|
val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params={'': ((val4, False),)})
|
2013-12-09 15:08:14 +01:00
|
|
|
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params={'': ((val5, False),)})
|
|
|
|
interface1 = OptionDescription('val1', '', [val1, val2, val3, val5, val6])
|
2013-06-12 10:22:50 +02:00
|
|
|
interface1.impl_set_group_type(groups.master)
|
2013-09-19 21:38:46 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
|
2013-06-12 10:22:50 +02:00
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val4 == ['val10', 'val11']
|
2015-11-19 22:25:00 +01:00
|
|
|
assert cfg.val1.val1 == []
|
|
|
|
assert cfg.val1.val2 == []
|
|
|
|
assert cfg.val1.val3 == []
|
|
|
|
assert cfg.val1.val5 == []
|
|
|
|
assert cfg.val1.val6 == []
|
|
|
|
#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")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2014-04-12 11:53:58 +02:00
|
|
|
#default calculation has greater length
|
2015-11-19 22:25:00 +01:00
|
|
|
#raises(SlaveError, "cfg.val1.val1 = ['val1']")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val1.val1 = ['val1', 'val2']
|
2013-06-12 10:22:50 +02:00
|
|
|
assert cfg.val1.val1 == ['val1', 'val2']
|
|
|
|
assert cfg.val1.val2 == ['val1', 'val2']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val1.val3 == ['yes', 'yes']
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val5")
|
|
|
|
raises(SlaveError, "cfg.val1.val6")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2014-04-12 11:53:58 +02:00
|
|
|
cfg.val1.val1.append('val3')
|
2013-06-12 10:22:50 +02:00
|
|
|
assert cfg.val1.val1 == ['val1', 'val2', 'val3']
|
|
|
|
assert cfg.val1.val2 == ['val1', 'val2', 'val3']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val1.val3 == ['yes', 'yes', 'yes']
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val5")
|
|
|
|
raises(SlaveError, "cfg.val1.val6")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
|
|
|
cfg.val1.val1.pop(2)
|
|
|
|
assert cfg.val1.val1 == ['val1', 'val2']
|
|
|
|
assert cfg.val1.val2 == ['val1', 'val2']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val1.val3 == ['yes', 'yes']
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val5")
|
|
|
|
raises(SlaveError, "cfg.val1.val6")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
|
|
|
cfg.val1.val2 = ['val2', 'val2']
|
2013-09-19 21:38:46 +02:00
|
|
|
cfg.val1.val3 = ['val2', 'val2']
|
|
|
|
cfg.val1.val5 = ['val2', 'val2']
|
2013-06-12 10:22:50 +02:00
|
|
|
assert cfg.val1.val2 == ['val2', 'val2']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val1.val3 == ['val2', 'val2']
|
|
|
|
assert cfg.val1.val5 == ['val2', 'val2']
|
2013-12-09 15:08:14 +01:00
|
|
|
assert cfg.val1.val6 == ['val2', 'val2']
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
|
|
|
cfg.val1.val1.append('val3')
|
|
|
|
assert cfg.val1.val2 == ['val2', 'val2', 'val3']
|
2013-09-19 21:38:46 +02:00
|
|
|
assert cfg.val1.val3 == ['val2', 'val2', 'yes']
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val5")
|
|
|
|
raises(SlaveError, "cfg.val1.val6")
|
2013-09-19 21:38:46 +02:00
|
|
|
cfg.cfgimpl_get_settings().remove('cache')
|
|
|
|
cfg.val4 = ['val10', 'val11', 'val12']
|
|
|
|
#if value is already set, not updated !
|
|
|
|
cfg.val1.val1.pop(2)
|
|
|
|
cfg.val1.val1.append('val3')
|
|
|
|
cfg.val1.val1 = ['val1', 'val2', 'val3']
|
2015-11-19 22:25:00 +01:00
|
|
|
raises(SlaveError, "cfg.val1.val5")
|
|
|
|
raises(SlaveError, "cfg.val1.val6")
|
2015-10-26 15:39:07 +01:00
|
|
|
|
|
|
|
|
2013-12-09 15:08:14 +01:00
|
|
|
def test_callback_master():
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value)
|
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
|
|
|
|
interface1 = OptionDescription('val1', '', [val1, val2])
|
2015-10-26 15:39:07 +01:00
|
|
|
interface1
|
2013-12-09 15:08:14 +01:00
|
|
|
raises(ValueError, "interface1.impl_set_group_type(groups.master)")
|
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
#FIXME: slave est un symlink
|
2013-12-09 15:08:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_different_type():
|
|
|
|
val = IntOption('val', "", default=2)
|
|
|
|
val_ = IntOption('val_', "", default=3)
|
|
|
|
val1 = IntOption('val1', "", multi=True)
|
|
|
|
val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params={'': ((val, False), (val1, False)), 'k': ((val_, False),)})
|
|
|
|
interface1 = OptionDescription('val1', '', [val1, val2])
|
|
|
|
interface1.impl_set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
assert cfg.val1.val1 == []
|
|
|
|
assert cfg.val1.val2 == []
|
|
|
|
cfg.val1.val1 = [1]
|
|
|
|
assert cfg.val1.val1 == [1]
|
|
|
|
assert cfg.val1.val2 == [6]
|
|
|
|
cfg.val1.val1 = [1, 3]
|
|
|
|
assert cfg.val1.val1 == [1, 3]
|
|
|
|
assert cfg.val1.val2 == [6, 8]
|
|
|
|
cfg.val1.val1 = [1, 3, 5]
|
|
|
|
assert cfg.val1.val1 == [1, 3, 5]
|
|
|
|
assert cfg.val1.val2 == [6, 8, 10]
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
2013-06-26 16:26:42 +02:00
|
|
|
def test_callback_hidden():
|
|
|
|
opt1 = BoolOption('opt1', '')
|
2013-09-19 21:38:46 +02:00
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
|
2013-06-26 16:26:42 +02:00
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
2013-08-21 22:21:50 +02:00
|
|
|
cfg.cfgimpl_get_settings().setpermissive(('hidden',))
|
2013-06-26 16:26:42 +02:00
|
|
|
cfg.read_write()
|
|
|
|
raises(PropertiesOptionError, 'cfg.od1.opt1')
|
|
|
|
cfg.od2.opt2
|
2013-09-16 15:02:14 +02:00
|
|
|
|
|
|
|
|
2013-09-16 20:51:13 +02:00
|
|
|
def test_callback_two_disabled():
|
2013-09-16 15:02:14 +02:00
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
2013-09-19 21:38:46 +02:00
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',))
|
2013-09-16 15:02:14 +02:00
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
2013-09-16 20:51:13 +02:00
|
|
|
raises(PropertiesOptionError, 'cfg.od2.opt2')
|
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2015-04-18 23:46:37 +02:00
|
|
|
def test_callback_calculating_invalid():
|
|
|
|
opt1 = IntOption('opt1', '', 1)
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
setting = cfg.cfgimpl_get_settings()
|
|
|
|
cfg.read_write()
|
|
|
|
raises(ValueError, 'cfg.od2.opt2')
|
|
|
|
setting[opt2].append('disabled')
|
|
|
|
raises(PropertiesOptionError, 'cfg.od2.opt2')
|
|
|
|
|
|
|
|
|
2013-09-16 20:51:13 +02:00
|
|
|
def test_callback_calculating_disabled():
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
2013-09-19 21:38:46 +02:00
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
|
2013-09-16 20:51:13 +02:00
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
raises(ConfigError, 'cfg.od2.opt2')
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_calculating_mandatory():
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
2013-09-19 21:38:46 +02:00
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('mandatory',))
|
2013-09-16 20:51:13 +02:00
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_only()
|
|
|
|
raises(ConfigError, 'cfg.od2.opt2')
|
2013-09-17 09:10:08 +02:00
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
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')
|
|
|
|
|
|
|
|
|
2013-09-17 09:10:08 +02:00
|
|
|
def test_callback_two_disabled_multi():
|
|
|
|
opt1 = BoolOption('opt1', '', properties=('disabled',))
|
2013-09-19 21:38:46 +02:00
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',), multi=True)
|
2013-09-17 09:10:08 +02:00
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
|
|
|
raises(PropertiesOptionError, 'cfg.od2.opt2')
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params():
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'': ((val1, False),)})
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
2013-12-09 15:08:14 +01:00
|
|
|
assert cfg.val2.val2 == ['val', 'val']
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_multi_list_params_key():
|
|
|
|
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'value': ((val1, False),)})
|
|
|
|
oval2 = OptionDescription('val2', '', [val2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, oval2])
|
|
|
|
cfg = Config(maconfig)
|
|
|
|
cfg.read_write()
|
2013-12-09 15:08:14 +01:00
|
|
|
assert cfg.val2.val2 == ['val', 'val']
|
2014-06-19 23:22:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_masterslaves_callback_description():
|
|
|
|
st1 = StrOption('st1', "", multi=True)
|
|
|
|
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params={'': ((st1, False),)})
|
|
|
|
stm = OptionDescription('st1', '', [st1, st2])
|
|
|
|
stm.impl_set_group_type(groups.master)
|
|
|
|
st = OptionDescription('st', '', [stm])
|
|
|
|
od = OptionDescription('od', '', [st])
|
|
|
|
od2 = OptionDescription('od', '', [od])
|
|
|
|
cfg = Config(od2)
|
|
|
|
owner = cfg.cfgimpl_get_settings().getowner()
|
|
|
|
st1 = cfg.unwrap_from_path('od.st.st1.st1')
|
|
|
|
st2 = cfg.unwrap_from_path('od.st.st1.st2')
|
|
|
|
assert cfg.od.st.st1.st1 == []
|
|
|
|
assert cfg.od.st.st1.st2 == []
|
|
|
|
assert cfg.getowner(st1) == owners.default
|
|
|
|
assert cfg.getowner(st2) == owners.default
|
|
|
|
##
|
|
|
|
cfg.od.st.st1.st1.append('yes')
|
|
|
|
assert cfg.od.st.st1.st1 == ['yes']
|
|
|
|
assert cfg.od.st.st1.st2 == ['yes']
|
|
|
|
assert cfg.getowner(st1) == owner
|