DynOptionDescription accept only suffixes attributes with Calculation, no more callback/callback_params

This commit is contained in:
Emmanuel Garette 2019-10-15 17:45:21 +02:00
parent fd50913466
commit 42291aec51
6 changed files with 111 additions and 118 deletions

View File

@ -10,7 +10,7 @@ from .autopath import do_autopath
do_autopath() do_autopath()
from tiramisu import Config, MetaConfig, \ from tiramisu import Config, MetaConfig, \
StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \ StrOption, SymLinkOption, OptionDescription, Leadership, DynOptionDescription, \
submulti, undefined, owners, Params, ParamOption submulti, undefined, owners, Params, ParamOption, Calculation
from tiramisu.error import PropertiesOptionError, APIError, ConfigError, LeadershipError from tiramisu.error import PropertiesOptionError, APIError, ConfigError, LeadershipError
ICON = u'\u2937' ICON = u'\u2937'
@ -1630,7 +1630,7 @@ def make_conf(options, multi, default, default_multi, require, consistency, call
if symlink: if symlink:
return return
optiondescription = DynOptionDescription optiondescription = DynOptionDescription
kwargs['callback'] = return_list kwargs['suffixes'] = Calculation(return_list)
dyn.append(path) dyn.append(path)
options = [] options = []
if 'options' in collected: if 'options' in collected:

View File

@ -309,7 +309,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=Params((ParamOption(a),))) dod = DynOptionDescription('dod', '', [b], suffixes=Calculation(funcname, 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

@ -57,7 +57,7 @@ def return_str(*args, **kwargs):
def test_build_dyndescription(): def test_build_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None} assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None}
@ -65,7 +65,7 @@ def test_build_dyndescription():
def test_build_dyndescription_raise(): def test_build_dyndescription_raise():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_raise) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_raise))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ConfigError, "cfg.value.dict()") raises(ConfigError, "cfg.value.dict()")
@ -73,7 +73,7 @@ def test_build_dyndescription_raise():
def test_build_dyndescription_not_list(): def test_build_dyndescription_not_list():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_str) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_str))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.value.dict()") raises(ValueError, "cfg.value.dict()")
@ -81,7 +81,7 @@ def test_build_dyndescription_not_list():
def test_subpath_dyndescription(): def test_subpath_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_list) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -90,7 +90,7 @@ def test_subpath_dyndescription():
def test_list_dyndescription(): def test_list_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -100,7 +100,7 @@ def test_list_dyndescription():
def test_unknown_dyndescription(): def test_unknown_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -111,7 +111,7 @@ def test_unknown_dyndescription():
def test_getdoc_dyndescription(): def test_getdoc_dyndescription():
st1 = StrOption('st', 'doc1') st1 = StrOption('st', 'doc1')
dod = DynOptionDescription('dod', 'doc2', [st1], callback=return_list) dod = DynOptionDescription('dod', 'doc2', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -127,7 +127,7 @@ def test_getdoc_dyndescription():
def test_mod_dyndescription(): def test_mod_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -153,7 +153,7 @@ def test_mod_dyndescription():
def test_del_dyndescription(): def test_del_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -168,7 +168,7 @@ def test_del_dyndescription():
def test_multi_dyndescription(): def test_multi_dyndescription():
st = StrOption('st', '', multi=True) st = StrOption('st', '', multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -195,7 +195,7 @@ def test_multi_dyndescription():
def test_prop_dyndescription(): def test_prop_dyndescription():
st = StrOption('st', '', properties=('test',)) st = StrOption('st', '', properties=('test',))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -219,7 +219,7 @@ def test_prop_dyndescription():
def test_prop_dyndescription_force_store_value(): def test_prop_dyndescription_force_store_value():
st = StrOption('st', '', properties=('force_store_value',)) st = StrOption('st', '', properties=('force_store_value',))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
raises(ConfigError, "Config(od2)") raises(ConfigError, "Config(od2)")
@ -227,7 +227,7 @@ def test_prop_dyndescription_force_store_value():
def test_callback_dyndescription(): def test_callback_dyndescription():
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -250,7 +250,7 @@ def test_callback_dyndescription():
def test_callback_list_dyndescription(): def test_callback_list_dyndescription():
st = StrOption('st', '', Calculation(return_list2), multi=True) st = StrOption('st', '', Calculation(return_list2), multi=True)
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -268,7 +268,7 @@ def test_callback_list_dyndescription():
def test_mandatory_dyndescription(): def test_mandatory_dyndescription():
st = StrOption('st', '', properties=('mandatory',)) st = StrOption('st', '', properties=('mandatory',))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
cfg = Config(od1) cfg = Config(od1)
assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']} assert cfg.value.dict() == {'dodval1.stval1': None, 'dodval2.stval2': None, 'val1': ['val1', 'val2']}
@ -299,7 +299,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od1 = OptionDescription('od', '', [dod, val1]) od1 = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -309,7 +309,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -321,7 +321,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -345,7 +345,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -361,7 +361,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -389,7 +389,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -406,7 +406,7 @@ def test_prop_dyndescription_context():
def test_callback_dyndescription_context(): def test_callback_dyndescription_context():
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True) val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
st = StrOption('st', '', Calculation(return_dynval)) st = StrOption('st', '', Calculation(return_dynval))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -430,7 +430,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -452,7 +452,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -469,7 +469,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=Params(ParamOption(val1))) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -500,7 +500,7 @@ def test_dyndescription_root():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,)) st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st1], callback=return_list) dod = DynOptionDescription('dod', '', [boolean, st1], suffixes=Calculation(return_list))
raises(ConfigError, "Config(dod)") raises(ConfigError, "Config(dod)")
@ -512,7 +512,7 @@ def test_requires_dyndescription():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st1 = StrOption('st', '', properties=(disabled_property,)) st1 = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st1], callback=return_list) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean]) od2 = OptionDescription('od', '', [od1, boolean])
api = Config(od2) api = Config(od2)
@ -567,7 +567,7 @@ def test_requires_dyndescription_boolean():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,)) st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od, boolean1, boolean]) od2 = OptionDescription('od', '', [od, boolean1, boolean])
cfg = Config(od2) cfg = Config(od2)
@ -599,7 +599,7 @@ def test_requires_dyndescription_in_dyn():
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
st = StrOption('st', '', properties=(disabled_property,)) st = StrOption('st', '', properties=(disabled_property,))
dod = DynOptionDescription('dod', '', [boolean, st], callback=return_list) dod = DynOptionDescription('dod', '', [boolean, st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -632,7 +632,7 @@ def test_requires_dyndescription2():
kwargs={'condition': ParamOption(boolean, raisepropertyerror=True), kwargs={'condition': ParamOption(boolean, raisepropertyerror=True),
'expected': ParamValue(False), 'expected': ParamValue(False),
'default': ParamValue(None)})) 'default': ParamValue(None)}))
dod = DynOptionDescription('dod', '', [st1], callback=return_list, properties=(disabled_property,)) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_list), properties=(disabled_property,))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
od2 = OptionDescription('od', '', [od1, boolean]) od2 = OptionDescription('od', '', [od1, boolean])
api = Config(od2) api = Config(od2)
@ -676,7 +676,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=Params((ParamValue('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], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -688,7 +688,7 @@ def test_validator_dyndescription():
def test_makedict_dyndescription_context(): def test_makedict_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) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -703,7 +703,7 @@ def test_makedict_dyndescription_context():
def test_find_dyndescription_context(): def test_find_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) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -721,7 +721,7 @@ def test_find_dyndescription_context():
def test_information_dyndescription_context(): def test_information_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) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, val1]) od = OptionDescription('od', '', [dod, val1])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
dod.impl_set_information('testod', 'val1') dod.impl_set_information('testod', 'val1')
@ -738,7 +738,7 @@ def test_information_dyndescription_context():
def test_consistency_dyndescription(): def test_consistency_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list) dod = DynOptionDescription('dod', '', [st1, st2], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
st1.impl_add_consistency('not_equal', st2) st1.impl_add_consistency('not_equal', st2)
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
@ -762,7 +762,7 @@ def test_consistency_dyndescription():
def test_consistency_dyndescription_default(): def test_consistency_dyndescription_default():
st = StrOption('st', '', 'yes') st = StrOption('st', '', 'yes')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list) dod = DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
st.impl_add_consistency('not_equal', st2) st.impl_add_consistency('not_equal', st2)
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
@ -774,7 +774,7 @@ def test_consistency_dyndescription_default():
def test_consistency_dyndescription_default_multi2(): def test_consistency_dyndescription_default_multi2():
st = StrOption('st', '', ['yes'], multi=True) st = StrOption('st', '', ['yes'], multi=True)
st2 = StrOption('st2', '', ['yes'], multi=True) st2 = StrOption('st2', '', ['yes'], multi=True)
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list) dod = DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list))
dod dod
# FIXME raises(ValueError, "st.impl_add_consistency('not_equal', st2)") # FIXME raises(ValueError, "st.impl_add_consistency('not_equal', st2)")
@ -783,7 +783,7 @@ def test_consistency_only_one_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
st st
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st2], callback=return_list) dod = DynOptionDescription('dod', '', [st2], suffixes=Calculation(return_list))
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)") raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
raises(ConfigError, "st2.impl_add_consistency('not_equal', st)") raises(ConfigError, "st2.impl_add_consistency('not_equal', st)")
@ -792,7 +792,7 @@ def test_consistency_became_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
st2.impl_add_consistency('not_equal', st) st2.impl_add_consistency('not_equal', st)
od = DynOptionDescription('dod', '', [st2], callback=return_list) od = DynOptionDescription('dod', '', [st2], suffixes=Calculation(return_list))
od2 = OptionDescription('od', '', [od, st]) od2 = OptionDescription('od', '', [od, st])
od2 od2
raises(ConfigError, "c = Config(od2)") raises(ConfigError, "c = Config(od2)")
@ -802,7 +802,7 @@ def test_consistency_became_dyndescription2():
st = StrOption('st', '') st = StrOption('st', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
st.impl_add_consistency('not_equal', st2) st.impl_add_consistency('not_equal', st2)
od = DynOptionDescription('dod', '', [st2], callback=return_list) od = DynOptionDescription('dod', '', [st2], suffixes=Calculation(return_list))
od2 = OptionDescription('od', '', [od, st]) od2 = OptionDescription('od', '', [od, st])
od2 od2
raises(ConfigError, "c = Config(od2)") raises(ConfigError, "c = Config(od2)")
@ -812,7 +812,7 @@ def test_consistency_external_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
st1 = StrOption('st1', '') st1 = StrOption('st1', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list) dod = DynOptionDescription('dod', '', [st1, st2], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, st]) od = OptionDescription('od', '', [dod, st])
od od
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)") raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
@ -821,10 +821,10 @@ def test_consistency_external_dyndescription():
def test_consistency_notsame_dyndescription(): def test_consistency_notsame_dyndescription():
st1 = StrOption('st1', '') st1 = StrOption('st1', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list) dod = DynOptionDescription('dod', '', [st1, st2], suffixes=Calculation(return_list))
tst1 = StrOption('tst1', '') tst1 = StrOption('tst1', '')
tst2 = StrOption('tst2', '') tst2 = StrOption('tst2', '')
tdod = DynOptionDescription('tdod', '', [tst1, tst2], callback=return_list) tdod = DynOptionDescription('tdod', '', [tst1, tst2], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod, tdod]) od = OptionDescription('od', '', [dod, tdod])
od od
raises(ConfigError, "st1.impl_add_consistency('not_equal', tst1)") raises(ConfigError, "st1.impl_add_consistency('not_equal', tst1)")
@ -851,7 +851,7 @@ def test_all_dyndescription():
dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1, dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1,
boo, intr, floa, uni, port, broad, boo, intr, floa, uni, port, broad,
domain, email, url, username, domain, email, url, username,
filename], callback=return_list) filename], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [dod]) od = OptionDescription('od', '', [dod])
api = Config(od) api = Config(od)
assert api.option('dodval1.stval1').value.get() is None assert api.option('dodval1.stval1').value.get() is None
@ -928,7 +928,7 @@ def test_all_dyndescription():
def test_consistency_ip_netmask_dyndescription(): def test_consistency_ip_netmask_dyndescription():
ipa = IPOption('a', '') ipa = IPOption('a', '')
netb = NetmaskOption('b', '') netb = NetmaskOption('b', '')
dod = DynOptionDescription('dod', '', [ipa, netb], callback=return_list) dod = DynOptionDescription('dod', '', [ipa, netb], suffixes=Calculation(return_list))
netb.impl_add_consistency('ip_netmask', ipa) netb.impl_add_consistency('ip_netmask', ipa)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
@ -944,7 +944,7 @@ def test_consistency_ip_in_network_dyndescription():
neta = NetworkOption('a', '') neta = NetworkOption('a', '')
netb = NetmaskOption('b', '') netb = NetmaskOption('b', '')
ipc = IPOption('c', '') ipc = IPOption('c', '')
dod = DynOptionDescription('dod', '', [neta, netb, ipc], callback=return_list) dod = DynOptionDescription('dod', '', [neta, netb, ipc], suffixes=Calculation(return_list))
ipc.impl_add_consistency('in_network', neta, netb) ipc.impl_add_consistency('in_network', neta, netb)
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
@ -957,7 +957,7 @@ def test_leadership_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1015,7 +1015,7 @@ def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1040,7 +1040,7 @@ def test_leadership_dyndescription_param():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1))) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -1098,7 +1098,7 @@ def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1179,7 +1179,7 @@ def test_leadership_dyndescription_param_leader():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val1))) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val1))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -1190,7 +1190,7 @@ def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1217,7 +1217,7 @@ def test_leadership_dyndescription_param_follower():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list, callback_params=Params(ParamOption(val2))) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list, Params(ParamOption(val2))))
od = OptionDescription('od', '', [st, odval]) od = OptionDescription('od', '', [st, odval])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
cfg = Config(od2) cfg = Config(od2)
@ -1228,7 +1228,7 @@ def test_leadership_default_multi_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=True, default_multi='no') st2 = StrOption('st2', "", multi=True, default_multi='no')
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1252,7 +1252,7 @@ def test_leadership_submulti_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", multi=submulti) st2 = StrOption('st2', "", multi=submulti)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
std = DynOptionDescription('st', '', [stm], callback=return_list) std = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [std]) od1 = OptionDescription('od', '', [std])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -1284,7 +1284,7 @@ def test_leadership_callback_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamOption(st1)})), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st1 = DynOptionDescription('st', '', [stm], callback=return_list) st1 = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [st1]) od1 = OptionDescription('od', '', [st1])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -1345,7 +1345,7 @@ def test_leadership_callback_value_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(kwargs={'value': ParamValue('val')})), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
st = DynOptionDescription('st', '', [stm], callback=return_list) st = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od = OptionDescription('od', '', [st]) od = OptionDescription('od', '', [st])
od2 = OptionDescription('od', '', [od]) od2 = OptionDescription('od', '', [od])
api = Config(od2) api = Config(od2)
@ -1361,7 +1361,7 @@ def test_leadership_callback_nomulti_dyndescription():
st1 = StrOption('st1', "", multi=True) st1 = StrOption('st1', "", multi=True)
st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True) st2 = StrOption('st2', "", Calculation(return_dynval, Params(ParamOption(v11))), multi=True)
stm = Leadership('st1', '', [st1, st2]) stm = Leadership('st1', '', [st1, st2])
stt = DynOptionDescription('st', '', [stm], callback=return_list) stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1, v11]) od2 = OptionDescription('od', '', [od1, v11])
api = Config(od2) api = Config(od2)
@ -1376,7 +1376,7 @@ def test_leadership_callback_samegroup_dyndescription():
st2 = StrOption('st2', "", multi=True) st2 = StrOption('st2', "", multi=True)
st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True) st3 = StrOption('st3', "", Calculation(return_dynval, Params(ParamOption(st2))), multi=True)
stm = Leadership('st1', '', [st1, st2, st3]) stm = Leadership('st1', '', [st1, st2, st3])
stt = DynOptionDescription('st', '', [stm], callback=return_list) stt = DynOptionDescription('st', '', [stm], suffixes=Calculation(return_list))
od1 = OptionDescription('od', '', [stt]) od1 = OptionDescription('od', '', [stt])
od2 = OptionDescription('od', '', [od1]) od2 = OptionDescription('od', '', [od1])
api = Config(od2) api = Config(od2)
@ -1419,7 +1419,7 @@ def test_leadership_callback_samegroup_dyndescription():
def test_invalid_conflict_dyndescription(): def test_invalid_conflict_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st], callback=return_list) dod = DynOptionDescription('dod', '', [st], suffixes=Calculation(return_list))
dodinvalid = StrOption('dodinvalid', '') dodinvalid = StrOption('dodinvalid', '')
dod, dodinvalid dod, dodinvalid
raises(ConflictError, "OptionDescription('od', '', [dod, dodinvalid])") raises(ConflictError, "OptionDescription('od', '', [dod, dodinvalid])")
@ -1429,33 +1429,33 @@ def test_invalid_subod_dyndescription():
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
od1 = OptionDescription('od1', '', [st2]) od1 = OptionDescription('od1', '', [st2])
od1 od1
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)") raises(ConfigError, "DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list))")
def test_invalid_subdynod_dyndescription(): def test_invalid_subdynod_dyndescription():
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
od1 = DynOptionDescription('od1', '', [st2], callback=return_list) od1 = DynOptionDescription('od1', '', [st2], suffixes=Calculation(return_list))
od1 od1
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)") raises(ConfigError, "DynOptionDescription('dod', '', [od1], suffixes=Calculation(return_list))")
def test_invalid_symlink_dyndescription(): def test_invalid_symlink_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
st2 = SymLinkOption('st2', st) st2 = SymLinkOption('st2', st)
st2 st2
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2], callback=return_list)") raises(ConfigError, "DynOptionDescription('dod', '', [st, st2], suffixes=Calculation(return_list))")
def test_nocallback_dyndescription(): def test_nocallback_dyndescription():
st = StrOption('st', '') st = StrOption('st', '')
st2 = StrOption('st2', '') st2 = StrOption('st2', '')
st, st2 st, st2
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2])") raises(TypeError, "DynOptionDescription('dod', '', [st, st2])")
def test_invalid_samevalue_dyndescription(): def test_invalid_samevalue_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_same_list) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_same_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.value.dict()") raises(ValueError, "cfg.value.dict()")
@ -1463,7 +1463,7 @@ def test_invalid_samevalue_dyndescription():
def test_invalid_name_dyndescription(): def test_invalid_name_dyndescription():
st1 = StrOption('st', '') st1 = StrOption('st', '')
dod = DynOptionDescription('dod', '', [st1], callback=return_wrong_list) dod = DynOptionDescription('dod', '', [st1], suffixes=Calculation(return_wrong_list))
od1 = OptionDescription('od', '', [dod]) od1 = OptionDescription('od', '', [dod])
cfg = Config(od1) cfg = Config(od1)
raises(ValueError, "cfg.value.dict()") raises(ValueError, "cfg.value.dict()")

