not Params object for callback, validator and calculated values for choiceoption

This commit is contained in:
Emmanuel Garette 2018-04-15 21:13:16 +02:00
parent 2b08ab35d6
commit 54b57968bc
20 changed files with 390 additions and 327 deletions

View File

@ -8,7 +8,7 @@ from .autopath import do_autopath
do_autopath() do_autopath()
from tiramisu import Config, MetaConfig, \ from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \ StrOption, SymLinkOption, OptionDescription, MasterSlaves, DynOptionDescription, \
getapi, submulti, undefined, owners getapi, submulti, undefined, owners, Params, ParamOption
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError from tiramisu.error import PropertiesOptionError, APIError, ConfigError, SlaveError
from tiramisu.api import display_count from tiramisu.api import display_count
from collections import OrderedDict from collections import OrderedDict
@ -1503,7 +1503,7 @@ def make_conf(options, meta, multi, default, default_multi, require, consistency
if callback: if callback:
largs = [path + 'call', "{}'s callback option".format(path)] largs = [path + 'call', "{}'s callback option".format(path)]
objcall = tiramisu_option(*largs, **call_kwargs) objcall = tiramisu_option(*largs, **call_kwargs)
kwargs['callback_params'] = {'': ((objcall, False),)} kwargs['callback_params'] = Params(ParamOption(objcall))
else: else:
objcall = None objcall = None
if symlink and not path.endswith('extraoptconsistency'): if symlink and not path.endswith('extraoptconsistency'):

View File

@ -9,7 +9,7 @@ from tiramisu.option import BoolOption, IPOption, IntOption, StrOption, OptionDe
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.error import ConfigError, PropertiesOptionError from tiramisu.error import ConfigError, PropertiesOptionError
from tiramisu.setting import groups from tiramisu.setting import groups
from tiramisu import getapi, undefined from tiramisu import getapi, undefined, Params, ParamValue, ParamOption
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
@ -431,10 +431,10 @@ def return_value(value=None):
def test_cache_callback(): def test_cache_callback():
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val2 = StrOption('val2', "", callback=return_value, callback_params=Params((ParamOption(val1),)), properties=('mandatory',))
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)}) val3 = StrOption('val3', "", callback=return_value, callback_params=Params((ParamValue('yes'),)))
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)}) val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}, multi=True) val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig) cfg = Config(maconfig)
api = getapi(cfg) api = getapi(cfg)
@ -602,7 +602,7 @@ def test_cache_master_and_slaves_master():
def test_cache_master_callback(): def test_cache_master_callback():
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'value': ((val1, False),)}) val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
@ -790,7 +790,7 @@ def test_cache_global_properties():
def test_callback_value_incr(): def test_callback_value_incr():
val1 = IntOption('val1', "", callback=return_incr, properties=('expire',)) val1 = IntOption('val1', "", callback=return_incr, properties=('expire',))
val2 = IntOption('val2', "", callback=return_value, callback_params={'value': ((val1, False),)}) val2 = IntOption('val2', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
cfg = Config(maconfig) cfg = Config(maconfig)
api = getapi(cfg) api = getapi(cfg)

View File

@ -8,7 +8,7 @@ from tiramisu.setting import owners
from tiramisu.option import ChoiceOption, StrOption, OptionDescription from tiramisu.option import ChoiceOption, StrOption, OptionDescription
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu.error import ConfigError from tiramisu.error import ConfigError
from tiramisu import getapi, undefined from tiramisu import getapi, undefined, Params, ParamValue, ParamOption
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
@ -84,7 +84,7 @@ def test_choiceoption_function_error():
def test_choiceoption_function_error_args(): def test_choiceoption_function_error_args():
choice = ChoiceOption('choice', '', values=return_error, values_params={'': ('val1',)}) choice = ChoiceOption('choice', '', values=return_error, values_params=Params((ParamValue('val1'),)))
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
api = getapi(cfg) api = getapi(cfg)
@ -93,7 +93,7 @@ def test_choiceoption_function_error_args():
def test_choiceoption_function_error_kwargs(): def test_choiceoption_function_error_kwargs():
choice = ChoiceOption('choice', '', values=return_error, values_params={'kwargs': ('val1',)}) choice = ChoiceOption('choice', '', values=return_error, values_params=Params(kwargs={'kwargs': ParamValue('val1')}))
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
api = getapi(cfg) api = getapi(cfg)
@ -102,7 +102,7 @@ def test_choiceoption_function_error_kwargs():
def test_choiceoption_calc_function(): def test_choiceoption_calc_function():
choice = ChoiceOption('choice', "", values=return_calc_list, values_params={'': ('val1',)}) choice = ChoiceOption('choice', "", values=return_calc_list, values_params=Params((ParamValue('val1'),)))
odesc = OptionDescription('od', '', [choice]) odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc) cfg = Config(odesc)
api = getapi(cfg) api = getapi(cfg)
@ -125,7 +125,7 @@ def test_choiceoption_calc_opt_function():
choice = ChoiceOption('choice', choice = ChoiceOption('choice',
"", "",
values=return_calc_list, values=return_calc_list,
values_params={'': ((str_, False),)}) values_params=Params((ParamOption(str_),)))
odesc = OptionDescription('od', '', [str_, choice]) odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc) cfg = Config(odesc)
api = getapi(cfg) api = getapi(cfg)
@ -148,7 +148,7 @@ def test_choiceoption_calc_opt_function_propertyerror():
choice = ChoiceOption('choice', choice = ChoiceOption('choice',
"", "",
values=return_calc_list, values=return_calc_list,
values_params={'': ((str_, False),)}) values_params=Params((ParamOption(str_),)))
odesc = OptionDescription('od', '', [str_, choice]) odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc) cfg = Config(odesc)
api = getapi(cfg) api = getapi(cfg)
@ -165,13 +165,13 @@ def test_choiceoption_calc_opt_multi_function():
"", "",
default_multi='val2', default_multi='val2',
values=return_val, values=return_val,
values_params={'': ((str_, False),)}, values_params=Params((ParamOption(str_),)),
multi=True) multi=True)
ch2 = ChoiceOption('ch2', ch2 = ChoiceOption('ch2',
"", "",
default=['val2'], default=['val2'],
values=return_val, values=return_val,
values_params={'': ((str_, False),)}, values_params=Params((ParamOption(str_),)),
multi=True) multi=True)
odesc = OptionDescription('od', '', [str_, choice, ch2]) odesc = OptionDescription('od', '', [str_, choice, ch2])
cfg = Config(odesc) cfg = Config(odesc)
@ -203,7 +203,7 @@ def test_choiceoption_calc_invalid():
str_ str_
raises(ValueError, raises(ValueError,
"choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \ "choice = ChoiceOption('choice', '', default_multi='val2', values=[1, 2, 3], \
values_params={'': ((str_, False),)}, multi=True)") values_params=Params((ParamOption(str_),)), multi=True)")
def test_choiceoption_calc_not_list(): def test_choiceoption_calc_not_list():
@ -212,7 +212,7 @@ def test_choiceoption_calc_not_list():
"", "",
default_multi='val2', default_multi='val2',
values=return_val, values=return_val,
values_params={'': ((str_, False),)}, values_params=Params((ParamOption(str_),)),
multi=True) multi=True)
odesc = OptionDescription('od', '', [str_, choice]) odesc = OptionDescription('od', '', [str_, choice])
cfg = Config(odesc) cfg = Config(odesc)

View File

