2017-07-09 09:49:03 +02:00
|
|
|
from .autopath import do_autopath
|
2015-07-24 17:54:10 +02:00
|
|
|
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
|
2018-03-19 08:33:53 +01:00
|
|
|
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
|
|
|
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \
|
|
|
|
getapi, undefined
|
|
|
|
from tiramisu.api import TIRAMISU_VERSION
|
2013-09-16 20:51:13 +02:00
|
|
|
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
|
2018-04-10 22:42:20 +02:00
|
|
|
from tiramisu.i18n import _
|
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
|
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
def return_value3(value=None, index=None):
|
|
|
|
if index is not None and isinstance(value, list):
|
|
|
|
if len(value) > index:
|
|
|
|
return value[index]
|
|
|
|
return None
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
def return_index(val1, val2=None, index=None, self=None):
|
|
|
|
if index is None:
|
|
|
|
return [val1, val2]
|
|
|
|
if index == 0:
|
|
|
|
return val1
|
|
|
|
if index == 1:
|
|
|
|
return val2
|
|
|
|
|
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'
|
|
|
|
|
|
|
|
|
2017-09-17 15:55:32 +02:00
|
|
|
def ret_from_config(config):
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(config)
|
|
|
|
return api.option('val1').value.get()
|
2017-09-17 15:55:32 +02:00
|
|
|
|
|
|
|
|
2017-02-11 18:11:05 +01:00
|
|
|
def return_raise(*arg):
|
|
|
|
raise Exception('test')
|
|
|
|
|
|
|
|
|
|
|
|
def return_valueerror(*arg):
|
|
|
|
raise ValueError('test')
|
|
|
|
|
|
|
|
|
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()")
|
|
|
|
|
|
|
|
|
2018-03-19 08:33:53 +01:00
|
|
|
def test_hidden_if_in():
|
2013-05-08 18:14:42 +02:00
|
|
|
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'},))
|
2018-03-19 08:33:53 +01:00
|
|
|
descr = OptionDescription('constraints', '', [stroption, intoption])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
assert not 'hidden' in api.option('str').property.get()
|
|
|
|
api.option('int').value.set(1)
|
|
|
|
raises(PropertiesOptionError, "api.option('str').value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.option('str').value.set('uvw')")
|
|
|
|
assert 'hidden' in api.unrestraint.option('str').property.get()
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
assert not 'hidden' in api.option('str').property.get()
|
|
|
|
api.option('int').value.set(1)
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.name').value.get()")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
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,
|
2018-03-19 08:33:53 +01:00
|
|
|
objspaceoption, stroption, intoption])
|
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('gc.name').value.get()
|
|
|
|
api.option('int').value.set(1)
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.name').value.get()")
|
2013-05-08 18:14:42 +02:00
|
|
|
#____________________________________________________________
|
|
|
|
|
|
|
|
|
|
|
|
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'
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('bool').value.set(False)
|
2013-05-08 18:14:42 +02:00
|
|
|
# because dummy has a callback
|
2018-03-19 08:33:53 +01:00
|
|
|
api.property.add('freeze')
|
|
|
|
api.option('gc.dummy').property.add('frozen')
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(True)")
|
2013-05-08 18:14:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_freeze_and_has_callback():
|
|
|
|
descr = make_description_callback()
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(descr))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('bool').value.set(False)
|
|
|
|
api.property.add('freeze')
|
|
|
|
api.option('gc.dummy').property.add('frozen')
|
|
|
|
raises(PropertiesOptionError, "api.option('gc.dummy').value.set(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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
|
|
|
api.option('val1').value.set('new-val')
|
|
|
|
assert api.option('val1').value.get() == 'new-val'
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
2013-06-11 15:36:08 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
assert api.option('val1').value.get() == 'yes'
|
2014-03-26 19:44:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_context_named():
|
|
|
|
val1 = StrOption("val1", "", callback=is_config, callback_params={'config': ((None,),)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
assert api.option('val1').value.get() == 'yes'
|
2014-03-26 19:44:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_with_error():
|
|
|
|
val1 = StrOption("val1", "", callback=is_config, callback_params={'': ('string',), 'value': ('string',)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
assert api.option('val1').value.get() == 'no'
|
2013-12-09 18:56:29 +01:00
|
|
|
|
|
|
|
|
2017-09-17 15:55:32 +02:00
|
|
|
def test_callback_with_context_value():
|
|
|
|
val1 = StrOption("val1", "")
|
|
|
|
val2 = StrOption("val2", "", callback=ret_from_config, callback_params={'': ((None,),)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.option('val1').value.set('yes')
|
|
|
|
assert api.option('val1').value.get() == 'yes'
|
|
|
|
assert api.option('val2').value.get() == 'yes'
|
|
|
|
api.option('val1').value.set('no')
|
|
|
|
assert api.option('val1').value.get() == 'no'
|
|
|
|
assert api.option('val2').value.get() == 'no'
|
2017-09-17 15:55:32 +02: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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
|
|
|
assert api.option('val2').value.get() == 'val'
|
|
|
|
assert api.option('val4').value.get() == 'val'
|
|
|
|
api.option('val1').value.set('new-val')
|
|
|
|
assert api.option('val1').value.get() == 'new-val'
|
|
|
|
assert api.option('val2').value.get() == 'new-val'
|
|
|
|
assert api.option('val4').value.get() == 'new-val'
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
|
|
|
assert api.option('val2').value.get() == 'val'
|
|
|
|
assert api.option('val3').value.get() == 'yes'
|
|
|
|
assert api.option('val4').value.get() == 'val'
|
|
|
|
assert api.option('val5').value.get() == 'yes'
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == 'val1'
|
|
|
|
assert api.option('val2').value.get() == 'val2'
|
|
|
|
assert api.option('val3').value.get() == 'val1.val2'
|
|
|
|
assert api.option('val4').value.get() == 'yes.no'
|
|
|
|
api.option('val1').value.set('new-val')
|
|
|
|
assert api.option('val3').value.get() == 'new-val.val2'
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val3').value.get() == 'val1.val2'
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
raises(ConfigError, "api.option('val2').value.get()")
|
|
|
|
api.option('val3').value.get() is None
|
2013-09-19 21:38:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
|
|
|
assert api.option('val2').value.get() == 'val'
|
|
|
|
assert api.option('val3').value.get() == 'val'
|
|
|
|
api.option('val1').value.set('new-val')
|
|
|
|
assert api.option('val1').value.get() == 'new-val'
|
|
|
|
assert api.option('val3').value.get() == 'new-val'
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == 'val'
|
|
|
|
assert api.option('val3').value.get() == 'val'
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_list():
|
|
|
|
val1 = StrOption('val1', "", callback=return_list)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ValueError, "api.option('val1').value.get()")
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
2017-01-26 21:01:54 +01:00
|
|
|
def test_callback_list2():
|
|
|
|
val1 = StrOption('val1', "", callback=return_list)
|
|
|
|
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)})
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1, val2])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ValueError, "api.option('val1').value.get()")
|
2017-01-26 21:01:54 +01:00
|
|
|
#cfg.val2
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(ValueError, "api.option('val2').value.get()")
|
2017-01-26 21:01:54 +01:00
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
def test_callback_multi():
|
|
|
|
val1 = StrOption('val1', "", callback=return_val, multi=True)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [val1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == ['val']
|
|
|
|
api.option('val1').value.set(['new-val'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val']
|
|
|
|
api.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == ['val']
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == ['val']
|
|
|
|
assert api.option('val2').value.get() == ['val']
|
|
|
|
assert api.option('val4').value.get() == ['val', 'yes']
|
|
|
|
api.option('val1').value.set(['new-val'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val']
|
|
|
|
assert api.option('val2').value.get() == ['new-val']
|
|
|
|
assert api.option('val4').value.get() == ['new-val', 'yes']
|
|
|
|
api.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
assert api.option('val2').value.get() == ['new-val', 'new-val2']
|
|
|
|
assert api.option('val4').value.get() == ['new-val', 'new-val2', 'yes']
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == ['val']
|
|
|
|
assert api.option('val2').value.get() == ['val']
|
|
|
|
assert api.option('val3').value.get() == ['yes']
|
|
|
|
assert api.option('val4').value.get() == ['val', 'yes']
|
|
|
|
api.option('val2').value.set(['val', 'new'])
|
|
|
|
assert api.option('val1').value.get() == ['val']
|
|
|
|
assert api.option('val2').value.get() == ['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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == ['val', 'val']
|
|
|
|
api.option('val1').value.set(['new-val'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val']
|
|
|
|
api.option('val1').value.set(['new-val', 'new-val2'])
|
|
|
|
assert api.option('val1').value.get() == ['new-val', 'new-val2']
|
|
|
|
api.option('val1').value.reset()
|
|
|
|
assert api.option('val1').value.get() == ['val', 'val']
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1').value.get() == ['1', '2', '3', '4', '5']
|
2013-12-09 15:08:14 +01:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val']
|
|
|
|
api.option('val1.val1').value.set(['val1', undefined])
|
|
|
|
assert api.option('val1.val1').value.get() == ['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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2013-06-12 10:22:50 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val']
|
|
|
|
api.option('val1.val1').value.set([undefined, undefined])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
2017-01-26 21:18:57 +01:00
|
|
|
def test_callback_slave():
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
2018-03-19 08:33:53 +01:00
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params={'': (['string', 'new'],)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-01-26 21:18:57 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set(['val'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
api.option('val1.val1').value.set(['val', 'val1'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
api.option('val1.val1').value.set(['val', 'val1', 'val2'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == None
|
|
|
|
api.option('val1.val1').value.set(['val', 'val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'string'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'new'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == None
|
|
|
|
assert api.option('val1.val2', 3).value.get() == None
|
2017-01-26 21:18:57 +01:00
|
|
|
|
|
|
|
|
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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-02 12:04:50 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set(['val'])
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val2'
|
2014-04-02 12:04:50 +02:00
|
|
|
|
|
|
|
|
2017-03-02 21:21:03 +01:00
|
|
|
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',))
|
2018-03-19 08:33:53 +01:00
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
|
|
|
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params={'': ((val1, False),)}, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-03-02 21:21:03 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val']
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set([undefined, 'val3'])
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val3']
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val3', 1).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val4', 1).value.get()")
|
2017-03-02 21:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_master_and_slaves_master_mandatory2():
|
|
|
|
val = StrOption('val', "", default='val')
|
|
|
|
val_ = StrOption('val_', "", default='val_')
|
2018-03-19 08:33:53 +01:00
|
|
|
val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params={'': ((val, False),), 'val2': ((val_, False),)}, properties=('mandatory',))
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params={'': ((val1, False),), 'val2': ((val_, False),)}, properties=('mandatory',))
|
|
|
|
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params={'': ((val1, False),), 'val2': ((val_, False),)}, properties=('mandatory',))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-03-02 21:21:03 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val_']
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set(['val', 'val_', 'val3'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val3', 2).value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val4', 2).value.get()")
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
2017-03-02 21:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
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',))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-03-02 21:21:03 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val_']
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set(['val', 'val_', 'val3'])
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val3', 2).value.get() == 'val3'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 1).value.get() == 'val_'
|
|
|
|
assert api.option('val1.val4', 2).value.get() == 'val3'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val_', 'val3']
|
2017-03-02 21:21:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
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',))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2017-03-02 21:21:03 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [val, interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
#raises(IndexError, "api.option('val1.val3').value.get()")
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val']
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val1.val1').value.set(['val', 'val3'])
|
|
|
|
api.property.read_only()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val3']
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val3'
|
|
|
|
assert api.option('val1.val4', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val4', 1).value.get() == 'val3'
|
2017-03-02 21:21:03 +01:00
|
|
|
|
|
|
|
|
2016-03-17 22:06:16 +01:00
|
|
|
def test_callback_master_and_slaves_master3():
|
|
|
|
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
|
|
|
|
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2016-03-17 22:06:16 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert list(api.value.mandatory_warnings()) == ['val1.val1']
|
2016-03-17 22:06:16 +01:00
|
|
|
|
|
|
|
|
2016-03-18 16:41:59 +01:00
|
|
|
def test_callback_master_and_slaves_master4():
|
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
|
|
|
|
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
|
|
|
|
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)})
|
|
|
|
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2016-03-18 16:41:59 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
api.property.add('expert')
|
|
|
|
api.permissive.set(frozenset(['expert']))
|
|
|
|
assert list(api.value.mandatory_warnings()) == []
|
2016-03-18 16:41:59 +01:00
|
|
|
|
|
|
|
|
2016-10-12 21:58:37 +02:00
|
|
|
def test_consistency_master_and_slaves_master_mandatory_transitive():
|
2016-03-18 19:55:41 +01:00
|
|
|
#default value
|
|
|
|
val1 = IPOption('val1', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
|
|
|
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
|
|
|
val2.impl_add_consistency('ip_netmask', val1)
|
|
|
|
#no value
|
|
|
|
val3 = IPOption('val3', "", multi=True, properties=('mandatory',))
|
|
|
|
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
|
|
|
val4.impl_add_consistency('ip_netmask', val3)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
interface2 = MasterSlaves('val3', '', [val3, val4])
|
2016-03-18 19:55:41 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
2018-04-10 22:42:20 +02:00
|
|
|
err = None
|
|
|
|
try:
|
|
|
|
api.option('val1.val1').value.get()
|
|
|
|
except PropertiesOptionError as error:
|
|
|
|
err = error
|
|
|
|
assert err, 'should raises'
|
|
|
|
assert str(err) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', 'property', '"disabled"'))
|
2018-03-19 08:33:53 +01:00
|
|
|
raises(PropertiesOptionError, "api.option('val3.val3').value.get()")
|
|
|
|
assert list(api.value.mandatory_warnings()) == []
|
2016-03-18 19:55:41 +01:00
|
|
|
|
|
|
|
|
2016-10-12 21:58:37 +02:00
|
|
|
def test_consistency_master_and_slaves_master_mandatory_non_transitive():
|
2016-03-18 19:55:41 +01:00
|
|
|
#no value
|
|
|
|
val1 = IPOption('val1', "", multi=True, properties=('mandatory',))
|
|
|
|
val2 = NetmaskOption('val2', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
|
|
|
val2.impl_add_consistency('ip_netmask', val1, transitive=False)
|
|
|
|
#default value
|
|
|
|
val3 = IPOption('val3', "", ['192.168.0.1'], multi=True, properties=('mandatory',))
|
|
|
|
val4 = NetmaskOption('val4', "", multi=True, default_multi='255.255.255.0', properties=('disabled', 'mandatory'))
|
|
|
|
val4.impl_add_consistency('ip_netmask', val3, transitive=False)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
interface2 = MasterSlaves('val3', '', [val3, val4])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
|
|
|
#interface2.impl_set_group_type(groups.master)
|
2016-03-18 19:55:41 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
assert list(api.value.mandatory_warnings()) == ["val1.val1", "val1.val2"]
|
|
|
|
else:
|
|
|
|
assert list(api.value.mandatory_warnings()) == ["val1.val1"]
|
2016-03-18 19:55:41 +01:00
|
|
|
|
|
|
|
|
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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2013-06-12 10:22:50 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
|
|
|
api.option('val1.val1').value.set(['val', 'val', undefined])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val', None]
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
|
|
|
api.option('val1.val1').value.reset()
|
|
|
|
assert api.option('val1.val1').value.get() == ['val', 'val']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
|
|
|
api.option('val1.val1').value.pop(1)
|
|
|
|
assert api.option('val1.val1').value.get() == ['val']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
2013-06-12 10:22:50 +02:00
|
|
|
|
|
|
|
|
2018-04-09 21:37:49 +02:00
|
|
|
def test_callback_master_and_slaves_master_slave_list():
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", multi=True, callback=return_list)
|
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
|
|
|
api.option('val1.val1').value.set(['val1'])
|
|
|
|
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
|
|
|
|
|
|
|
|
2013-06-12 10:22:50 +02:00
|
|
|
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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2013-06-11 15:10:38 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val'
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 'val'
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.pop(2)
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val'
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val2', 0).value.set('val2')
|
|
|
|
api.option('val1.val2', 1).value.set('val2')
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
2013-06-11 15:10:38 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == '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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-02 12:04:50 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
2014-04-02 12:04:50 +02:00
|
|
|
|
|
|
|
|
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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-02-02 18:20:01 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val3])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val3').value.get() == []
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
|
|
|
api.option('val1.val1').value.set(['val1'])
|
|
|
|
api.option('val3').value.set(['val1'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
api.option('val1.val1').value.reset()
|
|
|
|
api.option('val1.val2', 0).value.set('val')
|
|
|
|
api.option('val3').value.set(['val1', 'val2'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val'
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
api.option('val1.val2', 0).value.set('val1')
|
|
|
|
api.option('val1.val2', 1).value.set('val2')
|
|
|
|
api.option('val3').value.set(['val1'])
|
2014-02-02 18:20:01 +01:00
|
|
|
# cannot remove slave's value because master is calculated
|
|
|
|
# so raise
|
2018-03-19 08:33:53 +01:00
|
|
|
if TIRAMISU_VERSION == 2:
|
|
|
|
raises(SlaveError, "api.option('val1.val1').value.get()")
|
|
|
|
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
|
|
|
else:
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1']
|
|
|
|
raises(SlaveError, "api.option('val1.val2', 0).value.get()")
|
|
|
|
api.option('val3').value.set(['val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 'val'
|
2014-02-02 18:20:01 +01:00
|
|
|
|
|
|
|
|
2014-04-12 11:53:58 +02:00
|
|
|
def test_callback_master_and_slaves_master_disabled():
|
|
|
|
#properties must be transitive
|
2018-03-19 08:33:53 +01:00
|
|
|
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('disabled',))
|
2014-04-12 11:53:58 +02:00
|
|
|
val2 = StrOption('val2', "", multi=True)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-12 11:53:58 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val1').value.get()")
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val1').value.set(['yes'])")
|
|
|
|
raises(PropertiesOptionError, "api.option('val1.val2', 0).value.get()")
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-12 11:53:58 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ConfigError, "api.option('val1.val1').value.get()")
|
|
|
|
raises(ConfigError, "api.option('val1.val2').value.get()")
|
|
|
|
api.property.pop('disabled')
|
|
|
|
api.option('val1.val1').value.set([])
|
|
|
|
api.property.add('disabled')
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_master_and_slaves_slave_disabled():
|
|
|
|
val1 = StrOption('val1', "", multi=True)
|
|
|
|
val2 = StrOption('val2', "", multi=True, properties=('disabled',))
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-12 11:53:58 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
|
|
|
#raises(PropertiesOptionError, "api.option('val1.val2').value.get()")
|
|
|
|
api.option('val1.val1').value.set(['yes'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['yes']
|
|
|
|
api.property.pop('disabled')
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
api.option('val1.val2', 0).value.set('no')
|
|
|
|
api.option('val1.val1').value.set(['yes', 'yes2', 'yes3'])
|
|
|
|
api.option('val1.val2', 2).value.set('no1')
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'no'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == None
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 'no1'
|
|
|
|
api.property.add('disabled')
|
|
|
|
api.option('val1.val1').value.pop(0)
|
|
|
|
assert api.option('val1.val1').value.get() == ['yes2', 'yes3']
|
|
|
|
api.property.pop('disabled')
|
|
|
|
assert api.option('val1.val2', 0).value.get() == None
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'no1'
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2014-04-12 11:53:58 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val0])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
|
|
|
api.option('val1.val1').value.set(['yes'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['yes']
|
|
|
|
api.property.pop('disabled')
|
|
|
|
api.option('val1.val2', 0).value.set('no')
|
|
|
|
api.option('val1.val1').value.set(['yes', 'yes1'])
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'no'
|
|
|
|
api.property.add('disabled')
|
|
|
|
api.option('val1.val1').value.pop(1)
|
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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2013-09-19 21:38:46 +02:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val4])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
api.option('val4').value.get() == ['val10', 'val11']
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
2015-11-19 22:25:00 +01:00
|
|
|
#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
|
2018-03-19 08:33:53 +01:00
|
|
|
#raises(SlaveError, "api.option('val1.val1').value.set(['val1']")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'yes'
|
|
|
|
raises(SlaveError, "api.option('val1.val5', 0).value.get()")
|
|
|
|
raises(SlaveError, "api.option('val1.val5', 1).value.get()")
|
|
|
|
raises(SlaveError, "api.option('val1.val6', 0).value.get()")
|
|
|
|
raises(SlaveError, "api.option('val1.val6', 1).value.get()")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2', 'val3']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 'val3'
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'yes'
|
|
|
|
assert api.option('val1.val3', 2).value.get() == 'yes'
|
|
|
|
raises(SlaveError, "api.option('val1.val5', 2).value.get()")
|
|
|
|
raises(SlaveError, "api.option('val1.val6', 2).value.get()")
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.pop(2)
|
|
|
|
assert api.option('val1.val1').value.get() == ['val1', 'val2']
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val1'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'yes'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'yes'
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val2', 0).value.set('val2')
|
|
|
|
api.option('val1.val2', 1).value.set('val2')
|
|
|
|
api.option('val1.val3', 0).value.set('val2')
|
|
|
|
api.option('val1.val3', 1).value.set('val2')
|
|
|
|
api.option('val1.val5', 0).value.set('val2')
|
|
|
|
api.option('val1.val5', 1).value.set('val2')
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val3', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val3', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val5', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val5', 1).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val6', 0).value.get() == 'val2'
|
|
|
|
assert api.option('val1.val6', 1).value.get() == 'val2'
|
2013-06-12 10:22:50 +02:00
|
|
|
#
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('val1.val1').value.set(['val1', 'val2', 'val3'])
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 'val3'
|
|
|
|
assert api.option('val1.val3', 2).value.get() == 'yes'
|
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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
raises(ValueError, "MasterSlaves('val1', '', [val1, val2])")
|
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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
interface1 = MasterSlaves('val1', '', [val1, val2])
|
|
|
|
#interface1.impl_set_group_type(groups.master)
|
2013-12-09 15:08:14 +01:00
|
|
|
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val1.val1').value.get() == []
|
|
|
|
api.option('val1.val1').value.set([1])
|
|
|
|
assert api.option('val1.val1').value.get() == [1]
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 6
|
|
|
|
api.option('val1.val1').value.set([1, 3])
|
|
|
|
assert api.option('val1.val1').value.get() == [1, 3]
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 6
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 8
|
|
|
|
api.option('val1.val1').value.set([1, 3, 5])
|
|
|
|
assert api.option('val1.val1').value.get() == [1, 3, 5]
|
|
|
|
assert api.option('val1.val2', 0).value.get() == 6
|
|
|
|
assert api.option('val1.val2', 1).value.get() == 8
|
|
|
|
assert api.option('val1.val2', 2).value.get() == 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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
|
|
|
|
api.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive():
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)})
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.permissive.set(frozenset(['hidden']))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
|
|
|
|
api.option('od2.opt2').value.get()
|
|
|
|
|
|
|
|
|
|
|
|
def test_callback_hidden_permissive_callback():
|
|
|
|
opt1 = BoolOption('opt1', '')
|
|
|
|
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, True),)})
|
|
|
|
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od1.opt1').value.get()")
|
|
|
|
api.option('od2.opt2').value.get()
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
|
2013-09-16 20:51:13 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
api.permissive.set(frozenset(['hidden']))
|
|
|
|
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
|
|
|
|
assert api.forcepermissive.option('od2.opt2').owner.isdefault()
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ValueError, "api.option('od2.opt2').value.get()")
|
|
|
|
api.unrestraint.option('od2.opt2').property.add('disabled')
|
|
|
|
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
|
2015-04-18 23:46:37 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(ConfigError, "api.option('od2.opt2').value.get()")
|
2013-09-16 20:51:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
raises(ConfigError, "api.option('od2.opt2').value.get()")
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_only()
|
|
|
|
raises(ConfigError, "api.option('od2.opt2').value.get()")
|
2014-04-12 11:53:58 +02:00
|
|
|
|
|
|
|
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
raises(PropertiesOptionError, "api.option('od2.opt2').value.get()")
|
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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val2.val2').value.get() == ['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])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
|
|
|
assert api.option('val2.val2').value.get() == ['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),)})
|
2017-10-14 13:33:25 +02:00
|
|
|
stm = MasterSlaves('st1', '', [st1, st2])
|
|
|
|
#stm.impl_set_group_type(groups.master)
|
2014-06-19 23:22:39 +02:00
|
|
|
st = OptionDescription('st', '', [stm])
|
|
|
|
od = OptionDescription('od', '', [st])
|
|
|
|
od2 = OptionDescription('od', '', [od])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(od2))
|
|
|
|
owner = api.owner.get()
|
|
|
|
assert api.option('od.st.st1.st1').value.get() == []
|
|
|
|
assert api.option('od.st.st1.st1').owner.isdefault()
|
2014-06-19 23:22:39 +02:00
|
|
|
##
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od.st.st1.st1').value.set(['yes'])
|
|
|
|
api.option('od.st.st1.st2', 0).value.set('yes')
|
|
|
|
assert api.option('od.st.st1.st1').owner.get() == owner
|
|
|
|
assert api.option('od.st.st1.st2', 0).owner.get() == owner
|
2015-11-24 10:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_re_set_callback():
|
|
|
|
st1 = StrOption('st1', "", multi=True)
|
|
|
|
st2 = StrOption('st2', "", multi=True)
|
|
|
|
st2.impl_set_callback(return_value, {'': ((st1, False),)})
|
|
|
|
raises(ConfigError, "st2.impl_set_callback(return_value, {'': ((st1, False),)})")
|
2017-02-11 18:11:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_callback_raise():
|
|
|
|
opt1 = BoolOption('opt1', 'Option 1', callback=return_raise)
|
|
|
|
opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror)
|
|
|
|
od1 = OptionDescription('od1', '', [opt1])
|
|
|
|
od2 = OptionDescription('od2', '', [opt2])
|
|
|
|
maconfig = OptionDescription('rootconfig', '', [od1, od2])
|
2018-03-19 08:33:53 +01:00
|
|
|
api = getapi(Config(maconfig))
|
|
|
|
api.property.read_write()
|
2017-02-11 18:11:05 +01:00
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od1.opt1').value.get()
|
2017-07-09 09:49:03 +02:00
|
|
|
except ConfigError as err:
|
2017-02-11 18:11:05 +01:00
|
|
|
assert '"Option 1"' in str(err)
|
|
|
|
try:
|
2018-03-19 08:33:53 +01:00
|
|
|
api.option('od2.opt2').value.get()
|
2017-07-09 09:49:03 +02:00
|
|
|
except ConfigError as err:
|
2017-02-11 18:11:05 +01:00
|
|
|
assert '"Option 2"' in str(err)
|