corrections in dynoption/masterslaves
This commit is contained in:
@ -1,206 +0,0 @@
|
||||
"""test consistencies about multi and submulti"""
|
||||
from py.test import raises
|
||||
from .autopath import do_autopath
|
||||
do_autopath()
|
||||
from tiramisu.setting import groups
|
||||
from tiramisu import Config, StrOption, IntOption, OptionDescription, MasterSlaves, getapi, \
|
||||
submulti, undefined
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
||||
|
||||
def return_val(val=None):
|
||||
if val is None:
|
||||
return 'val'
|
||||
else:
|
||||
return val
|
||||
|
||||
|
||||
def return_list(value=None):
|
||||
return ['val', 'val']
|
||||
|
||||
|
||||
def return_list2(value=None):
|
||||
return [['val', 'val']]
|
||||
|
||||
|
||||
def test_multi_unique():
|
||||
int_ = IntOption('int', '', multi=True, unique=True)
|
||||
od_ = OptionDescription('od', '', [int_])
|
||||
cfg = Config(od_)
|
||||
api = getapi(cfg)
|
||||
assert api.option('int').value.get() == []
|
||||
value = [0]
|
||||
api.option('int').value.set(value)
|
||||
assert api.option('int').value.get() == value
|
||||
value.append(1)
|
||||
assert api.option('int').value.get() == [0]
|
||||
raises(ValueError, "api.option('int').value.set([0, 0])")
|
||||
raises(ValueError, "api.option('int').value.set([1, 0, 2, 3, 4, 5, 6, 0, 7])")
|
||||
|
||||
|
||||
def test_multi_none():
|
||||
str_ = StrOption('str', '', multi=True)
|
||||
od_ = OptionDescription('od', '', [str_])
|
||||
cfg = Config(od_)
|
||||
cfg.read_only()
|
||||
api = getapi(cfg)
|
||||
assert api.option('str').value.get() == []
|
||||
cfg.read_write()
|
||||
api.option('str').value.set([None])
|
||||
assert api.option('str').value.get() == [None]
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "api.option('str').value.get()")
|
||||
cfg.read_write()
|
||||
api.option('str').value.set([''])
|
||||
assert api.option('str').value.get() == ['']
|
||||
cfg.read_only()
|
||||
raises(PropertiesOptionError, "api.option('str').value.get()")
|
||||
|
||||
|
||||
# ______________ submulti ______________
|
||||
|
||||
def test_append_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od_ = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
cfg = Config(od_)
|
||||
api = getapi(cfg)
|
||||
#FIXME
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.isdefault()
|
||||
api.option('multi').value.set([undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
value = api.option('multi').value.get()
|
||||
assert value == [[]]
|
||||
value.append(['no'])
|
||||
assert api.option('multi').value.get() == [[]]
|
||||
api.option('multi').value.set(value)
|
||||
assert api.option('multi').value.get() == [[], ['no']]
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
assert api.option('multi2').owner.isdefault()
|
||||
api.option('multi2').value.set([undefined])
|
||||
assert api.option('multi2').owner.get() == owner
|
||||
assert api.option('multi2').value.get() == [['yes']]
|
||||
api.option('multi2').value.set([['yes'], ['no']])
|
||||
assert api.option('multi2').value.get() == [['yes'], ['no']]
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.isdefault()
|
||||
api.option('multi3').value.set([['yes'], undefined])
|
||||
assert api.option('multi3').owner.get() == owner
|
||||
assert api.option('multi3').value.get() == [['yes'], []]
|
||||
api.option('multi3').value.set([['yes'], [], ['no']])
|
||||
assert api.option('multi3').value.get() == [['yes'], [], ['no']]
|
||||
|
||||
|
||||
def test_append_unvalide_submulti():
|
||||
multi = StrOption('multi', '', multi=submulti)
|
||||
multi2 = StrOption('multi2', '', default_multi=['yes'], multi=submulti)
|
||||
multi3 = StrOption('multi3', '', default=[['yes']], multi=submulti)
|
||||
od_ = OptionDescription('od', '', [multi, multi2, multi3])
|
||||
cfg = Config(od_)
|
||||
api = getapi(cfg)
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.isdefault()
|
||||
raises(ValueError, "api.option('multi').value.set([1])")
|
||||
assert api.option('multi').value.get() == []
|
||||
assert api.option('multi').owner.isdefault()
|
||||
#
|
||||
assert api.option('multi2').value.get() == []
|
||||
raises(ValueError, "api.option('multi2').value.set('no')")
|
||||
assert api.option('multi2').owner.isdefault()
|
||||
assert api.option('multi2').value.get() == []
|
||||
#
|
||||
assert api.option('multi3').value.get() == [['yes']]
|
||||
assert api.option('multi3').owner.isdefault()
|
||||
|
||||
|
||||
def test_submulti_unique():
|
||||
int_ = IntOption('int', '', multi=submulti, unique=True)
|
||||
od_ = OptionDescription('od', '', [int_])
|
||||
cfg = Config(od_)
|
||||
api = getapi(cfg)
|
||||
assert api.option('int').value.get() == []
|
||||
api.option('int').value.set([[0]])
|
||||
assert api.option('int').value.get() == [[0]]
|
||||
raises(ValueError, "api.option('int').value.set([[0, 0]])")
|
||||
api.option('int').value.set([[0], [0]])
|
||||
raises(ValueError, "api.option('int').value.set([[0], [1, 0, 2, 3, 4, 5, 6, 0, 7]])")
|
||||
|
||||
|
||||
def test_callback_reset():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_val)
|
||||
od_ = OptionDescription('od', '', [multi])
|
||||
cfg = Config(od_)
|
||||
cfg.read_write()
|
||||
api = getapi(cfg)
|
||||
#FIXME
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
assert api.option('multi').owner.isdefault()
|
||||
api.option('multi').value.set([['val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val'], ['val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.isdefault()
|
||||
assert api.option('multi').value.get() == [['val']]
|
||||
api.option('multi').value.set([['val1']])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val1']]
|
||||
|
||||
|
||||
def test_callback_submulti_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list)
|
||||
od_ = OptionDescription('od', '', [multi])
|
||||
cfg = Config(od_)
|
||||
cfg.read_write()
|
||||
api = getapi(cfg)
|
||||
owner = cfg.cfgimpl_get_settings().getowner()
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.isdefault()
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.set([['val', 'val'], undefined, undefined])
|
||||
assert api.option('multi').value.get() == [['val', 'val'], ['val', 'val'], ['val', 'val']]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.isdefault()
|
||||
|
||||
|
||||
def test_callback_submulti_list_list():
|
||||
multi = StrOption('multi', '', multi=submulti, callback=return_list2)
|
||||
od = OptionDescription('od', '', [multi])
|
||||
cfg = Config(od)
|
||||
cfg.read_write()
|
||||
api = getapi(cfg)
|
||||
owner = api.owner.get()
|
||||
assert owner == 'user'
|
||||
assert api.option('multi').value.get() == [['val', 'val']]
|
||||
assert api.option('multi').owner.isdefault()
|
||||
api.option('multi').value.set([['val', 'val'], undefined])
|
||||
assert api.option('multi').owner.get() == owner
|
||||
assert api.option('multi').value.get() == [['val', 'val'], []]
|
||||
api.option('multi').value.reset()
|
||||
assert api.option('multi').owner.isdefault()
|
||||
|
||||
|
||||
#FIXME
|
||||
#def test_multi_submulti_meta():
|
||||
# multi = StrOption('multi', '', multi=submulti)
|
||||
# od = OptionDescription('od', '', [multi])
|
||||
# conf1 = Config(od, session_id='conf1')
|
||||
# conf1.read_write()
|
||||
# conf2 = Config(od, session_id='conf2')
|
||||
# conf2.read_write()
|
||||
# meta = MetaConfig([conf1, conf2])
|
||||
# meta.read_write()
|
||||
# meta.multi = [['val']]
|
||||
# assert meta.multi == [['val']]
|
||||
# multi = conf1.multi[0]
|
||||
# multi.append()
|
||||
# assert conf1.multi == [['val', None]]
|
||||
# assert meta.multi == [['val']]
|
@ -343,7 +343,7 @@ def test_validator_warning():
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt2').value.set('val')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt2
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@ -353,7 +353,7 @@ def test_validator_warning():
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('opt3').value.set(['val', 'val1'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == opt3
|
||||
assert w[0].message.opt() == opt3
|
||||
assert str(w[0].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@ -364,9 +364,9 @@ def test_validator_warning():
|
||||
api.option('opt2').value.set('val')
|
||||
api.option('opt3').value.set(['val', 'val1', 'val'])
|
||||
assert len(w) == 2
|
||||
assert w[0].message.opt == opt2
|
||||
assert w[0].message.opt() == opt2
|
||||
assert str(w[0].message) == msg_err.format('val', opt2._display_name, 'opt2', 'test error return_false')
|
||||
assert w[1].message.opt == opt3
|
||||
assert w[1].message.opt() == opt3
|
||||
assert str(w[1].message) == msg_err.format('val1', opt3._display_name, 'opt3', 'test error')
|
||||
|
||||
|
||||
@ -420,27 +420,27 @@ def test_validator_warning_master_slave():
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('val1')
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == netmask_admin_eth0
|
||||
assert w[0].message.opt() == netmask_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val1', netmask_admin_eth0._display_name, display_name_netmask, 'test error')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val'])
|
||||
assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val', 'val1', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val', 'val1'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
#
|
||||
warnings.resetwarnings()
|
||||
@ -448,7 +448,7 @@ def test_validator_warning_master_slave():
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['val1', 'val1', 'val'])
|
||||
#FIXME
|
||||
#assert len(w) == 1
|
||||
assert w[0].message.opt == ip_admin_eth0
|
||||
assert w[0].message.opt() == ip_admin_eth0
|
||||
assert str(w[0].message) == msg_err.format('val', ip_admin_eth0._display_name, display_name_ip, 'test error return_false')
|
||||
|
||||
|
||||
|
@ -222,6 +222,33 @@ def test_groups_with_master_hidden_in_config2():
|
||||
assert api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() is None
|
||||
|
||||
|
||||
def test_groups_with_master_reset_empty():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od_ = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od_))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()")
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
|
||||
|
||||
def test_groups_with_master_reset_out_of_range():
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True)
|
||||
netmask_admin_eth0 = StrOption('netmask_admin_eth0', "masque du sous-réseau", multi=True)
|
||||
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||
od_ = OptionDescription('root', '', [interface1])
|
||||
api = getapi(Config(od_))
|
||||
api.property.read_write()
|
||||
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1'])
|
||||
api.forcepermissive.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')
|
||||
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||
raises(SlaveError, "api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.reset()")
|
||||
raises(IndexError, "api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)")
|
||||
|
||||
|
||||
def test_groups_with_master_hidden_in_config3():
|
||||
#if master is hidden, slave are hidden too
|
||||
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=True, properties=('hidden',))
|
||||
|
Reference in New Issue
Block a user