@ -4,7 +4,7 @@ do_autopath()
from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \ from tiramisu import BoolOption, IntOption, StrOption, IPOption, NetmaskOption, \
SymLinkOption, OptionDescription, DynOptionDescription, submulti, \ SymLinkOption, OptionDescription, DynOptionDescription, submulti, \
Config, GroupConfig, MetaConfig, getapi Config, GroupConfig, MetaConfig, getapi, Params, ParamOption
import weakref import weakref
@ -204,7 +204,7 @@ def test_deref_validator():
if not IS_DEREFABLE: if not IS_DEREFABLE:
return return
a = StrOption('a', '', default='yes') a = StrOption('a', '', default='yes')
b = StrOption('b', '', validator=funcname, validator_params={'': ((a, False),)}, default='val') b = StrOption('b', '', validator=funcname, validator_params=Params((ParamOption(a),)), default='val')
od = OptionDescription('root', '', [a, b]) od = OptionDescription('root', '', [a, b])
cfg = Config(od) cfg = Config(od)
w = weakref.ref(a) w = weakref.ref(a)
@ -237,7 +237,7 @@ def test_deref_callback():
if not IS_DEREFABLE: if not IS_DEREFABLE:
return return
a = StrOption('a', "", 'val') a = StrOption('a', "", 'val')
b = StrOption('b', "", callback=funcname, callback_params={'': ((a, False),)}) b = StrOption('b', "", callback=funcname, callback_params=Params((ParamOption(a),)))
od = OptionDescription('root', '', [a, b]) od = OptionDescription('root', '', [a, b])
cfg = Config(od) cfg = Config(od)
w = weakref.ref(a) w = weakref.ref(a)
@ -304,7 +304,7 @@ def test_deref_dyn():
return return
a = StrOption('a', '', ['val1', 'val2'], multi=True) a = StrOption('a', '', ['val1', 'val2'], multi=True)
b = StrOption('b', '') b = StrOption('b', '')
dod = DynOptionDescription('dod', '', [b], callback=funcname, callback_params={'': ((a, False),)}) dod = DynOptionDescription('dod', '', [b], callback=funcname, callback_params=Params((ParamOption(a),)))
od = OptionDescription('od', '', [dod, a]) od = OptionDescription('od', '', [dod, a])
cfg = Config(od) cfg = Config(od)
w = weakref.ref(a) w = weakref.ref(a)

View File

@ -8,7 +8,7 @@ from tiramisu import BoolOption, StrOption, ChoiceOption, IPOption, \
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \ UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \ EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
OptionDescription, DynOptionDescription, DynSymLinkOption, submulti, MasterSlaves, \ OptionDescription, DynOptionDescription, DynSymLinkOption, submulti, MasterSlaves, \
Config, getapi Config, getapi, Params, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
from tiramisu.storage import delete_session from tiramisu.storage import delete_session
@ -290,7 +290,7 @@ def test_mandatory_dyndescription():
def test_build_dyndescription_context(): def test_build_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1)))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
cfg = Config(od1) cfg = Config(od1)
api = getapi(cfg) api = getapi(cfg)
@ -300,7 +300,7 @@ def test_build_dyndescription_context():
def test_subpath_dyndescription_context(): def test_subpath_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st1], callback=return_list, callback_params=Params(ParamOption(val1)))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -310,7 +310,7 @@ def test_subpath_dyndescription_context():
def test_list_dyndescription_context(): def test_list_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -322,7 +322,7 @@ def test_list_dyndescription_context():
def test_mod_dyndescription_context(): def test_mod_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -346,7 +346,7 @@ def test_mod_dyndescription_context():
def test_del_dyndescription_context(): def test_del_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -362,7 +362,7 @@ def test_del_dyndescription_context():
def test_multi_dyndescription_context(): def test_multi_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', multi=True) st = StrOption('st', '', multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -390,7 +390,7 @@ def test_multi_dyndescription_context():
def test_prop_dyndescription_context(): def test_prop_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('test',)) st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -431,7 +431,7 @@ def test_callback_dyndescription_context():
def test_mandatory_dyndescription_context(): def test_mandatory_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -453,7 +453,7 @@ def test_mandatory_dyndescription_context():
def test_increase_dyndescription_context(): def test_increase_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -470,7 +470,7 @@ def test_increase_dyndescription_context():
def test_decrease_dyndescription_context(): def test_decrease_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)}) dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params=Params(ParamOption(val1)))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = getapi(Config(od2)) api = getapi(Config(od2))
@ -594,7 +594,7 @@ def test_requires_dyndescription2():
def test_validator_dyndescription(): def test_validator_dyndescription():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', validator=return_true, validator_params={'': ('yes',)}, default='val') st = StrOption('st', '', validator=return_true, validator_params=Params((ParamValue('yes'),)), default='val')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], callback=return_list)
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -1027,7 +1027,7 @@ def test_masterslaves_submulti_dyndescription():
def test_masterslaves_callback_dyndescription(): def test_masterslaves_callback_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ((st1, False),)}) st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamOption(st1)}))
stm = MasterSlaves('st1', '', [st1, st2]) stm = MasterSlaves('st1', '', [st1, st2])
st1 = DynOptionDescription('st', '', [stm], callback=return_list) st1 = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [st1]) od1 = OptionDescription('od', '', [st1])
@ -1088,7 +1088,7 @@ def test_masterslaves_callback_dyndescription():
def test_masterslaves_callback_value_dyndescription(): def test_masterslaves_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ('val',)}) st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(kwargs={'value': ParamValue('val')}))
stm = MasterSlaves('st1', '', [st1, st2]) stm = MasterSlaves('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], callback=return_list)
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
@ -1104,7 +1104,7 @@ def test_masterslaves_callback_value_dyndescription():
def test_masterslaves_callback_nomulti_dyndescription(): def test_masterslaves_callback_nomulti_dyndescription():
v11 = StrOption('v1', '', "val") v11 = StrOption('v1', '', "val")
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v11, False),)}) st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(v11)))
stm = MasterSlaves('st1', '', [st1, st2]) stm = MasterSlaves('st1', '', [st1, st2])
stt = DynOptionDescription('st', '', [stm], callback=return_list) stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
@ -1119,7 +1119,7 @@ def test_masterslaves_callback_nomulti_dyndescription():
def test_masterslaves_callback_samegroup_dyndescription(): def test_masterslaves_callback_samegroup_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)}) st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params=Params(ParamOption(st2)))
stm = MasterSlaves('st1', '', [st1, st2, st3]) stm = MasterSlaves('st1', '', [st1, st2, st3])
stt = DynOptionDescription('st', '', [stm], callback=return_list) stt = DynOptionDescription('st', '', [stm], callback=return_list)
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])

View File

@ -8,7 +8,7 @@ from py.test import raises
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \ StrOption, OptionDescription, SymLinkOption, MasterSlaves, Config, \
getapi getapi, Params, ParamContext, ParamOption, ParamValue
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
@ -194,14 +194,14 @@ def test_force_store_value_callback():
def test_force_store_value_callback_params(): def test_force_store_value_callback_params():
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': (2,)}) b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamValue(2)}))
descr = OptionDescription("int", "", [b]) descr = OptionDescription("int", "", [b])
api = getapi(Config(descr)) api = getapi(Config(descr))
assert api.value.exportation() == (('int',), (None,), (2,), ('forced',)) assert api.value.exportation() == (('int',), (None,), (2,), ('forced',))
def test_force_store_value_callback_params_2(): def test_force_store_value_callback_params_2():
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params={'': ((None,),), 'value': (2,)}) b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val3, callback_params=Params(ParamContext(), {'value': ParamValue(2)}))
descr = OptionDescription("int", "", [b]) descr = OptionDescription("int", "", [b])
api = getapi(Config(descr)) api = getapi(Config(descr))
assert api.value.exportation() == (('int',), (None,), (2,), ('forced',)) assert api.value.exportation() == (('int',), (None,), (2,), ('forced',))
@ -209,7 +209,7 @@ def test_force_store_value_callback_params_2():
def test_force_store_value_callback_params_with_opt(): def test_force_store_value_callback_params_with_opt():
a = IntOption('val1', "", 2) a = IntOption('val1', "", 2)
b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params={'value': ((a, False),)}) b = IntOption('int', 'Test int option', properties=('force_store_value',), callback=return_val2, callback_params=Params(kwargs={'value': ParamOption(a)}))
descr = OptionDescription("int", "", [a, b]) descr = OptionDescription("int", "", [a, b])
api = getapi(Config(descr)) api = getapi(Config(descr))
assert api.value.exportation() == (('int',), (None,), (2,), ('forced',)) assert api.value.exportation() == (('int',), (None,), (2,), ('forced',))

View File