View File

@ -114,8 +114,7 @@ class SubConfig(object):
option = woption() option = woption()
if option.impl_is_dynoptiondescription(): if option.impl_is_dynoptiondescription():
subpath = option.impl_getpath().rsplit('.', 1)[0] subpath = option.impl_getpath().rsplit('.', 1)[0]
for suffix in option.get_suffixes(option_bag.config_bag, for suffix in option.get_suffixes(option_bag.config_bag):
remove_none=True):
doption = option.to_dynoption(subpath, doption = option.to_dynoption(subpath,
suffix) suffix)
doption_path = doption.impl_getpath() doption_path = doption.impl_getpath()

View File

@ -25,24 +25,24 @@ from typing import List, Callable
from ..i18n import _ from ..i18n import _
from .optiondescription import OptionDescription from .optiondescription import OptionDescription
from .baseoption import BaseOption from .baseoption import BaseOption
from ..setting import ConfigBag, groups, undefined from ..setting import OptionBag, ConfigBag, groups, undefined
from ..error import ConfigError from ..error import ConfigError
from ..autolib import carry_out_calculation from ..autolib import carry_out_calculation, Calculation
NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$') NAME_REGEXP = re.compile(r'^[a-zA-Z\d\-_]*$')
class DynOptionDescription(OptionDescription): class DynOptionDescription(OptionDescription):
__slots__ = ('_suffixes',)
def __init__(self, def __init__(self,
name: str, name: str,
doc: str, doc: str,
children: List[BaseOption], children: List[BaseOption],
suffixes: Calculation,
requires=None, requires=None,
properties=None, properties=None) -> None:
callback: Callable=None,
callback_params=None) -> None:
super().__init__(name, super().__init__(name,
doc, doc,
@ -61,46 +61,40 @@ class DynOptionDescription(OptionDescription):
raise ConfigError(_('cannot set symlinkoption in a ' raise ConfigError(_('cannot set symlinkoption in a '
'dynoptiondescription')) 'dynoptiondescription'))
child._setsubdyn(self) child._setsubdyn(self)
# add callback # add suffixes
self._impl_set_callback(callback, if __debug__ and isinstance(suffixes, Calculation):
callback_params) self._suffixes = suffixes
def _validate_calculator(self,
callback: Callable,
callback_params) -> None:
if callback is None:
raise ConfigError(_('callback is mandatory for the dynoptiondescription "{}"'
'').format(self.impl_get_display_name()))
def get_suffixes(self, def get_suffixes(self,
config_bag: ConfigBag, config_bag: ConfigBag) -> List[str]:
remove_none: bool=False) -> List[str]:
callback, callback_params = self.impl_get_callback() option_bag = OptionBag()
values = carry_out_calculation(self, option_bag.set_option(self,
callback, self.impl_getpath(),
callback_params, None,
None, config_bag)
config_bag, values = self._suffixes.execute(option_bag)
fromconsistency=[]) if __debug__:
if not isinstance(values, list): if not isinstance(values, list):
raise ValueError(_('DynOptionDescription callback for option "{}", is not a list ({})' raise ValueError(_('DynOptionDescription suffixes for option "{}", is not a list ({})'
'').format(self.impl_get_display_name(), values)) '').format(self.impl_get_display_name(), values))
values_ = [] values_ = []
for val in values: for val in values:
if not isinstance(val, str) or re.match(NAME_REGEXP, val) is None: if not isinstance(val, str) or re.match(NAME_REGEXP, val) is None:
if not remove_none or val is not None: if val is not None:
raise ValueError(_('invalid suffix "{}" for option "{}"' raise ValueError(_('invalid suffix "{}" for option "{}"'
'').format(val, '').format(val,
self.impl_get_display_name())) self.impl_get_display_name()))
else: else:
values_.append(val) values_.append(val)
if len(values_) > len(set(values_)): if len(values_) > len(set(values_)):
extra_values = values_.copy() extra_values = values_.copy()
for val in set(values_): for val in set(values_):
extra_values.remove(val) extra_values.remove(val)
raise ValueError(_('DynOptionDescription callback return a list with multiple value ' raise ValueError(_('DynOptionDescription suffixes return a list with multiple value '
'"{}"''').format(extra_values)) '"{}"''').format(extra_values))
return values_ values = values_
return values
def impl_is_dynoptiondescription(self) -> bool: def impl_is_dynoptiondescription(self) -> bool:
return True return True

View File

@ -69,8 +69,8 @@ class SynDynOptionDescription:
return child.to_dynoption(subpath, return child.to_dynoption(subpath,
self._suffix) self._suffix)
raise AttributeError(_('unknown option "{0}" ' raise AttributeError(_('unknown option "{0}" '
'in syndynoptiondescription "{1}"' 'in dynamic optiondescription "{1}"'
'').format(name, self.impl_getname())) '').format(name, self.impl_get_display_name()))
def impl_getname(self) -> str: def impl_getname(self) -> str:
return self._opt.impl_getname() + self._suffix return self._opt.impl_getname() + self._suffix