add DynOptionDescription
This commit is contained in:
87
test/test_choice_option.py
Normal file
87
test/test_choice_option.py
Normal file
@ -0,0 +1,87 @@
|
||||
# coding: utf-8
|
||||
import autopath
|
||||
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.option import ChoiceOption, StrOption, OptionDescription
|
||||
from tiramisu.config import Config
|
||||
|
||||
from py.test import raises
|
||||
|
||||
|
||||
def return_val(val):
|
||||
return val
|
||||
|
||||
|
||||
def return_list():
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def return_calc_list(val):
|
||||
return [val]
|
||||
|
||||
|
||||
def test_choiceoption_function():
|
||||
ch = ChoiceOption('ch', '', values=return_list)
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
|
||||
|
||||
def test_choiceoption_calc_function():
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ('val1',)})
|
||||
od = OptionDescription('od', '', [ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_function():
|
||||
st = StrOption('st', '', 'val1')
|
||||
ch = ChoiceOption('ch', "", values=return_calc_list, values_params={'': ((st, False),)})
|
||||
od = OptionDescription('od', '', [st, ch])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
cfg.ch = 'val1'
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
|
||||
|
||||
def test_choiceoption_calc_opt_multi_function():
|
||||
st = StrOption('st', '', ['val1'], multi=True)
|
||||
ch = ChoiceOption('ch', "", default_multi='val2', values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
ch2 = ChoiceOption('ch2', "", default=['val2'], values=return_val, values_params={'': ((st, False),)}, multi=True)
|
||||
od = OptionDescription('od', '', [st, ch, ch2])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
assert cfg.ch == []
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch.append()")
|
||||
cfg.ch = ['val1']
|
||||
assert cfg.getowner(ch) == owner
|
||||
del(cfg.ch)
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
raises(ValueError, "cfg.ch='no'")
|
||||
assert cfg.getowner(ch) == owners.default
|
||||
#
|
||||
raises(ValueError, "cfg.ch2")
|
1317
test/test_dyn_optiondescription.py
Normal file
1317
test/test_dyn_optiondescription.py
Normal file
@ -0,0 +1,1317 @@
|
||||
# coding: utf-8
|
||||
import autopath
|
||||
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.option import BoolOption, StrOption, ChoiceOption, IPOption, \
|
||||
NetworkOption, NetmaskOption, IntOption, FloatOption, \
|
||||
UnicodeOption, PortOption, BroadcastOption, DomainnameOption, \
|
||||
EmailOption, URLOption, UsernameOption, FilenameOption, SymLinkOption, \
|
||||
OptionDescription, DynOptionDescription, DynSymLinkOption, submulti
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.error import PropertiesOptionError, ConfigError, ConflictError
|
||||
from tiramisu.storage import delete_session
|
||||
from test.test_state import _diff_opts, _diff_conf
|
||||
|
||||
from py.test import raises
|
||||
from pickle import dumps, loads
|
||||
|
||||
|
||||
def return_true(value, param=None):
|
||||
if value == 'val' and param in [None, 'yes']:
|
||||
return
|
||||
raise ValueError('no value')
|
||||
|
||||
|
||||
def return_dynval(suffix, value='val'):
|
||||
return value
|
||||
|
||||
|
||||
def return_list2(suffix):
|
||||
return [suffix, 'val2']
|
||||
|
||||
|
||||
def return_list(val=None):
|
||||
if val:
|
||||
return val
|
||||
else:
|
||||
return ['val1', 'val2']
|
||||
|
||||
|
||||
def test_build_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
assert str(cfg) == """[dodval1]
|
||||
[dodval2]"""
|
||||
assert str(cfg.dodval1) == "stval1 = None"
|
||||
assert str(cfg.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
def test_subpath_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert str(cfg) == "[od]"
|
||||
assert str(cfg.od) == """[dodval1]
|
||||
[dodval2]"""
|
||||
assert str(cfg.od.dodval1) == "stval1 = None"
|
||||
assert str(cfg.od.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
def test_list_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
|
||||
|
||||
def test_unknown_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
raises(AttributeError, "cfg.od.dodval3")
|
||||
raises(AttributeError, "cfg.od.dodval1.novalue")
|
||||
|
||||
|
||||
def test_getdoc_dyndescription():
|
||||
st = StrOption('st', 'doc1')
|
||||
dod = DynOptionDescription('dod', 'doc2', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
dodval1 = cfg.unwrap_from_path('od.dodval1')
|
||||
dodval2 = cfg.unwrap_from_path('od.dodval2')
|
||||
assert stval1.impl_getname() == 'stval1'
|
||||
assert stval2.impl_getname() == 'stval2'
|
||||
assert dodval1.impl_getname() == 'dodval1'
|
||||
assert dodval2.impl_getname() == 'dodval2'
|
||||
assert stval1.impl_getdoc() == 'doc1'
|
||||
assert stval2.impl_getdoc() == 'doc1'
|
||||
assert dodval1.impl_getdoc() == 'doc2'
|
||||
assert dodval2.impl_getdoc() == 'doc2'
|
||||
|
||||
|
||||
def test_getpaths_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.cfgimpl_get_description().impl_getpaths() == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
assert cfg.cfgimpl_get_description().impl_getpaths(include_groups=True) == ['od', 'od.dodval1', 'od.dodval1.stval1', 'od.dodval2', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
def test_mod_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.od.dodval1.stval1 == 'yes'
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval2.stval2 = 'no'
|
||||
assert cfg.od.dodval1.stval1 == 'yes'
|
||||
assert cfg.od.dodval2.stval2 == 'no'
|
||||
assert cfg.getowner(st) == owners.default
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owner
|
||||
|
||||
|
||||
def test_del_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.getowner(stval1) == owner
|
||||
del(cfg.od.dodval1.stval1)
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
|
||||
|
||||
def test_multi_dyndescription():
|
||||
st = StrOption('st', '', multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 == []
|
||||
assert cfg.od.dodval2.stval2 == []
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1.append('yes')
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
assert cfg.od.dodval2.stval2 == []
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval2.stval2 = ['no']
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
assert cfg.od.dodval2.stval2 == ['no']
|
||||
assert cfg.getowner(st) == owners.default
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owner
|
||||
cfg.od.dodval1.stval1.append('yes')
|
||||
assert cfg.od.dodval1.stval1 == ['yes', 'yes']
|
||||
cfg.od.dodval1.stval1.pop(0)
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
|
||||
|
||||
def test_prop_dyndescription():
|
||||
st = StrOption('st', '', properties=('test',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
dodval1 = cfg.unwrap_from_path('od.dodval1')
|
||||
dodval2 = cfg.unwrap_from_path('od.dodval2')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str(['test'])
|
||||
assert str(cfg.cfgimpl_get_settings()[stval2]) == str(['test'])
|
||||
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str(['test'])
|
||||
assert str(cfg.cfgimpl_get_settings()[stval2]) == str(['test', 'test2'])
|
||||
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
||||
#
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval1]) == str([])
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval2]) == str([])
|
||||
cfg.cfgimpl_get_settings()[dodval1].append('test1')
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval1]) == str(['test1'])
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval2]) == str([])
|
||||
cfg.cfgimpl_get_settings()[dodval1].remove('test1')
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval1]) == str([])
|
||||
assert str(cfg.cfgimpl_get_settings()[dodval2]) == str([])
|
||||
|
||||
|
||||
def test_callback_dyndescription():
|
||||
st = StrOption('st', '', callback=return_dynval)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1 = 'val2'
|
||||
assert cfg.od.dodval1.stval1 == 'val2'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
del(cfg.od.dodval1.stval1)
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
|
||||
|
||||
def test_callback_list_dyndescription():
|
||||
st = StrOption('st', '', callback=return_list2, multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 == ['val1', 'val2']
|
||||
assert cfg.od.dodval2.stval2 == ['val2', 'val2']
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1 = ['val3', 'val2']
|
||||
assert cfg.od.dodval1.stval1 == ['val3', 'val2']
|
||||
assert cfg.od.dodval2.stval2 == ['val2', 'val2']
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
|
||||
|
||||
def test_mandatory_dyndescription():
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "cfg.od.dodval1.stval1")
|
||||
raises(PropertiesOptionError, "cfg.od.dodval2.stval2")
|
||||
cfg.read_write()
|
||||
cfg.od.dodval1.stval1 = 'val'
|
||||
cfg.read_only()
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
raises(PropertiesOptionError, "cfg.od.dodval2.stval2")
|
||||
cfg.read_write()
|
||||
del(cfg.od.dodval1.stval1)
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "cfg.od.dodval1.stval1")
|
||||
assert cfg.cfgimpl_get_values().mandatory_warnings() == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
def test_build_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
cfg = Config(od)
|
||||
assert str(cfg) == """[dodval1]
|
||||
[dodval2]
|
||||
val1 = ['val1', 'val2']"""
|
||||
assert str(cfg.dodval1) == "stval1 = None"
|
||||
assert str(cfg.dodval2) == "stval2 = None"
|
||||
cfg.unwrap_from_path('dodval2')
|
||||
|
||||
|
||||
def test_subpath_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert str(cfg) == "[od]"
|
||||
assert str(cfg.od) == """[dodval1]
|
||||
[dodval2]
|
||||
val1 = ['val1', 'val2']"""
|
||||
assert str(cfg.od.dodval1) == "stval1 = None"
|
||||
assert str(cfg.od.dodval2) == "stval2 = None"
|
||||
|
||||
|
||||
def test_list_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
raises(AttributeError, "cfg.od.dodval3")
|
||||
|
||||
|
||||
def test_mod_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.od.dodval1.stval1 == 'yes'
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval2.stval2 = 'no'
|
||||
assert cfg.od.dodval1.stval1 == 'yes'
|
||||
assert cfg.od.dodval2.stval2 == 'no'
|
||||
assert cfg.getowner(st) == owners.default
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owner
|
||||
|
||||
|
||||
def test_del_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.getowner(stval1) == owner
|
||||
del(cfg.od.dodval1.stval1)
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
|
||||
|
||||
def test_multi_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', multi=True)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 == []
|
||||
assert cfg.od.dodval2.stval2 == []
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1.append('yes')
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
assert cfg.od.dodval2.stval2 == []
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval2.stval2 = ['no']
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
assert cfg.od.dodval2.stval2 == ['no']
|
||||
assert cfg.getowner(st) == owners.default
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owner
|
||||
cfg.od.dodval1.stval1.append('yes')
|
||||
assert cfg.od.dodval1.stval1 == ['yes', 'yes']
|
||||
cfg.od.dodval1.stval1.pop(0)
|
||||
assert cfg.od.dodval1.stval1 == ['yes']
|
||||
|
||||
|
||||
def test_prop_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('test',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str(['test'])
|
||||
assert str(cfg.cfgimpl_get_settings()[stval2]) == str(['test'])
|
||||
cfg.cfgimpl_get_settings()[stval2].append('test2')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str(['test'])
|
||||
assert str(cfg.cfgimpl_get_settings()[stval2]) == str(['test', 'test2'])
|
||||
cfg.cfgimpl_get_settings()[stval1].remove('test')
|
||||
assert str(cfg.cfgimpl_get_settings()[stval1]) == str([])
|
||||
|
||||
|
||||
def test_callback_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', callback=return_dynval)
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
cfg.od.dodval1.stval1 = 'val2'
|
||||
assert cfg.od.dodval1.stval1 == 'val2'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owner
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
del(cfg.od.dodval1.stval1)
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
assert cfg.od.dodval2.stval2 == 'val'
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owners.default
|
||||
|
||||
|
||||
def test_mandatory_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "cfg.od.dodval1.stval1")
|
||||
raises(PropertiesOptionError, "cfg.od.dodval2.stval2")
|
||||
cfg.read_write()
|
||||
cfg.od.dodval1.stval1 = 'val'
|
||||
cfg.read_only()
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
raises(PropertiesOptionError, "cfg.od.dodval2.stval2")
|
||||
cfg.read_write()
|
||||
del(cfg.od.dodval1.stval1)
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "cfg.od.dodval1.stval1")
|
||||
assert cfg.cfgimpl_get_values().mandatory_warnings() == ['od.dodval1.stval1', 'od.dodval2.stval2']
|
||||
|
||||
|
||||
def test_increase_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.read_write()
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
raises(AttributeError, "cfg.od.dodval3")
|
||||
cfg.od.val1 = ['val1', 'val2', 'val3']
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
assert cfg.od.dodval3.stval3 is None
|
||||
|
||||
|
||||
def test_decrease_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', properties=('mandatory',))
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list, callback_params={'': ((val1, False),)})
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
stval1 = cfg.unwrap_from_path('od.dodval1.stval1')
|
||||
stval2 = cfg.unwrap_from_path('od.dodval2.stval2')
|
||||
cfg.read_write()
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
cfg.od.dodval2.stval2 = 'yes'
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 == 'yes'
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
assert cfg.getowner(stval2) == owner
|
||||
raises(AttributeError, "cfg.od.dodval3")
|
||||
cfg.od.val1 = ['val1']
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
raises(AttributeError, "cfg.od.dodval2")
|
||||
raises(AttributeError, "cfg.od.dodval3")
|
||||
assert cfg.getowner(stval1) == owners.default
|
||||
#FIXME
|
||||
# raises(AttributeError, "cfg.getowner(stval2)")
|
||||
raises(AttributeError, "cfg.unwrap_from_path('od.dodval2.stval2')")
|
||||
|
||||
|
||||
def test_requires_dyndescription():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st = StrOption('st', '', requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od, boolean])
|
||||
cfg = Config(od2)
|
||||
cfg.read_write()
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
#
|
||||
cfg.boolean = False
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval1.stval1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval2.stval2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
#
|
||||
cfg.boolean = True
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
#transitive
|
||||
cfg.cfgimpl_get_settings()[boolean].append('disabled')
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval1.stval1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval2.stval2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_requires_dyndescription2():
|
||||
boolean = BoolOption('boolean', '', True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list,
|
||||
requires=[{'option': boolean, 'expected': False,
|
||||
'action': 'disabled'}])
|
||||
od = OptionDescription('od', '', [dod])
|
||||
od2 = OptionDescription('od', '', [od, boolean])
|
||||
cfg = Config(od2)
|
||||
cfg.read_write()
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
#
|
||||
cfg.boolean = False
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval1.stval1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval2.stval2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
#
|
||||
cfg.boolean = True
|
||||
assert cfg.od.dodval1.stval1 is None
|
||||
assert cfg.od.dodval2.stval2 is None
|
||||
#transitive
|
||||
cfg.cfgimpl_get_settings()[boolean].append('disabled')
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval1.stval1
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
props = []
|
||||
try:
|
||||
cfg.od.dodval2.stval2
|
||||
except PropertiesOptionError as err:
|
||||
props = err.proptype
|
||||
assert props == ['disabled']
|
||||
|
||||
|
||||
def test_validator_dyndescription():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '', validator=return_true, validator_params={'': ('yes',)}, default='val')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.dodval1.stval1 == 'val'
|
||||
raises(ValueError, "cfg.od.dodval1.stval1 = 'no'")
|
||||
cfg.od.dodval1.stval1 = 'val'
|
||||
|
||||
|
||||
def test_makedict_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.make_dict() == {'od.val1': ['val1', 'val2'], 'od.dodval1.stval1': 'yes', 'od.dodval2.stval2': None}
|
||||
assert cfg.make_dict(flatten=True) == {'val1': ['val1', 'val2'], 'stval1': 'yes', 'stval2': None}
|
||||
assert cfg.make_dict(withoption='stval1') == {'od.dodval1.stval1': 'yes'}
|
||||
assert cfg.od.make_dict(withoption='stval1') == {'dodval1.stval1': 'yes'}
|
||||
assert cfg.od.dodval1.make_dict(withoption='stval1') == {'stval1': 'yes'}
|
||||
|
||||
|
||||
def test_find_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
assert cfg.find_first(byname='stval1', type_='value') == "yes"
|
||||
assert isinstance(cfg.find_first(byname='stval1', type_='option'), DynSymLinkOption)
|
||||
assert cfg.find(bytype=StrOption, type_='path') == ['od.dodval1.stval1', 'od.dodval2.stval2', 'od.val1']
|
||||
opts = cfg.find(byvalue='yes')
|
||||
assert len(opts) == 1
|
||||
assert isinstance(opts[0], DynSymLinkOption)
|
||||
assert opts[0].impl_getname() == 'stval1'
|
||||
|
||||
|
||||
def test_iter_all_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
for it in cfg.iter_all():
|
||||
assert it[0] == 'od'
|
||||
assert str(it[1]) == str(cfg.od)
|
||||
#
|
||||
list_od = []
|
||||
for it in cfg.od.iter_all():
|
||||
list_od.append(it[0])
|
||||
assert list_od == ['dodval1', 'dodval2', 'val1']
|
||||
#
|
||||
list_od = []
|
||||
for it in cfg.od.dodval1:
|
||||
list_od.append(it[0])
|
||||
assert list_od == ['stval1']
|
||||
|
||||
|
||||
def test_information_dyndescription_context():
|
||||
val1 = StrOption('val1', '', ['val1', 'val2'], multi=True)
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, val1])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
dod.impl_set_information('testod', 'val1')
|
||||
st.impl_set_information('testst', 'val2')
|
||||
cfg = Config(od2)
|
||||
cfg.impl_set_information('testcfgod', 'val3')
|
||||
assert dod.impl_get_information('testod') == 'val1'
|
||||
assert st.impl_get_information('testst') == 'val2'
|
||||
assert cfg.impl_get_information('testcfgod') == 'val3'
|
||||
|
||||
|
||||
def test_consistency_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st, st2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
st.impl_add_consistency('not_equal', st2)
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
cfg.od.dodval1.stval1 = 'yes'
|
||||
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
cfg.od.dodval2.stval2 = 'yes'
|
||||
raises(ValueError, "cfg.od.dodval2.st2val2 = 'yes'")
|
||||
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
del(cfg.od.dodval2.stval2)
|
||||
raises(ValueError, "cfg.od.dodval1.st2val1 = 'yes'")
|
||||
cfg.od.dodval2.st2val2 = 'yes'
|
||||
raises(ValueError, "cfg.od.dodval2.stval2 = 'yes'")
|
||||
|
||||
|
||||
def test_consistency_external_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st1 = StrOption('st1', '')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, st])
|
||||
raises(ConfigError, "st.impl_add_consistency('not_equal', st2)")
|
||||
|
||||
|
||||
def test_consistency_notsame_dyndescription():
|
||||
st1 = StrOption('st1', '')
|
||||
st2 = StrOption('st2', '')
|
||||
dod = DynOptionDescription('dod', '', [st1, st2], callback=return_list)
|
||||
tst1 = StrOption('tst1', '')
|
||||
tst2 = StrOption('tst2', '')
|
||||
tdod = DynOptionDescription('tdod', '', [tst1, tst2], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod, tdod])
|
||||
raises(ConfigError, "st1.impl_add_consistency('not_equal', tst1)")
|
||||
|
||||
|
||||
def test_all_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
ip = IPOption('ip', '')
|
||||
network = NetworkOption('network', '')
|
||||
netmask = NetmaskOption('netmask', '')
|
||||
ch = ChoiceOption('ch', '', ('val1', 'val2', 'val3'))
|
||||
ch1 = ChoiceOption('ch1', '', return_list)
|
||||
boo = BoolOption('boo', '')
|
||||
intr = IntOption('intr', '')
|
||||
floa = FloatOption('floa', '')
|
||||
uni = UnicodeOption('uni', '')
|
||||
port = PortOption('port', '')
|
||||
broad = BroadcastOption('broad', '')
|
||||
domain = DomainnameOption('domain', '')
|
||||
email = EmailOption('email', '')
|
||||
url = URLOption('url', '')
|
||||
username = UsernameOption('username', '')
|
||||
filename = FilenameOption('filename', '')
|
||||
dod = DynOptionDescription('dod', '', [st, ip, network, netmask, ch, ch1,
|
||||
boo, intr, floa, uni, port, broad,
|
||||
domain, email, url, username,
|
||||
filename], callback=return_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
assert cfg.dodval1.stval1 is None
|
||||
assert cfg.dodval1.ipval1 is None
|
||||
assert cfg.dodval1.networkval1 is None
|
||||
assert cfg.dodval1.netmaskval1 is None
|
||||
assert cfg.dodval1.chval1 is None
|
||||
assert cfg.dodval1.ch1val1 is None
|
||||
assert cfg.dodval1.booval1 is None
|
||||
assert cfg.dodval1.intrval1 is None
|
||||
assert cfg.dodval1.floaval1 is None
|
||||
assert cfg.dodval1.unival1 is None
|
||||
assert cfg.dodval1.portval1 is None
|
||||
assert cfg.dodval1.broadval1 is None
|
||||
assert cfg.dodval1.domainval1 is None
|
||||
assert cfg.dodval1.emailval1 is None
|
||||
assert cfg.dodval1.urlval1 is None
|
||||
assert cfg.dodval1.usernameval1 is None
|
||||
assert cfg.dodval1.filenameval1 is None
|
||||
#
|
||||
cfg.dodval1.stval1 = "no"
|
||||
cfg.dodval1.ipval1 = "1.1.1.1"
|
||||
cfg.dodval1.networkval1 = "1.1.1.0"
|
||||
cfg.dodval1.netmaskval1 = "255.255.255.0"
|
||||
cfg.dodval1.chval1 = "val1"
|
||||
cfg.dodval1.ch1val1 = "val2"
|
||||
cfg.dodval1.booval1 = True
|
||||
cfg.dodval1.intrval1 = 1
|
||||
cfg.dodval1.floaval1 = 0.1
|
||||
cfg.dodval1.unival1 = u"no"
|
||||
cfg.dodval1.portval1 = 80
|
||||
cfg.dodval1.broadval1 = "1.1.1.255"
|
||||
cfg.dodval1.domainval1 = "test.com"
|
||||
cfg.dodval1.emailval1 = "test@test.com"
|
||||
cfg.dodval1.urlval1 = "http://test.com"
|
||||
cfg.dodval1.usernameval1 = "user1"
|
||||
cfg.dodval1.filenameval1 = "/tmp"
|
||||
assert cfg.dodval1.stval1 == "no"
|
||||
assert cfg.dodval1.ipval1 == "1.1.1.1"
|
||||
assert cfg.dodval1.networkval1 == "1.1.1.0"
|
||||
assert cfg.dodval1.netmaskval1 == "255.255.255.0"
|
||||
assert cfg.dodval1.chval1 == "val1"
|
||||
assert cfg.dodval1.ch1val1 == "val2"
|
||||
assert cfg.dodval1.booval1 is True
|
||||
assert cfg.dodval1.intrval1 == 1
|
||||
assert cfg.dodval1.floaval1 == 0.1
|
||||
assert cfg.dodval1.unival1 == u"no"
|
||||
assert cfg.dodval1.portval1 == 80
|
||||
assert cfg.dodval1.broadval1 == "1.1.1.255"
|
||||
assert cfg.dodval1.domainval1 == "test.com"
|
||||
assert cfg.dodval1.emailval1 == "test@test.com"
|
||||
assert cfg.dodval1.urlval1 == "http://test.com"
|
||||
assert cfg.dodval1.usernameval1 == "user1"
|
||||
assert cfg.dodval1.filenameval1 == "/tmp"
|
||||
#
|
||||
assert cfg.dodval2.stval2 is None
|
||||
assert cfg.dodval2.ipval2 is None
|
||||
assert cfg.dodval2.networkval2 is None
|
||||
assert cfg.dodval2.netmaskval2 is None
|
||||
assert cfg.dodval2.chval2 is None
|
||||
assert cfg.dodval2.ch1val2 is None
|
||||
assert cfg.dodval2.booval2 is None
|
||||
assert cfg.dodval2.intrval2 is None
|
||||
assert cfg.dodval2.floaval2 is None
|
||||
assert cfg.dodval2.unival2 is None
|
||||
assert cfg.dodval2.portval2 is None
|
||||
assert cfg.dodval2.broadval2 is None
|
||||
assert cfg.dodval2.domainval2 is None
|
||||
assert cfg.dodval2.emailval2 is None
|
||||
assert cfg.dodval2.urlval2 is None
|
||||
assert cfg.dodval2.usernameval2 is None
|
||||
assert cfg.dodval2.filenameval2 is None
|
||||
|
||||
|
||||
def test_consistency_ip_netmask_dyndescription():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
dod = DynOptionDescription('dod', '', [a, b], callback=return_list)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
c = Config(od)
|
||||
c.dodval1.aval1 = '192.168.1.1'
|
||||
c.dodval1.bval1 = '255.255.255.0'
|
||||
c.dodval2.aval2 = '192.168.1.2'
|
||||
c.dodval2.bval2 = '255.255.255.255'
|
||||
c.dodval2.bval2 = '255.255.255.0'
|
||||
|
||||
|
||||
def test_consistency_ip_in_network_dyndescription():
|
||||
a = NetworkOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
c = IPOption('c', '')
|
||||
dod = DynOptionDescription('dod', '', [a, b, c], callback=return_list)
|
||||
c.impl_add_consistency('in_network', a, b)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
cfg.dodval1.aval1 = '192.168.1.0'
|
||||
cfg.dodval1.bval1 = '255.255.255.0'
|
||||
cfg.dodval1.cval1 = '192.168.1.1'
|
||||
|
||||
|
||||
def test_masterslaves_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [None], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == [None]
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == [None]
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st2val1 = ['no']
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1.pop(0)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
del(cfg.od.stval1.st1val1.st2val1)
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
del(cfg.od.stval1.st1val1.st1val1)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
|
||||
|
||||
def test_masterslaves_default_multi_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, default_multi='no')
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
|
||||
|
||||
def test_masterslaves_submulti_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=submulti)
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == [[]]
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st2val1[0].append('no')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == [['no']]
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
|
||||
|
||||
def test_masterslaves_consistency_ip_dyndescription():
|
||||
a = NetworkOption('net', '', multi=True)
|
||||
b = NetmaskOption('mask', '', multi=True)
|
||||
c = BroadcastOption('broad', '', multi=True)
|
||||
b.impl_add_consistency('network_netmask', a)
|
||||
c.impl_add_consistency('broadcast', a, b)
|
||||
dod = DynOptionDescription('net', '', [a, b, c], callback=return_list)
|
||||
dod.impl_set_group_type(groups.master)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
cfg.netval1.netval1 = ['192.168.1.0']
|
||||
cfg.netval1.maskval1 = ['255.255.255.0']
|
||||
cfg.netval1.broadval1 = ['192.168.1.255']
|
||||
|
||||
cfg.netval1.netval1 = ['192.168.1.0', '192.168.2.128']
|
||||
cfg.netval1.maskval1 = ['255.255.255.0', '255.255.255.128']
|
||||
cfg.netval1.broadval1 = ['192.168.1.255', '192.168.2.255']
|
||||
cfg.netval1.broadval1[1] = '192.168.2.255'
|
||||
#
|
||||
assert cfg.netval1.netval1 == ['192.168.1.0', '192.168.2.128']
|
||||
assert cfg.netval1.maskval1 == ['255.255.255.0', '255.255.255.128']
|
||||
assert cfg.netval1.broadval1 == ['192.168.1.255', '192.168.2.255']
|
||||
assert cfg.netval2.netval2 == []
|
||||
assert cfg.netval2.maskval2 == []
|
||||
assert cfg.netval2.broadval2 == []
|
||||
|
||||
|
||||
def test_masterslaves_callback_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ((st1, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': [], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': []}
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st2val1': ['yes'], 'od.stval2.st1val2.st2val2': [], 'od.stval2.st1val2.st1val2': [], 'od.stval1.st1val1.st1val1': ['yes']}
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['yes']
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st2val1 = ['no']
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1.pop(0)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
del(cfg.od.stval1.st1val1.st2val1)
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
cfg.od.stval1.st1val1.st2val1 = ['yes']
|
||||
del(cfg.od.stval1.st1val1.st1val1)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st2val1 = []
|
||||
cfg.od.stval1.st1val1.st1val1 = ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['yes']
|
||||
|
||||
|
||||
def test_masterslaves_callback_value_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'value': ('val',)})
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1[0] == 'val'
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['val']
|
||||
|
||||
|
||||
def test_masterslaves_callback_nomulti_dyndescription():
|
||||
v1 = StrOption('v1', '', "val")
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v1, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, v1])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['val']
|
||||
|
||||
|
||||
def test_masterslaves_callback_multi_dyndescription():
|
||||
v1 = StrOption('v1', '', multi=True)
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, callback=return_dynval, callback_params={'': ((v1, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, v1])
|
||||
cfg = Config(od2)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == [None]
|
||||
cfg.od.stval1.st1val1.st2val1 = ['no']
|
||||
cfg.v1 = ['no', 'no', 'no']
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes', 'yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['no', 'no']
|
||||
cfg.od.stval1.st1val1.st1val1.pop(1)
|
||||
assert cfg.od.stval1.st1val1.st1val1 == ['yes']
|
||||
assert cfg.od.stval1.st1val1.st2val1 == ['no']
|
||||
|
||||
|
||||
def test_masterslaves_callback_samegroup_dyndescription():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2, st3])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1val1 = cfg.unwrap_from_path('od.stval1.st1val1.st1val1')
|
||||
st2val1 = cfg.unwrap_from_path('od.stval1.st1val1.st2val1')
|
||||
st3val1 = cfg.unwrap_from_path('od.stval1.st1val1.st3val1')
|
||||
st1val2 = cfg.unwrap_from_path('od.stval2.st1val2.st1val2')
|
||||
st2val2 = cfg.unwrap_from_path('od.stval2.st1val2.st2val2')
|
||||
st3val2 = cfg.unwrap_from_path('od.stval2.st1val2.st3val2')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': [],
|
||||
'od.stval1.st1val1.st2val1': [],
|
||||
'od.stval1.st1val1.st3val1': [],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.od.stval1.st1val1.st1val1 == []
|
||||
assert cfg.od.stval1.st1val1.st2val1 == []
|
||||
assert cfg.od.stval1.st1val1.st3val1 == []
|
||||
assert cfg.od.stval2.st1val2.st1val2 == []
|
||||
assert cfg.od.stval2.st1val2.st2val2 == []
|
||||
assert cfg.od.stval2.st1val2.st3val2 == []
|
||||
assert cfg.getowner(st1val1) == owners.default
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
assert cfg.getowner(st3val1) == owners.default
|
||||
assert cfg.getowner(st3val2) == owners.default
|
||||
##
|
||||
cfg.od.stval1.st1val1.st1val1.append('yes')
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': [None],
|
||||
'od.stval1.st1val1.st3val1': [None],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owners.default
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
assert cfg.getowner(st3val1) == owners.default
|
||||
assert cfg.getowner(st3val2) == owners.default
|
||||
#
|
||||
cfg.od.stval1.st1val1.st2val1[0] = 'yes'
|
||||
assert cfg.make_dict() == {'od.stval1.st1val1.st1val1': ['yes'],
|
||||
'od.stval1.st1val1.st2val1': ['yes'],
|
||||
'od.stval1.st1val1.st3val1': ['yes'],
|
||||
'od.stval2.st1val2.st1val2': [],
|
||||
'od.stval2.st1val2.st2val2': [],
|
||||
'od.stval2.st1val2.st3val2': []}
|
||||
assert cfg.getowner(st1val1) == owner
|
||||
assert cfg.getowner(st1val2) == owners.default
|
||||
assert cfg.getowner(st2val1) == owner
|
||||
assert cfg.getowner(st2val2) == owners.default
|
||||
assert cfg.getowner(st3val1) == owners.default
|
||||
assert cfg.getowner(st3val2) == owners.default
|
||||
|
||||
|
||||
def test_state_config():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
dod1 = DynOptionDescription('dod1', '', [a, b], callback=return_list)
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od1 = OptionDescription('od1', '', [dod1])
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st3 = StrOption('st3', "", multi=True, callback=return_dynval, callback_params={'': ((st2, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2, st3])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = DynOptionDescription('st', '', [stm], callback=return_list)
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='29090938')
|
||||
except ValueError:
|
||||
cfg = Config(od2, session_id='29090938')
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
|
||||
try:
|
||||
delete_session('config', '29090938')
|
||||
except ConfigError:
|
||||
pass
|
||||
|
||||
|
||||
def test_invalid_conflict_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_list)
|
||||
dodinvalid = StrOption('dodinvalid', '')
|
||||
raises(ConflictError, "OptionDescription('od', '', [dod, dodinvalid])")
|
||||
|
||||
|
||||
def test_invalid_subod_dyndescription():
|
||||
st2 = StrOption('st2', '')
|
||||
od1 = OptionDescription('od1', '', [st2])
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
|
||||
|
||||
|
||||
def test_invalid_subdynod_dyndescription():
|
||||
st2 = StrOption('st2', '')
|
||||
od1 = DynOptionDescription('od1', '', [st2], callback=return_list)
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [od1], callback=return_list)")
|
||||
|
||||
|
||||
def test_invalid_symlink_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = SymLinkOption('st2', st)
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2], callback=return_list)")
|
||||
|
||||
|
||||
def test_nocallback_dyndescription():
|
||||
st = StrOption('st', '')
|
||||
st2 = StrOption('st2', st)
|
||||
raises(ConfigError, "DynOptionDescription('dod', '', [st, st2])")
|
||||
|
||||
|
||||
def test_invalid_samevalue_dyndescription():
|
||||
def return_same_list():
|
||||
return ['val1', 'val1']
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_same_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
raises(ConfigError, "print cfg")
|
||||
|
||||
|
||||
def test_invalid_name_dyndescription():
|
||||
def return_same_list():
|
||||
return ['---', ' ']
|
||||
st = StrOption('st', '')
|
||||
dod = DynOptionDescription('dod', '', [st], callback=return_same_list)
|
||||
od = OptionDescription('od', '', [dod])
|
||||
cfg = Config(od)
|
||||
raises(ValueError, "print cfg")
|
@ -46,9 +46,12 @@ def a_func():
|
||||
def test_option_valid_name():
|
||||
IntOption('test', '')
|
||||
raises(ValueError, 'IntOption(1, "")')
|
||||
raises(ValueError, 'IntOption("1test", "")')
|
||||
IntOption("test1", "")
|
||||
raises(ValueError, 'IntOption("impl_test", "")')
|
||||
raises(ValueError, 'IntOption("_test", "")')
|
||||
raises(ValueError, 'IntOption("unwrap_from_path", "")')
|
||||
raises(ValueError, 'IntOption(" ", "")')
|
||||
|
||||
|
||||
def test_option_with_callback():
|
||||
|
@ -51,30 +51,6 @@ def is_config(config, **kwargs):
|
||||
return 'no'
|
||||
|
||||
|
||||
def make_description():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
gcdummy = BoolOption('dummy', 'dummy', default=False)
|
||||
objspaceoption = ChoiceOption('objspace', 'Object space',
|
||||
('std', 'thunk'), 'std')
|
||||
booloption = BoolOption('bool', 'Test boolean option', default=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
intoption2 = IntOption('int', 'Test int option', default=0)
|
||||
floatoption = FloatOption('float', 'Test float option', default=2.3)
|
||||
stroption = StrOption('str', 'Test string option', default="abc")
|
||||
boolop = BoolOption('boolop', 'Test boolean option op', default=True)
|
||||
wantref_option = BoolOption('wantref', 'Test requires', default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
wantframework_option = BoolOption('wantframework', 'Test requires',
|
||||
default=False,
|
||||
requires=({'option': boolop, 'expected': True, 'action': 'hidden'},))
|
||||
gcgroup = OptionDescription('gc', '', [gcoption, gcdummy, floatoption, intoption2])
|
||||
descr = OptionDescription('constraints', '', [gcgroup, booloption, objspaceoption,
|
||||
wantref_option, stroption,
|
||||
wantframework_option,
|
||||
intoption, boolop])
|
||||
return descr
|
||||
|
||||
|
||||
def make_description_duplicates():
|
||||
gcoption = ChoiceOption('name', 'GC name', ('ref', 'framework'), 'ref')
|
||||
## dummy 1
|
||||
@ -929,3 +905,26 @@ def test_callback_multi_list_params_key():
|
||||
cfg = Config(maconfig)
|
||||
cfg.read_write()
|
||||
assert cfg.val2.val2 == ['val', 'val']
|
||||
|
||||
|
||||
def test_masterslaves_callback_description():
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True, callback=return_value, callback_params={'': ((st1, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = OptionDescription('st', '', [stm])
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od])
|
||||
cfg = Config(od2)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
st1 = cfg.unwrap_from_path('od.st.st1.st1')
|
||||
st2 = cfg.unwrap_from_path('od.st.st1.st2')
|
||||
assert cfg.od.st.st1.st1 == []
|
||||
assert cfg.od.st.st1.st2 == []
|
||||
assert cfg.getowner(st1) == owners.default
|
||||
assert cfg.getowner(st2) == owners.default
|
||||
##
|
||||
cfg.od.st.st1.st1.append('yes')
|
||||
assert cfg.od.st.st1.st1 == ['yes']
|
||||
assert cfg.od.st.st1.st2 == ['yes']
|
||||
assert cfg.getowner(st1) == owner
|
||||
|
@ -1,9 +1,10 @@
|
||||
import autopath
|
||||
|
||||
from tiramisu.option import BoolOption, UnicodeOption, SymLinkOption, \
|
||||
IntOption, OptionDescription
|
||||
IntOption, IPOption, NetmaskOption, StrOption, OptionDescription, \
|
||||
DynOptionDescription
|
||||
from tiramisu.config import Config, GroupConfig, MetaConfig
|
||||
from tiramisu.setting import owners
|
||||
from tiramisu.setting import groups, owners
|
||||
from tiramisu.storage import delete_session
|
||||
from tiramisu.error import ConfigError
|
||||
from pickle import dumps, loads
|
||||
@ -93,10 +94,35 @@ def _diff_opt(opt1, opt2):
|
||||
assert val1[key][idx] == val2[key][idx]
|
||||
else:
|
||||
assert val1 == val2
|
||||
elif attr == '_master_slaves':
|
||||
assert val1.master.impl_getname() == val2.master.impl_getname()
|
||||
sval1 = [opt.impl_getname() for opt in val1.slaves]
|
||||
sval2 = [opt.impl_getname() for opt in val2.slaves]
|
||||
assert sval1 == sval2
|
||||
elif attr == '_subdyn':
|
||||
try:
|
||||
assert val1.impl_getname() == val2.impl_getname()
|
||||
except AttributeError:
|
||||
assert val1 == val2
|
||||
else:
|
||||
assert val1 == val2
|
||||
|
||||
|
||||
def _diff_opts(opt1, opt2):
|
||||
_diff_opt(opt1, opt2)
|
||||
if isinstance(opt1, OptionDescription) or isinstance(opt1, DynOptionDescription):
|
||||
children1 = set([opt.impl_getname() for opt in opt1._impl_getchildren(dyn=False)])
|
||||
children2 = set([opt.impl_getname() for opt in opt2._impl_getchildren(dyn=False)])
|
||||
diff1 = children1 - children2
|
||||
diff2 = children2 - children1
|
||||
if diff1 != set():
|
||||
raise Exception('more attribute in opt1 {0}'.format(list(diff1)))
|
||||
if diff2 != set():
|
||||
raise Exception('more attribute in opt2 {0}'.format(list(diff2)))
|
||||
for child in children1:
|
||||
_diff_opts(opt1._getattr(child, dyn=False), opt2._getattr(child, dyn=False))
|
||||
|
||||
|
||||
def _diff_conf(cfg1, cfg2):
|
||||
attr1 = set(_get_slots(cfg1))
|
||||
attr2 = set(_get_slots(cfg2))
|
||||
@ -148,11 +174,7 @@ def test_diff_opt():
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opt(o1, q)
|
||||
_diff_opt(o1.o, q.o)
|
||||
_diff_opt(o1.o.b, q.o.b)
|
||||
_diff_opt(o1.o.u, q.o.u)
|
||||
_diff_opt(o1.o.s, q.o.s)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_only_optiondescription():
|
||||
@ -172,11 +194,7 @@ def test_diff_opt_cache():
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opt(o1, q)
|
||||
_diff_opt(o1.o, q.o)
|
||||
_diff_opt(o1.o.b, q.o.b)
|
||||
_diff_opt(o1.o.u, q.o.u)
|
||||
_diff_opt(o1.o.s, q.o.s)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_diff_opt_callback():
|
||||
@ -190,11 +208,7 @@ def test_diff_opt_callback():
|
||||
|
||||
a = dumps(o1)
|
||||
q = loads(a)
|
||||
_diff_opt(o1, q)
|
||||
_diff_opt(o1.o, q.o)
|
||||
_diff_opt(o1.o.b, q.o.b)
|
||||
_diff_opt(o1.o.b2, q.o.b2)
|
||||
_diff_opt(o1.o.b3, q.o.b3)
|
||||
_diff_opts(o1, q)
|
||||
|
||||
|
||||
def test_no_state_attr():
|
||||
@ -224,6 +238,7 @@ def test_state_config():
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', '29090931')
|
||||
@ -231,6 +246,35 @@ def test_state_config():
|
||||
pass
|
||||
|
||||
|
||||
def test_state_config2():
|
||||
a = IPOption('a', '')
|
||||
b = NetmaskOption('b', '')
|
||||
dod1 = OptionDescription('dod1', '', [a, b])
|
||||
b.impl_add_consistency('ip_netmask', a)
|
||||
od1 = OptionDescription('od1', '', [dod1])
|
||||
st1 = StrOption('st1', "", multi=True)
|
||||
st2 = StrOption('st2', "", multi=True)
|
||||
st3 = StrOption('st3', "", multi=True, callback=return_value, callback_params={'': ((st2, False),)})
|
||||
stm = OptionDescription('st1', '', [st1, st2, st3])
|
||||
stm.impl_set_group_type(groups.master)
|
||||
st = OptionDescription('st', '', [stm])
|
||||
od = OptionDescription('od', '', [st])
|
||||
od2 = OptionDescription('od', '', [od, od1])
|
||||
try:
|
||||
cfg = Config(od2, persistent=True, session_id='29090939')
|
||||
except ValueError:
|
||||
cfg = Config(od2, session_id='29090939')
|
||||
cfg._impl_test = True
|
||||
a = dumps(cfg)
|
||||
q = loads(a)
|
||||
_diff_opts(cfg.cfgimpl_get_description(), q.cfgimpl_get_description())
|
||||
_diff_conf(cfg, q)
|
||||
try:
|
||||
delete_session('config', '29090939')
|
||||
except ConfigError:
|
||||
pass
|
||||
|
||||
|
||||
def test_state_properties():
|
||||
val1 = BoolOption('val1', "")
|
||||
maconfig = OptionDescription('rootconfig', '', [val1])
|
||||
|
Reference in New Issue
Block a user