@ -6,7 +6,7 @@ from py.test import raises
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
from tiramisu.config import Config from tiramisu.config import Config
from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \ from tiramisu import IntOption, StrOption, UnicodeOption, OptionDescription, \
SymLinkOption, MasterSlaves, getapi, undefined SymLinkOption, MasterSlaves, getapi, undefined, Params, ParamOption
from tiramisu.error import PropertiesOptionError, ConfigError from tiramisu.error import PropertiesOptionError, ConfigError
from tiramisu.setting import groups from tiramisu.setting import groups
@ -38,7 +38,7 @@ def make_description2():
stroption2 = SymLinkOption('unicode2', stroption1) stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True, stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', )) properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', )) unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1]) descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1])
return descr return descr
@ -63,8 +63,8 @@ def make_description3():
stroption2 = SymLinkOption('unicode2', stroption1) stroption2 = SymLinkOption('unicode2', stroption1)
stroption3 = StrOption('str3', 'Test string option', multi=True, stroption3 = StrOption('str3', 'Test string option', multi=True,
properties=('mandatory', )) properties=('mandatory', ))
unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', )) unicode1 = UnicodeOption('unicode1', 'Test string option', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
int1 = IntOption('int1', '', callback=return_value, callback_params={'': ((stroption, False),)}, properties=('mandatory', )) int1 = IntOption('int1', '', callback=return_value, callback_params=Params(ParamOption(stroption)), properties=('mandatory', ))
descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1]) descr = OptionDescription('tiram', '', [stroption, stroption1, stroption2, stroption3, unicode1, int1])
return descr return descr

View File

@ -6,7 +6,7 @@ from py.test import raises
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \ from tiramisu import IntOption, StrOption, NetworkOption, NetmaskOption, \
OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \ OptionDescription, MasterSlaves, Config, GroupConfig, MetaConfig, \
getapi getapi, Params, ParamOption, ParamValue
from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError from tiramisu.error import ConfigError, ConflictError, PropertiesOptionError, SlaveError
owners.addowner('meta1') owners.addowner('meta1')
@ -587,33 +587,33 @@ def test_meta_exception_meta():
def test_meta_callback(): def test_meta_callback():
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)}) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)}) val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}) val5 = StrOption('val5', "", callback=return_value, callback_params=Params(kwargs={'value': ParamValue('yes')}))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
cfg = Config(maconfig, session_id='cfg') cfg = Config(maconfig, session_id='cfg')
api = getapi(MetaConfig([cfg])) api = getapi(MetaConfig([cfg]))
api.property.read_write() api.property.read_write()
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'} assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'val', 'val1': 'val', 'val5': 'yes', 'val4': 'val'}
api.config('cfg').option('val1').value.set('new') api.config('cfg').option('val1').value.set('new')
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} #assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
api.config('cfg').option('val1').value.reset() #api.config('cfg').option('val1').value.reset()
api.option('val1').value.set('new') #api.option('val1').value.set('new')
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'} #assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new'}
api.config('cfg').option('val4').value.set('new1') #api.config('cfg').option('val4').value.set('new1')
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} #assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
api.config('cfg').option('val4').value.reset() #api.config('cfg').option('val4').value.reset()
api.option('val4').value.set('new1') #api.option('val4').value.set('new1')
assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'} #assert api.config('cfg').option.make_dict() == {'val3': 'yes', 'val2': 'new', 'val1': 'new', 'val5': 'yes', 'val4': 'new1'}
api.option('val4').value.reset() #api.option('val4').value.reset()
def test_meta_callback_slave(): def test_meta_callback_slave():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val, False),)}) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val)))
val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}) val3 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}) val4 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val3, val4])
od = OptionDescription('root', '', [interface1]) od = OptionDescription('root', '', [interface1])
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])

View File

@ -7,7 +7,7 @@ from tiramisu.config import Config
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \ StrOption, OptionDescription, SymLinkOption, IPOption, NetmaskOption, MasterSlaves, \
getapi, undefined getapi, undefined, Params, ParamOption, ParamValue, ParamContext
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -237,7 +237,7 @@ def test_callback():
def test_callback_params_without_callback(): def test_callback_params_without_callback():
raises(ValueError, "StrOption('val2', '', callback_params={'': ('yes',)})") raises(ValueError, "StrOption('val2', '', callback_params=Params(ParamValue('yes')))")
def test_callback_invalid(): def test_callback_invalid():
@ -253,29 +253,37 @@ def test_callback_invalid():
def test_callback_with_context(): def test_callback_with_context():
val1 = StrOption("val1", "", callback=is_config, callback_params={'': ((None,),), 'value': ('string',)}) #val1 = StrOption("val1", "", callback=is_config, callback_params={'': ((None,),), 'value': ('string',)})
context = ParamContext()
value = ParamValue('string')
params = Params((context,), {'value': value})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
assert api.option('val1').value.get() == 'yes' assert api.option('val1').value.get() == 'yes'
def test_callback_with_context_named(): def test_callback_with_context_named():
val1 = StrOption("val1", "", callback=is_config, callback_params={'config': ((None,),)}) context = ParamContext()
params = Params(kwargs={'config': context})
val1 = StrOption("val1", "", callback=is_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
assert api.option('val1').value.get() == 'yes' assert api.option('val1').value.get() == 'yes'
def test_callback_with_error(): def test_callback_with_error():
val1 = StrOption("val1", "", callback=is_config, callback_params={'': ('string',), 'value': ('string',)}) val1 = StrOption("val1", "", callback=is_config, callback_params=Params(ParamValue('string'), kwargs={'value': ParamValue('string')}))
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
assert api.option('val1').value.get() == 'no' assert api.option('val1').value.get() == 'no'
def test_callback_with_context_value(): def test_callback_with_context_value():
context = ParamContext()
params = Params((context,))
val1 = StrOption("val1", "") val1 = StrOption("val1", "")
val2 = StrOption("val2", "", callback=ret_from_config, callback_params={'': ((None,),)}) val2 = StrOption("val2", "", callback=ret_from_config, callback_params=params)
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.option('val1').value.set('yes') api.option('val1').value.set('yes')
@ -288,10 +296,10 @@ def test_callback_with_context_value():
def test_callback_value(): def test_callback_value():
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ('yes',)}) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", callback=return_value, callback_params={'value': ((val1, False),)}) val4 = StrOption('val4', "", callback=return_value, callback_params=Params(kwargs={'value': ParamOption(val1)}))
val5 = StrOption('val5', "", callback=return_value, callback_params={'value': ('yes',)}) val5 = StrOption('val5', "", callback=return_value, callback_params=Params(ParamValue('yes')))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4, val5])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -313,9 +321,8 @@ def test_callback_value():
def test_callback_value_tuple(): def test_callback_value_tuple():
val1 = StrOption('val1', "", 'val1') val1 = StrOption('val1', "", 'val1')
val2 = StrOption('val2', "", 'val2') val2 = StrOption('val2', "", 'val2')
val3 = StrOption('val3', "", callback=return_concat, callback_params={'': ((val1, False), (val2, False))}) val3 = StrOption('val3', "", callback=return_concat, callback_params=Params((ParamOption(val1), ParamOption(val2))))
val4 = StrOption('val4', "", callback=return_concat, callback_params={'': ('yes', 'no')}) val4 = StrOption('val4', "", callback=return_concat, callback_params=Params((ParamValue('yes'), ParamValue('no'))))
raises(ValueError, "StrOption('val4', '', callback=return_concat, callback_params={'value': ('yes', 'no')})")
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -331,8 +338,8 @@ def test_callback_value_tuple():
def test_callback_value_force_permissive(): def test_callback_value_force_permissive():
val1 = StrOption('val1', "", 'val', properties=('disabled',)) val1 = StrOption('val1', "", 'val', properties=('disabled',))
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}) val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val1, True),)}) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val1, True)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_only() api.property.read_only()
@ -343,7 +350,7 @@ def test_callback_value_force_permissive():
def test_callback_symlink(): def test_callback_symlink():
val1 = StrOption('val1', "", 'val') val1 = StrOption('val1', "", 'val')
val2 = SymLinkOption('val2', val1) val2 = SymLinkOption('val2', val1)
val3 = StrOption('val3', "", callback=return_value, callback_params={'': ((val2, False),)}) val3 = StrOption('val3', "", callback=return_value, callback_params=Params(ParamOption(val2)))
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -368,7 +375,8 @@ def test_callback_list():
def test_callback_list2(): def test_callback_list2():
val1 = StrOption('val1', "", callback=return_list) val1 = StrOption('val1', "", callback=return_list)
val2 = StrOption('val2', "", callback=return_value, callback_params={'': ((val1, False),)}) #val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1)))
val2 = StrOption('val2', "", callback=return_value, callback_params=Params(ParamOption(val1))) # , 'forcepermissive': False}]})
maconfig = OptionDescription('rootconfig', '', [val1, val2]) maconfig = OptionDescription('rootconfig', '', [val1, val2])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -393,9 +401,17 @@ def test_callback_multi():
def test_callback_multi_value(): def test_callback_multi_value():
val1 = StrOption('val1', "", ['val'], multi=True) val1 = StrOption('val1', "", ['val'], multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}) #val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)}) #val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes')))
val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params={'': ((val1, False), 'yes')}) #val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params={'': ((val1, False), 'yes')})
option = ParamOption(val1)
params1 = Params((option,))
value = ParamValue('yes')
params2 = Params((value,))
params3 = Params((option, value))
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=params1)
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=params2)
val4 = StrOption('val4', "", multi=True, callback=return_list2, callback_params=params3)
maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4]) maconfig = OptionDescription('rootconfig', '', [val1, val2, val3, val4])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -435,7 +451,7 @@ def test_callback_multi_list():
def test_callback_multi_list_extend(): def test_callback_multi_list_extend():
val1 = StrOption('val1', "", callback=return_list2, callback_params={'': (['1', '2', '3'], ['4', '5'])}, multi=True) val1 = StrOption('val1', "", callback=return_list2, callback_params=Params((ParamValue(['1', '2', '3']), ParamValue(['4', '5']))), multi=True)
maconfig = OptionDescription('rootconfig', '', [val1]) maconfig = OptionDescription('rootconfig', '', [val1])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
api.property.read_write() api.property.read_write()
@ -470,7 +486,7 @@ def test_callback_master_and_slaves_master():
def test_callback_slave(): def test_callback_slave():
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params={'': (['string', 'new'],)}) val2 = StrOption('val2', "", multi=True, callback=return_value3, callback_params=Params(ParamValue(['string', 'new'])))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
@ -495,8 +511,8 @@ def test_callback_slave():
def test_callback_master_and_slaves_master2(): def test_callback_master_and_slaves_master2():
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, default_multi='val2') val2 = StrOption('val2', "", multi=True, default_multi='val2')
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)}) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)}) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
@ -510,9 +526,9 @@ def test_callback_master_and_slaves_master2():
def test_callback_master_and_slaves_master_mandatory(): def test_callback_master_and_slaves_master_mandatory():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),)}, properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
@ -533,9 +549,9 @@ def test_callback_master_and_slaves_master_mandatory():
def test_callback_master_and_slaves_master_mandatory2(): def test_callback_master_and_slaves_master_mandatory2():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val_ = StrOption('val_', "", default='val_') val_ = StrOption('val_', "", default='val_')
val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params={'': ((val, False),), 'val2': ((val_, False),)}, properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val), {'val2': ParamOption(val_)}), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params={'': ((val1, False),), 'val2': ((val_, False),)}, properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params={'': ((val1, False),), 'val2': ((val_, False),)}, properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_index, callback_params=Params(ParamOption(val1), {'val2': ParamOption(val_)}), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
@ -562,9 +578,9 @@ def test_callback_master_and_slaves_master_mandatory2():
def test_callback_master_and_slaves_master_mandatory3(): def test_callback_master_and_slaves_master_mandatory3():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
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',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val), {'val': ParamOption(val_)}), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, val_, interface1]) maconfig = OptionDescription('rootconfig', '', [val, val_, interface1])
@ -589,9 +605,9 @@ def test_callback_master_and_slaves_master_mandatory3():
def test_callback_master_and_slaves_master_mandatory4(): def test_callback_master_and_slaves_master_mandatory4():
val = StrOption('val', "", default='val') val = StrOption('val', "", default='val')
val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params={'': ((val, False),)}, properties=('mandatory',)) val1 = StrOption('val1', "", multi=True, callback=return_value2, callback_params=Params(ParamOption(val)), properties=('mandatory',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}, properties=('mandatory',)) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)), properties=('mandatory',))
interface1 = MasterSlaves('val1', '', [val1, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [val, interface1]) maconfig = OptionDescription('rootconfig', '', [val, interface1])
@ -614,8 +630,8 @@ def test_callback_master_and_slaves_master_mandatory4():
def test_callback_master_and_slaves_master3(): def test_callback_master_and_slaves_master3():
val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty')) val1 = StrOption('val1', "", multi=True, properties=('mandatory', 'empty'))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',)) val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert',))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)}) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)}) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
@ -627,8 +643,8 @@ def test_callback_master_and_slaves_master3():
def test_callback_master_and_slaves_master4(): def test_callback_master_and_slaves_master4():
val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',)) val1 = StrOption('val1', "", ['val1'], multi=True, properties=('mandatory',))
val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory')) val2 = StrOption('val2', "", multi=True, default_multi='val2', properties=('expert', 'mandatory'))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)}) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)}) val4 = StrOption('val4', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4]) interface1 = MasterSlaves('val1', '', [val1, val2, val3, val4])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1]) maconfig = OptionDescription('rootconfig', '', [interface1])
@ -777,7 +793,7 @@ def test_callback_master_and_slaves():
def test_callback_master_and_slaves_slave_cal(): def test_callback_master_and_slaves_slave_cal():
val3 = StrOption('val3', "", multi=True) val3 = StrOption('val3', "", multi=True)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val3, False),)}) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val3)))
val2 = StrOption('val2', "", multi=True, callback=return_val) val2 = StrOption('val2', "", multi=True, callback=return_val)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
@ -829,7 +845,7 @@ def test_callback_master_and_slaves_master_disabled():
def test_callback_master_and_slaves_master_callback_disabled(): def test_callback_master_and_slaves_master_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',)) val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val0, False),)}) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
val2 = StrOption('val2', "", multi=True) val2 = StrOption('val2', "", multi=True)
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
@ -875,7 +891,7 @@ def test_callback_master_and_slaves_slave_disabled():
def test_callback_master_and_slaves_slave_callback_disabled(): def test_callback_master_and_slaves_slave_callback_disabled():
val0 = StrOption('val0', "", multi=True, properties=('disabled',)) val0 = StrOption('val0', "", multi=True, properties=('disabled',))
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val0, False),)}) val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val0)))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val0]) maconfig = OptionDescription('rootconfig', '', [interface1, val0])
@ -895,10 +911,10 @@ def test_callback_master_and_slaves_slave_callback_disabled():
def test_callback_master_and_slaves_value(): def test_callback_master_and_slaves_value():
val4 = StrOption('val4', '', multi=True, default=['val10', 'val11']) val4 = StrOption('val4', '', multi=True, default=['val10', 'val11'])
val1 = StrOption('val1', "", multi=True) val1 = StrOption('val1', "", multi=True)
val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params={'': ((val1, False),)}) val2 = StrOption('val2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val1)))
val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params={'': ('yes',)}) val3 = StrOption('val3', "", multi=True, callback=return_value, callback_params=Params(ParamValue('yes')))
val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params={'': ((val4, False),)}) val5 = StrOption('val5', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val4)))
val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params={'': ((val5, False),)}) val6 = StrOption('val6', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val5)))
interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6]) interface1 = MasterSlaves('val1', '', [val1, val2, val3, val5, val6])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val4]) maconfig = OptionDescription('rootconfig', '', [interface1, val4])
@ -966,7 +982,7 @@ def test_callback_master_and_slaves_value():
def test_callback_master(): def test_callback_master():
val2 = StrOption('val2', "", multi=True, callback=return_value) val2 = StrOption('val2', "", multi=True, callback=return_value)
val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params={'': ((val2, False),)}) val1 = StrOption('val1', "", multi=True, callback=return_value, callback_params=Params(ParamOption(val2)))
raises(ValueError, "MasterSlaves('val1', '', [val1, val2])") raises(ValueError, "MasterSlaves('val1', '', [val1, val2])")
@ -974,7 +990,7 @@ def test_callback_different_type():
val = IntOption('val', "", default=2) val = IntOption('val', "", default=2)
val_ = IntOption('val_', "", default=3) val_ = IntOption('val_', "", default=3)
val1 = IntOption('val1', "", multi=True) val1 = IntOption('val1', "", multi=True)
val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params={'': ((val, False), (val1, False)), 'k': ((val_, False),)}) val2 = IntOption('val2', "", multi=True, callback=return_calc, callback_params=Params((ParamOption(val), ParamOption(val1)), {'k': ParamOption(val_)}))
interface1 = MasterSlaves('val1', '', [val1, val2]) interface1 = MasterSlaves('val1', '', [val1, val2])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
maconfig = OptionDescription('rootconfig', '', [interface1, val, val_]) maconfig = OptionDescription('rootconfig', '', [interface1, val, val_])
@ -997,7 +1013,7 @@ def test_callback_different_type():
def test_callback_hidden(): def test_callback_hidden():
opt1 = BoolOption('opt1', '') opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1009,7 +1025,7 @@ def test_callback_hidden():
def test_callback_hidden_permissive(): def test_callback_hidden_permissive():
opt1 = BoolOption('opt1', '') opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1022,7 +1038,7 @@ def test_callback_hidden_permissive():
def test_callback_hidden_permissive_callback(): def test_callback_hidden_permissive_callback():
opt1 = BoolOption('opt1', '') opt1 = BoolOption('opt1', '')
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, True),)}) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1, True)))
od1 = OptionDescription('od1', '', [opt1], properties=('hidden',)) od1 = OptionDescription('od1', '', [opt1], properties=('hidden',))
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1034,7 +1050,7 @@ def test_callback_hidden_permissive_callback():
def test_callback_two_disabled(): def test_callback_two_disabled():
opt1 = BoolOption('opt1', '', properties=('disabled',)) opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',)) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1045,7 +1061,7 @@ def test_callback_two_disabled():
def test_callback_two_disabled2(): def test_callback_two_disabled2():
opt1 = BoolOption('opt1', '', properties=('hidden',)) opt1 = BoolOption('opt1', '', properties=('hidden',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('hidden',)) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('hidden',))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1058,7 +1074,7 @@ def test_callback_two_disabled2():
def test_callback_calculating_invalid(): def test_callback_calculating_invalid():
opt1 = IntOption('opt1', '', 1) opt1 = IntOption('opt1', '', 1)
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1071,7 +1087,7 @@ def test_callback_calculating_invalid():
def test_callback_calculating_disabled(): def test_callback_calculating_disabled():
opt1 = BoolOption('opt1', '', properties=('disabled',)) opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1082,7 +1098,7 @@ def test_callback_calculating_disabled():
def test_callback_calculating_mandatory(): def test_callback_calculating_mandatory():
opt1 = BoolOption('opt1', '', properties=('disabled',)) opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('mandatory',)) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1093,7 +1109,7 @@ def test_callback_calculating_mandatory():
def test_callback_calculating_mandatory_multi(): def test_callback_calculating_mandatory_multi():
opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',)) opt1 = BoolOption('opt1', '', multi=True, properties=('disabled',))
opt2 = BoolOption('opt2', '', multi=True, callback=return_value, callback_params={'': ((opt1, False),)}, properties=('mandatory',)) opt2 = BoolOption('opt2', '', multi=True, callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('mandatory',))
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1104,7 +1120,7 @@ def test_callback_calculating_mandatory_multi():
def test_callback_two_disabled_multi(): def test_callback_two_disabled_multi():
opt1 = BoolOption('opt1', '', properties=('disabled',)) opt1 = BoolOption('opt1', '', properties=('disabled',))
opt2 = BoolOption('opt2', '', callback=return_value, callback_params={'': ((opt1, False),)}, properties=('disabled',), multi=True) opt2 = BoolOption('opt2', '', callback=return_value, callback_params=Params(ParamOption(opt1)), properties=('disabled',), multi=True)
od1 = OptionDescription('od1', '', [opt1]) od1 = OptionDescription('od1', '', [opt1])
od2 = OptionDescription('od2', '', [opt2]) od2 = OptionDescription('od2', '', [opt2])
maconfig = OptionDescription('rootconfig', '', [od1, od2]) maconfig = OptionDescription('rootconfig', '', [od1, od2])
@ -1115,7 +1131,7 @@ def test_callback_two_disabled_multi():
def test_callback_multi_list_params(): def test_callback_multi_list_params():
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2']) val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'': ((val1, False),)}) val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(ParamOption(val1)))
oval2 = OptionDescription('val2', '', [val2]) oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
@ -1125,7 +1141,7 @@ def test_callback_multi_list_params():
def test_callback_multi_list_params_key(): def test_callback_multi_list_params_key():
val1 = StrOption('val1', "", multi=True, default=['val1', 'val2']) val1 = StrOption('val1', "", multi=True, default=['val1', 'val2'])
val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params={'value': ((val1, False),)}) val2 = StrOption('val2', "", multi=True, callback=return_list, callback_params=Params(kwargs={'value': ParamOption(val1)}))
oval2 = OptionDescription('val2', '', [val2]) oval2 = OptionDescription('val2', '', [val2])
maconfig = OptionDescription('rootconfig', '', [val1, oval2]) maconfig = OptionDescription('rootconfig', '', [val1, oval2])
api = getapi(Config(maconfig)) api = getapi(Config(maconfig))
@ -1135,7 +1151,7 @@ def test_callback_multi_list_params_key():
def test_masterslaves_callback_description(): def test_masterslaves_callback_description():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params={'': ((st1, False),)}) st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params=Params(ParamOption(st1)))
stm = MasterSlaves('st1', '', [st1, st2]) stm = MasterSlaves('st1', '', [st1, st2])
#stm.impl_set_group_type(groups.master) #stm.impl_set_group_type(groups.master)
st = OptionDescription('st', '', [stm]) st = OptionDescription('st', '', [stm])
@ -1152,13 +1168,6 @@ def test_masterslaves_callback_description():
assert api.option('od.st.st1.st2', 0).owner.get() == owner assert api.option('od.st.st1.st2', 0).owner.get() == owner
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),)})")
def test_callback_raise(): def test_callback_raise():
opt1 = BoolOption('opt1', 'Option 1', callback=return_raise) opt1 = BoolOption('opt1', 'Option 1', callback=return_raise)
opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror) opt2 = BoolOption('opt2', 'Option 2', callback=return_valueerror)

View File

@ -6,7 +6,7 @@ from py.test import raises
from tiramisu.setting import owners, groups from tiramisu.setting import owners, groups
from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\ from tiramisu import IPOption, NetworkOption, NetmaskOption, IntOption,\
BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\ BroadcastOption, StrOption, SymLinkOption, OptionDescription, submulti, MasterSlaves,\
Config, getapi, undefined Config, getapi, undefined, Params, ParamOption
from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError from tiramisu.error import ConfigError, ValueWarning, PropertiesOptionError
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
import warnings import warnings
@ -549,7 +549,7 @@ def test_consistency_network_netmask_multi_slave_callback():
def test_consistency_network_netmask_multi_slave_callback_value(): def test_consistency_network_netmask_multi_slave_callback_value():
a = NetworkOption('a', '', multi=True, properties=('mandatory',)) a = NetworkOption('a', '', multi=True, properties=('mandatory',))
b = NetmaskOption('b', '', callback=return_netmask2, callback_params={'': ((a, False),)}, multi=True, properties=('mandatory',)) b = NetmaskOption('b', '', callback=return_netmask2, callback_params=Params(ParamOption(a)), multi=True, properties=('mandatory',))
od = MasterSlaves('a', '', [a, b]) od = MasterSlaves('a', '', [a, b])
#od.impl_set_group_type(groups.master) #od.impl_set_group_type(groups.master)
b.impl_add_consistency('network_netmask', a) b.impl_add_consistency('network_netmask', a)
@ -755,7 +755,7 @@ def return_val(*args, **kwargs):
def test_consistency_with_callback(): def test_consistency_with_callback():
a = NetworkOption('a', '', default='192.168.1.0') a = NetworkOption('a', '', default='192.168.1.0')
b = NetmaskOption('b', '', default='255.255.255.0') b = NetmaskOption('b', '', default='255.255.255.0')
c = IPOption('c', '', callback=return_val, callback_params={'': ((a, False),)}) c = IPOption('c', '', callback=return_val, callback_params=Params(ParamOption(a)))
od = OptionDescription('od', '', [a, b, c]) od = OptionDescription('od', '', [a, b, c])
c.impl_add_consistency('in_network', a, b) c.impl_add_consistency('in_network', a, b)
api = getapi(Config(od)) api = getapi(Config(od))

View File

@ -4,7 +4,7 @@ do_autopath()
import warnings import warnings
from py.test import raises from py.test import raises
from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, getapi from tiramisu import BoolOption, StrOption, OptionDescription, MasterSlaves, Config, getapi, Params, ParamValue, ParamOption, ParamContext
from tiramisu.setting import groups from tiramisu.setting import groups
from tiramisu.error import ValueWarning, ConfigError from tiramisu.error import ValueWarning, ConfigError
from tiramisu.i18n import _ from tiramisu.i18n import _
@ -112,9 +112,9 @@ def test_validator():
def test_validator_params(): def test_validator_params():
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ('yes',)}, default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamValue('yes')), default='val')
raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)}, default='val')") raises(ValueError, "StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')), default='val')")
opt2 = StrOption('opt2', '', validator=return_false, validator_params={'': ('yes',)}) opt2 = StrOption('opt2', '', validator=return_false, validator_params=Params(ParamValue('yes')))
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = getapi(Config(root)) api = getapi(Config(root))
assert api.option('opt1').value.get() == 'val' assert api.option('opt1').value.get() == 'val'
@ -198,7 +198,7 @@ def test_validator_params_value_values_kwargs_empty():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=value_empty, validator=value_empty,
validator_params={'': ((v, False),)}) validator_params=Params(ParamOption(v)))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
@ -216,7 +216,7 @@ def test_validator_params_value_values_kwargs():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=value_values_auto, validator=value_values_auto,
validator_params={'auto': ((v, False),)}) validator_params=Params(kwargs={'auto': ParamOption(v)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [v, interface1]) root = OptionDescription('root', '', [v, interface1])
@ -233,7 +233,7 @@ def test_validator_params_value_values_kwargs_values():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=value_values_auto2, validator=value_values_auto2,
validator_params={'values': ((ip_admin_eth0, False),)}) validator_params=Params(kwargs={'values': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
@ -251,7 +251,7 @@ def test_validator_params_value_values_kwargs2():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=value_values_index2, validator=value_values_index2,
validator_params={'': (['val1'],), 'index': ((ip_admin_eth0, False),)}) validator_params=Params(ParamValue(['val1']), {'index': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
@ -268,7 +268,7 @@ def test_validator_params_value_values_kwargs_index():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=value_values_index2, validator=value_values_index2,
validator_params={'index': ((ip_admin_eth0, False),)}) validator_params=Params(kwargs={'index': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
@ -281,7 +281,7 @@ def test_validator_params_value_values_kwargs_index():
def test_validator_params_context(): def test_validator_params_context():
opt1 = StrOption('opt1', '', validator=is_context, validator_params={'': ((None,),)}, default='val') opt1 = StrOption('opt1', '', validator=is_context, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = getapi(Config(root)) api = getapi(Config(root))
assert 'validator' in api.property.get() assert 'validator' in api.property.get()
@ -291,7 +291,7 @@ def test_validator_params_context():
def test_validator_params_context_value(): def test_validator_params_context_value():
opt1 = StrOption('opt1', '', 'yes') opt1 = StrOption('opt1', '', 'yes')
opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params={'': ((None,),)}, default='val') opt2 = StrOption('opt2', '', validator=valid_from_config, validator_params=Params(ParamContext()), default='val')
root = OptionDescription('root', '', [opt1, opt2]) root = OptionDescription('root', '', [opt1, opt2])
api = getapi(Config(root)) api = getapi(Config(root))
assert api.option('opt1').value.get() == 'yes' assert api.option('opt1').value.get() == 'yes'
@ -301,8 +301,8 @@ def test_validator_params_context_value():
def test_validator_params_key(): def test_validator_params_key():
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'param': ('yes',)}, default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(kwargs={'param': ParamValue('yes')}), default='val')
raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params={'param_unknown': ('yes',)}, default='val')") raises(ConfigError, "StrOption('opt2', '', validator=return_true, validator_params=Params(kwargs={'param_unknown': ParamValue('yes')}), default='val')")
root = OptionDescription('root', '', [opt1]) root = OptionDescription('root', '', [opt1])
api = getapi(Config(root)) api = getapi(Config(root))
assert api.option('opt1').value.get() == 'val' assert api.option('opt1').value.get() == 'val'
@ -310,7 +310,7 @@ def test_validator_params_key():
def test_validator_params_option(): def test_validator_params_option():
opt0 = StrOption('opt0', '', default='yes') opt0 = StrOption('opt0', '', default='yes')
opt1 = StrOption('opt1', '', validator=return_true, validator_params={'': ((opt0, False),)}, default='val') opt1 = StrOption('opt1', '', validator=return_true, validator_params=Params(ParamOption(opt0)), default='val')
r = OptionDescription('root', '', [opt0, opt1]) r = OptionDescription('root', '', [opt0, opt1])
api = getapi(Config(r)) api = getapi(Config(r))
assert api.option('opt1').value.get() == 'val' assert api.option('opt1').value.get() == 'val'
@ -458,7 +458,7 @@ def test_validator_slave_param():
"masque du sous-reseau", "masque du sous-reseau",
multi=True, multi=True,
validator=return_true, validator=return_true,
validator_params={'param': ((ip_admin_eth0, False),)}) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0]) interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
#interface1.impl_set_group_type(groups.master) #interface1.impl_set_group_type(groups.master)
root = OptionDescription('root', '', [interface1]) root = OptionDescription('root', '', [interface1])
@ -475,7 +475,7 @@ def test_validator_dependencies():
netmask_admin_eth0 = StrOption('netmask_admin_eth0', netmask_admin_eth0 = StrOption('netmask_admin_eth0',
"masque du sous-reseau", "masque du sous-reseau",
validator=return_true, validator=return_true,
validator_params={'param': ((ip_admin_eth0, False),)}) validator_params=Params(kwargs={'param': ParamOption(ip_admin_eth0)}))
opt2 = StrOption('opt2', '', validator=return_false) opt2 = StrOption('opt2', '', validator=return_false)
root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2]) root = OptionDescription('root', '', [ip_admin_eth0, netmask_admin_eth0, opt2])
api = getapi(Config(root)) api = getapi(Config(root))

View File

@ -7,7 +7,7 @@ from py.test import raises
from tiramisu.api import TIRAMISU_VERSION from tiramisu.api import TIRAMISU_VERSION
from tiramisu.setting import groups, owners from tiramisu.setting import groups, owners
from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \ from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \
MetaConfig, getapi, undefined MetaConfig, getapi, undefined, Params, ParamOption
from tiramisu.error import SlaveError from tiramisu.error import SlaveError
@ -372,7 +372,7 @@ def test__master_is_submulti():
def test_callback_submulti(): def test_callback_submulti():
multi = StrOption('multi', '', multi=submulti) multi = StrOption('multi', '', multi=submulti)
multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params={'': ((multi, False),)}) multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params=Params(ParamOption(multi)))
od = OptionDescription('multi', '', [multi, multi2]) od = OptionDescription('multi', '', [multi, multi2])
api = getapi(Config(od)) api = getapi(Config(od))
api.property.read_write() api.property.read_write()

View File

@ -93,7 +93,7 @@ def test_symlink_getcallback():
api = getapi(Config(descr)) api = getapi(Config(descr))
api.property.read_write() api.property.read_write()
assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True assert boolopt.impl_has_callback() == linkopt.impl_has_callback() == True
assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, {}) assert boolopt.impl_get_callback() == linkopt.impl_get_callback() == (return_value, None)
def test_symlink_requires(): def test_symlink_requires():

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from .config import Config, MetaConfig, GroupConfig from .config import Config, MetaConfig, GroupConfig
from .function import Params, ParamOption, ParamValue, ParamContext
from .option import * from .option import *
from .error import APIError from .error import APIError
from .api import getapi from .api import getapi
@ -20,7 +21,11 @@ from .option import __all__ as all_options
from .setting import owners, undefined from .setting import owners, undefined
allfuncs = ['MetaConfig', allfuncs = ['Params',
'ParamOption',
'ParamValue',
'ParamContext',
'MetaConfig',
'GroupConfig', 'GroupConfig',
'Config', 'Config',
'getapi', 'getapi',

View File

@ -23,9 +23,73 @@ from .i18n import _
from .setting import undefined from .setting import undefined
from .option.symlinkoption import DynSymLinkOption from .option.symlinkoption import DynSymLinkOption
from .storage import get_default_values_storages, get_default_settings_storages from .storage import get_default_values_storages, get_default_settings_storages
from .function import ParamValue, ParamContext, ParamIndex
# ____________________________________________________________ # ____________________________________________________________
def manager_callback(callbk,
option,
index,
orig_value,
config_bag,
context):
"""replace Param by true value"""
if isinstance(callbk, ParamValue):
return callbk.value
if isinstance(callbk, ParamIndex):
return index
if context is undefined:
return undefined
if isinstance(callbk, ParamContext):
#Not an option, set full context
return context.duplicate(force_values=get_default_values_storages(),
force_settings=get_default_settings_storages())
opt = callbk.option
if opt.issubdyn():
opt = DynSymLinkOption(opt,
option._rootpath,
option.impl_getsuffix())
path = opt.impl_getpath(context)
else:
path = context.cfgimpl_get_description().impl_get_path_by_opt(opt)
# don't validate if option is option that we tried to validate
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
sconfig_bag.force_permissive = True
if index is not None and opt.impl_is_master_slaves() and \
opt.impl_get_master_slaves().in_same_group(option):
if opt == option:
index_ = None
with_index = False
elif opt.impl_is_master_slaves('slave'):
index_ = index
with_index = False
else:
index_ = None
with_index = True
else:
index_ = None
with_index = False
if opt == option and orig_value is not undefined and \
(not opt.impl_is_master_slaves('slave') or index is None):
return orig_value
if opt == option:
sconfig_bag.validate = False
try:
# get value
value = context.getattr(path,
index_,
sconfig_bag)
if with_index:
return value[index]
return value
except PropertiesOptionError as err:
if callbk.notraiseproperty:
raise err
raise ConfigError(_('unable to carry out a calculation for "{}"'
', {}').format(option.impl_get_display_name(), err))
def carry_out_calculation(option, def carry_out_calculation(option,
context, context,
callback, callback,
@ -147,75 +211,36 @@ def carry_out_calculation(option,
args = [] args = []
kwargs = {} kwargs = {}
# if callback_params has a callback, launch several time calculate() # if callback_params has a callback, launch several time calculate()
master_slave = False
# multi's option should have same value for all option
if option.issubdyn(): if option.issubdyn():
#FIXME why here? should be ParamSuffix !
kwargs['suffix'] = option.impl_getsuffix() kwargs['suffix'] = option.impl_getsuffix()
for key, callbacks in callback_params.items(): if callback_params:
for callbk in callbacks: for callbk in callback_params.args:
if not isinstance(callbk, tuple): try:
# callbk is a value and not a multi value = manager_callback(callbk,
value = callbk option,
elif context is undefined: index,
return undefined orig_value,
elif callbk[0] is None: # pragma: optional cover config_bag,
#Not an option, set full context context)
value = context.duplicate(force_values=get_default_values_storages(), if value is undefined:
force_settings=get_default_settings_storages()) return undefined
elif callbk[0] == 'index':
value = index
else:
# callbk is something link (opt, True|False)
opt, force_permissive = callbk
if opt.issubdyn():
opt = DynSymLinkOption(opt,
option._rootpath,
option.impl_getsuffix())
path = opt.impl_getpath(context)
else:
path = context.cfgimpl_get_description().impl_get_path_by_opt(opt)
# don't validate if option is option that we tried to validate
sconfig_bag = config_bag.copy('nooption')
sconfig_bag.option = opt
sconfig_bag.force_permissive = True
if index is not None and opt.impl_is_master_slaves() and \
opt.impl_get_master_slaves().in_same_group(option):
if opt == option:
index_ = None
with_index = False
elif opt.impl_is_master_slaves('slave'):
index_ = index
with_index = False
else:
index_ = None
with_index = True
else:
index_ = None
with_index = False
if opt == option and orig_value is not undefined and \
(not opt.impl_is_master_slaves('slave') or index is None):
value = orig_value
else:
if opt == option:
sconfig_bag.validate = False
try:
# get value
value = context.getattr(path,
index_,
sconfig_bag)
if with_index:
value = value[index]
except PropertiesOptionError as err:
if force_permissive:
continue
raise ConfigError(_('unable to carry out a calculation for "{}"'
', {}').format(option.impl_get_display_name(), err))
if key == '':
args.append(value) args.append(value)
else: except PropertiesOptionError:
pass
for key, callbk in callback_params.kwargs.items():
try:
value = manager_callback(callbk,
option,
index,
orig_value,
config_bag,
context)
if value is undefined:
return undefined
kwargs[key] = value kwargs[key] = value
except PropertiesOptionError:
pass
ret = calculate(option, ret = calculate(option,
callback, callback,
is_validator, is_validator,

73
tiramisu/function.py Normal file
View File

@ -0,0 +1,73 @@
# Copyright (C) 2018 Team tiramisu (see AUTHORS for all contributors)
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .i18n import _
class Params:
__slots__ = ('args', 'kwargs')
def __init__(self, args=None, kwargs=None):
if args is None:
args = tuple()
if kwargs is None:
kwargs = {}
if isinstance(args, Param):
args = (args,)
else:
if not isinstance(args, tuple):
raise ValueError(_('args in params must be a tuple'))
for arg in args:
if not isinstance(arg, Param):
raise ValueError(_('arg in params must be a Param'))
if not isinstance(kwargs, dict):
raise ValueError(_('kwargs in params must be a dict'))
for arg in kwargs.values():
if not isinstance(arg, Param):
raise ValueError(_('arg in params must be a Param'))
self.args = args
self.kwargs = kwargs
class Param:
pass
class ParamOption(Param):
__slots__ = ('option', 'notraisepropertyerror')
def __init__(self, option, notraisepropertyerror=False):
if option.impl_is_symlinkoption():
cur_opt = option.impl_getopt()
else:
cur_opt = option
if not isinstance(notraisepropertyerror, bool):
raise ValueError(_('param must have a boolean'
' not a {} for notraisepropertyerror'
).format(type(notraisepropertyerror)))
self.option = cur_opt
self.notraiseproperty = notraisepropertyerror
class ParamValue(Param):
__slots__ = ('value',)
def __init__(self, value):
self.value = value
class ParamContext(Param):
__slots__ = tuple()
class ParamIndex(Param):
__slots__ = tuple()

View File

@ -22,10 +22,12 @@ import re
from types import FunctionType from types import FunctionType
import weakref import weakref
from inspect import signature from inspect import signature
from itertools import chain
from ..i18n import _ from ..i18n import _
from ..setting import undefined from ..setting import undefined
from ..error import ConfigError, display_list from ..error import ConfigError, display_list
from ..function import Params, ParamContext, ParamOption, ParamIndex
STATIC_TUPLE = frozenset() STATIC_TUPLE = frozenset()
@ -54,61 +56,17 @@ def validate_calculator(callback,
callbackoption): callbackoption):
"""validate function and parameter set for callback, validation, ... """validate function and parameter set for callback, validation, ...
""" """
def _validate_option(option):
#validate option
if not isinstance(option, OnlyOption):
raise ValueError(_('{}_params must have an option'
' not a {} for first argument'
).format(type_, type(option)))
if option.impl_is_symlinkoption():
cur_opt = option.impl_getopt()
else:
cur_opt = option
if cur_opt != callbackoption:
cur_opt._add_dependency(callbackoption)
callbackoption._has_dependency = True
def _validate_force_permissive(force_permissive):
#validate force_permissive
if not isinstance(force_permissive, bool):
raise ValueError(_('{}_params must have a boolean'
' not a {} for second argument'
).format(type_,
type(force_permissive)))
def _validate_calculator(callbk):
if isinstance(callbk, tuple):
if len(callbk) == 1:
if callbk not in ((None,), ('index',)):
raise ValueError(_('{0}_params with length of '
'tuple as 1 must only have '
'None as first value').format(type_))
if callbk == ((None,)):
callbackoption._has_calc_context = True
return
elif len(callbk) != 2:
raise ValueError(_('{0}_params must only have 1 or 2 '
'as length').format(type_))
option, force_permissive = callbk
_validate_option(option)
_validate_force_permissive(force_permissive)
if not isinstance(callback, FunctionType): if not isinstance(callback, FunctionType):
raise ValueError(_('{0} must be a function').format(type_)) raise ValueError(_('{0} must be a function').format(type_))
if callback_params is not None: if callback_params is not None:
if not isinstance(callback_params, dict): if not isinstance(callback_params, Params):
raise ValueError(_('{0}_params must be a dict').format(type_)) raise ValueError(_('{0}_params must be a params').format(type_))
for key, callbacks in callback_params.items(): for param in chain(callback_params.args, callback_params.kwargs.values()):
if key != '' and len(callbacks) != 1: if isinstance(param, ParamContext):
raise ValueError(_("{0}_params with key {1} mustn't have " callbackoption._has_calc_context = True
"length different to 1").format(type_, elif isinstance(param, ParamOption):
key)) param.option._add_dependency(callbackoption)
if not isinstance(callbacks, tuple): callbackoption._has_dependency = True
raise ValueError(_('{0}_params must be tuple for key "{1}"'
).format(type_, key))
for callbk in callbacks:
_validate_calculator(callbk)
#____________________________________________________________ #____________________________________________________________
@ -193,31 +151,30 @@ class Base(object):
def _get_parameters_args(self, def _get_parameters_args(self,
calculator_params, calculator_params,
add_value): add_value):
args = set() args = set()
kwargs = set() kwargs = set()
# add value as first argument
if add_value: if add_value:
args.add('value') args.add('value')
if self.impl_is_dynoptiondescription(): if self.impl_is_dynoptiondescription():
kwargs.add('suffix') kwargs.add('suffix')
if calculator_params is not None: if calculator_params:
for param in calculator_params.keys(): for idx in range(len(calculator_params.args)):
if param == '': # construct an appropriate name
for idx, _ in enumerate(calculator_params['']): args.add('param{}'.format(idx))
# construct an appropriate name for param in calculator_params.kwargs:
args.add('param{}'.format(idx)) kwargs.add(param)
else:
kwargs.add(param)
return args, kwargs return args, kwargs
def _build_calculator_params(self, def _build_calculator_params(self,
calculator, calculator,
calculator_params, calculator_params,
add_value=False): add_value=False):
"""
:add_value: add value as first argument for validator
"""
is_multi = self.impl_is_optiondescription() or self.impl_is_multi() is_multi = self.impl_is_dynoptiondescription() or self.impl_is_multi()
if calculator_params is None:
calculator_params = {}
func_args, func_kwargs, func_positional, func_keyword = self._get_function_args(calculator) func_args, func_kwargs, func_positional, func_keyword = self._get_function_args(calculator)
calculator_args, calculator_kwargs = self._get_parameters_args(calculator_params, add_value) calculator_args, calculator_kwargs = self._get_parameters_args(calculator_params, add_value)
# remove knowned kwargs # remove knowned kwargs
@ -242,6 +199,7 @@ class Base(object):
func_kwargs_pop.add(func_kwargs_left.pop()) func_kwargs_pop.add(func_kwargs_left.pop())
calculator_args.pop() calculator_args.pop()
func_kwargs -= func_kwargs_pop func_kwargs -= func_kwargs_pop
# func_positional or keyword is True, so assume all args or kwargs are satisfy
if func_positional: if func_positional:
calculator_args = set() calculator_args = set()
if func_keyword: if func_keyword:
@ -255,26 +213,27 @@ class Base(object):
has_index = False has_index = False
if is_multi and func_args: if is_multi and func_args:
# there is extra args/kwargs # there is extra args/kwargs
if not self.impl_is_optiondescription() and is_multi: if not self.impl_is_dynoptiondescription():
params = list(calculator_params.get('', tuple())) if calculator_params is None:
calculator_params = Params()
params = list(calculator_params.args)
if add_value: if add_value:
# only for validator # only for validator
has_self = True params.append(ParamOption(self))
params.append((self, False))
func_args.pop() func_args.pop()
if func_args: if func_args:
has_index = True has_index = True
params.append(('index',)) params.append(ParamIndex())
func_args.pop() func_args.pop()
calculator_params[''] = tuple(params) calculator_params.args = tuple(params)
if func_args: if func_args:
raise ConfigError(_('missing those arguments "{}" in function "{}" for "{}"' raise ConfigError(_('missing those arguments "{}" in function "{}" for "{}"'
'').format(display_list(list(func_args)), '').format(display_list(list(func_args)),
calculator.__name__, calculator.__name__,
self.impl_get_display_name())) self.impl_get_display_name()))
if not self.impl_is_optiondescription() and self.impl_is_multi(): if not self.impl_is_dynoptiondescription() and is_multi and \
if not has_index and 'index' in func_kwargs: not has_index and 'index' in func_kwargs:
calculator_params['index'] = (('index',),) calculator_params.kwargs['index'] = ParamIndex()
return calculator_params return calculator_params
def impl_has_dependency(self, def impl_has_dependency(self,
@ -302,19 +261,15 @@ class Base(object):
options.add(weakref.ref(option)) options.add(weakref.ref(option))
self._dependencies = tuple(options) self._dependencies = tuple(options)
def impl_set_callback(self, def _impl_set_callback(self,
callback, callback,
callback_params=None, callback_params=None):
_init=False):
if callback is None and callback_params is not None: if callback is None and callback_params is not None:
raise ValueError(_("params defined for a callback function but " raise ValueError(_("params defined for a callback function but "
"no callback defined" "no callback defined"
' yet for option "{0}"').format( ' yet for option "{0}"').format(
self.impl_getname())) self.impl_getname()))
if not _init and self.impl_get_callback()[0] is not None:
raise ConfigError(_("a callback is already set for {0}, "
"cannot set another one's").format(self.impl_getname()))
self._validate_calculator(callback, self._validate_calculator(callback,
callback_params) callback_params)
if callback is not None: if callback is not None:

View File

@ -61,8 +61,8 @@ class DynOptionDescription(OptionDescription):
'dynoptiondescription')) 'dynoptiondescription'))
child._setsubdyn(self) child._setsubdyn(self)
# add callback # add callback
self.impl_set_callback(callback, self._impl_set_callback(callback,
callback_params) callback_params)
def _validate_calculator(self, def _validate_calculator(self,
callback, callback,

View File

@ -20,6 +20,7 @@
# the whole pypy projet is under MIT licence # the whole pypy projet is under MIT licence
# ____________________________________________________________ # ____________________________________________________________
import weakref import weakref
from itertools import chain
from ..i18n import _ from ..i18n import _
@ -27,6 +28,7 @@ from ..setting import groups, undefined
from .optiondescription import OptionDescription from .optiondescription import OptionDescription
from .option import Option from .option import Option
from ..error import SlaveError, PropertiesOptionError from ..error import SlaveError, PropertiesOptionError
from ..function import ParamOption
class MasterSlaves(OptionDescription): class MasterSlaves(OptionDescription):
@ -74,13 +76,12 @@ class MasterSlaves(OptionDescription):
child._add_dependency(self) child._add_dependency(self)
child._master_slaves = weakref.ref(self) child._master_slaves = weakref.ref(self)
callback, callback_params = master.impl_get_callback() callback, callback_params = master.impl_get_callback()
if callback is not None and callback_params != {}: if callback is not None and callback_params != None:
for callbacks in callback_params.values(): for callbk in chain(callback_params.args, callback_params.kwargs.values()):
for callbk in callbacks: if isinstance(callbk, ParamOption):
if isinstance(callbk, tuple): if callbk.option in slaves:
if callbk[0] in slaves: raise ValueError(_("callback of master's option shall "
raise ValueError(_("callback of master's option shall " "not refered a slave's ones"))
"not refered a slave's ones"))
def is_master(self, opt): def is_master(self, opt):
master = self._children[0][0] master = self._children[0][0]

View File

@ -29,7 +29,7 @@ from ..setting import log, undefined, debug
from ..autolib import carry_out_calculation from ..autolib import carry_out_calculation
from ..error import (ConfigError, ValueWarning, PropertiesOptionError, from ..error import (ConfigError, ValueWarning, PropertiesOptionError,
display_list) display_list)
from itertools import combinations from ..function import Params, ParamValue
ALLOWED_CONST_LIST = ['_cons_not_equal'] ALLOWED_CONST_LIST = ['_cons_not_equal']
@ -157,9 +157,8 @@ class Option(OnlyOption):
default = tuple(default) default = tuple(default)
_setattr(self, '_default', default) _setattr(self, '_default', default)
self.impl_set_callback(callback, self._impl_set_callback(callback,
callback_params, callback_params)
_init=True)
def impl_is_multi(self): def impl_is_multi(self):
return getattr(self, '_multi', 1) != 1 return getattr(self, '_multi', 1) != 1
@ -221,19 +220,15 @@ class Option(OnlyOption):
_index): _index):
validator, validator_params = self.impl_get_validator() validator, validator_params = self.impl_get_validator()
if validator is not None: if validator is not None:
if validator_params != {}: #inject value in calculation
validator_params_ = {} if validator_params is None:
for val_param, values in validator_params.items(): args = []
validator_params_[val_param] = values kwargs = None
#inject value in calculation
if '' in validator_params_:
lst = list(validator_params_[''])
lst.insert(0, val)
validator_params_[''] = tuple(lst)
else:
validator_params_[''] = (val,)
else: else:
validator_params_ = {'': (val,)} args = list(validator_params.args)
kwargs = validator_params.kwargs
args.insert(0, ParamValue(val))
validator_params_ = Params(tuple(args), kwargs)
# Raise ValueError if not valid # Raise ValueError if not valid
carry_out_calculation(current_opt, carry_out_calculation(current_opt,
context=context, context=context,