submulti
This commit is contained in:
parent
c086f6dc0f
commit
16a160340c
|
@ -0,0 +1,302 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from .autopath import do_autopath
|
||||||
|
do_autopath()
|
||||||
|
|
||||||
|
from py.test import raises
|
||||||
|
|
||||||
|
from tiramisu.error import ConfigError
|
||||||
|
from tiramisu.config import Config
|
||||||
|
from tiramisu.option import BoolOption, OptionDescription, MasterSlaves
|
||||||
|
from tiramisu.setting import groups, owners
|
||||||
|
from tiramisu.storage import list_sessions, delete_session
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_persistent():
|
||||||
|
b = BoolOption('b', '')
|
||||||
|
o = OptionDescription('od', '', [b])
|
||||||
|
Config(o, session_id='test_non_persistent')
|
||||||
|
|
||||||
|
|
||||||
|
#def test_list():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# c = Config(o, session_id='test_non_persistent')
|
||||||
|
# c.cfgimpl_get_settings().remove('cache')
|
||||||
|
# c.b = True
|
||||||
|
# assert 'test_non_persistent' in list_sessions('config')
|
||||||
|
# del(c)
|
||||||
|
# assert 'test_non_persistent' not in list_sessions('config')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_persistent():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_delete_not_persistent():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# raises(ValueError, "delete_session('option', 'test_persistent')")
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_list_sessions_persistent():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.b = True
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert 'test_persistent' in list_sessions('config')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_delete_session_persistent():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert 'test_persistent' in list_sessions('config')
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
# assert 'test_persistent' not in list_sessions('config')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_persistent_retrieve():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert c.b is None
|
||||||
|
# c.b = True
|
||||||
|
# assert c.b is True
|
||||||
|
# del(c)
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.b is True
|
||||||
|
# assert 'test_persistent' in list_sessions('config')
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.b is None
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_two_persistent():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# c.cfgimpl_get_settings().remove('cache')
|
||||||
|
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c2.cfgimpl_get_settings().remove('cache')
|
||||||
|
# assert c.b is None
|
||||||
|
# assert c2.b is None
|
||||||
|
# c.b = False
|
||||||
|
# assert c.b is False
|
||||||
|
# assert c2.b is False
|
||||||
|
# c2.b = True
|
||||||
|
# assert c.b is True
|
||||||
|
# assert c2.b is True
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_persistent_retrieve_owner():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert c.getowner(b) == owners.default
|
||||||
|
# c.b = True
|
||||||
|
# assert c.b is True
|
||||||
|
# assert c.getowner(b) == owners.user
|
||||||
|
# owners.addowner('persistentowner')
|
||||||
|
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||||
|
# assert c.getowner(b) == owners.persistentowner
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.cfgimpl_get_values().setowner(b, owners.persistentowner)
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.b is None
|
||||||
|
# assert c.getowner(b) == owners.default
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_persistent_retrieve_owner_masterslaves():
|
||||||
|
# a = BoolOption('a', '', multi=True)
|
||||||
|
# b = BoolOption('b', '', multi=True)
|
||||||
|
# o = MasterSlaves('a', '', [a, b])
|
||||||
|
# #o.impl_set_group_type(groups.master)
|
||||||
|
# o1 = OptionDescription('a', '', [o])
|
||||||
|
# try:
|
||||||
|
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert c.getowner(a) == owners.default
|
||||||
|
# assert c.getowner(b) == owners.default
|
||||||
|
# c.a.a = [True]
|
||||||
|
# c.a.a.append(False)
|
||||||
|
# c.a.b[1] = True
|
||||||
|
# assert c.getowner(a) == owners.user
|
||||||
|
# assert c.getowner(b, 0) == owners.default
|
||||||
|
# assert c.getowner(b, 1) == owners.user
|
||||||
|
# owners.addowner('persistentowner2')
|
||||||
|
# c.cfgimpl_get_values().setowner(b, owners.persistentowner2, 1)
|
||||||
|
# c.a.b[0] = True
|
||||||
|
# assert c.getowner(b, 0) == owners.user
|
||||||
|
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.getowner(b, 0) == owners.user
|
||||||
|
# assert c.getowner(b, 1) == owners.persistentowner2
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o1, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.a.b == []
|
||||||
|
# assert c.getowner(b) == owners.default
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_two_persistent_owner():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.cfgimpl_get_settings().remove('cache')
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c2.cfgimpl_get_settings().remove('cache')
|
||||||
|
# assert c.getowner(b) == owners.default
|
||||||
|
# assert c2.getowner(b) == owners.default
|
||||||
|
# c.b = False
|
||||||
|
# assert c.getowner(b) == owners.user
|
||||||
|
# assert c2.getowner(b) == owners.user
|
||||||
|
# owners.addowner('persistent')
|
||||||
|
# c.cfgimpl_get_values().setowner(b, owners.persistent)
|
||||||
|
# assert c.getowner(b) == owners.persistent
|
||||||
|
# assert c2.getowner(b) == owners.persistent
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_create_persistent_retrieve_information():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# c.impl_set_information('info', 'string')
|
||||||
|
# assert c.impl_get_information('info') == 'string'
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.impl_get_information('info') == 'string'
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
# #
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# assert c.impl_get_information('info', None) == None
|
||||||
|
# delete_session('config', c.impl_getsessionid())
|
||||||
|
# del(c)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_two_persistent_information():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.cfgimpl_get_settings().remove('cache')
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# c.impl_set_information('info', 'string')
|
||||||
|
# assert c.impl_get_information('info') == 'string'
|
||||||
|
# c2 = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c2.cfgimpl_get_settings().remove('cache')
|
||||||
|
# c2.cfgimpl_get_settings().remove('cache')
|
||||||
|
# assert c2.impl_get_information('info') == 'string'
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_two_different_persistents():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.cfgimpl_get_settings().remove('cache')
|
||||||
|
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||||
|
# d.cfgimpl_get_settings().remove('cache')
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# c.cfgimpl_get_settings()[b].append('test')
|
||||||
|
# assert str(c.cfgimpl_get_settings()[b]) in ["['test']", "[u'test']"]
|
||||||
|
# assert str(d.cfgimpl_get_settings()[b]) == "[]"
|
||||||
|
# assert c.b is None
|
||||||
|
# assert d.b is None
|
||||||
|
# c.b = True
|
||||||
|
# assert c.b == True
|
||||||
|
# assert d.b is None
|
||||||
|
#
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
# delete_session('config', 'test_persistent2')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_two_different_information():
|
||||||
|
# b = BoolOption('b', '')
|
||||||
|
# o = OptionDescription('od', '', [b])
|
||||||
|
# try:
|
||||||
|
# c = Config(o, session_id='test_persistent', persistent=True)
|
||||||
|
# c.impl_set_information('a', 'a')
|
||||||
|
# d = Config(o, session_id='test_persistent2', persistent=True)
|
||||||
|
# d.impl_set_information('a', 'b')
|
||||||
|
# except ValueError:
|
||||||
|
# # storage is not persistent
|
||||||
|
# pass
|
||||||
|
# else:
|
||||||
|
# assert c.impl_get_information('a') == 'a'
|
||||||
|
# assert d.impl_get_information('a') == 'b'
|
||||||
|
#
|
||||||
|
# delete_session('config', 'test_persistent')
|
||||||
|
# delete_session('config', 'test_persistent2')
|
|
@ -0,0 +1,416 @@
|
||||||
|
# coding: utf-8
|
||||||
|
from .autopath import do_autopath
|
||||||
|
do_autopath()
|
||||||
|
from py.test import raises
|
||||||
|
|
||||||
|
|
||||||
|
from tiramisu.setting import groups, owners
|
||||||
|
from tiramisu import StrOption, IntOption, OptionDescription, submulti, MasterSlaves, Config, \
|
||||||
|
MetaConfig, getapi, undefined
|
||||||
|
from tiramisu.error import SlaveError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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_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])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi3').value.get() == [['yes']]
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
api.option('multi').value.set([undefined])
|
||||||
|
assert api.option('multi').owner.get() == owner
|
||||||
|
assert api.option('multi').value.get() == [[]]
|
||||||
|
api.option('multi').value.set([undefined, ['no']])
|
||||||
|
assert api.option('multi').value.get() == [[], ['no']]
|
||||||
|
#
|
||||||
|
assert api.option('multi2').value.get() == []
|
||||||
|
assert api.option('multi2').owner.get() == owners.default
|
||||||
|
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([undefined, ['no']])
|
||||||
|
assert api.option('multi2').value.get() == [['yes'], ['no']]
|
||||||
|
#
|
||||||
|
assert api.option('multi3').value.get() == [['yes']]
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
api.option('multi3').value.set([undefined, undefined])
|
||||||
|
assert api.option('multi3').owner.get() == owner
|
||||||
|
assert api.option('multi3').value.get() == [['yes'], []]
|
||||||
|
api.option('multi3').value.set([undefined, undefined, ['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])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
raises(ValueError, "api.option('multi').value.set([[1]])")
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
#
|
||||||
|
assert api.option('multi2').value.get() == []
|
||||||
|
raises(ValueError, "api.option('multi2').value.set(['no'])")
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi2').value.get() == []
|
||||||
|
#
|
||||||
|
assert api.option('multi3').value.get() == [['yes']]
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
raises(ValueError, "api.option('multi3').value.set([[1]])")
|
||||||
|
assert api.option('multi3').value.get() == [['yes']]
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
def test_pop_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])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
api.option('multi').value.set([['no', 'yes'], ['peharps']])
|
||||||
|
assert api.option('multi').owner.get() == owner
|
||||||
|
assert api.option('multi').value.get() == [['no', 'yes'], ['peharps']]
|
||||||
|
#
|
||||||
|
assert api.option('multi3').value.get() == [['yes']]
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
api.option('multi3').value.set([])
|
||||||
|
assert api.option('multi').owner.get() == owner
|
||||||
|
assert api.option('multi3').value.get() == []
|
||||||
|
api.option('multi3').value.reset()
|
||||||
|
assert api.option('multi3').owner.get() == owners.default
|
||||||
|
api.option('multi3').value.set([[]])
|
||||||
|
assert api.option('multi3').owner.get() == owner
|
||||||
|
assert api.option('multi3').value.get() == [[]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_submulti_str():
|
||||||
|
multi = StrOption('multi', '', multi=submulti, callback=return_val)
|
||||||
|
od = OptionDescription('od', '', [multi])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi').value.get() == [['val']]
|
||||||
|
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.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_submulti_list():
|
||||||
|
multi = StrOption('multi', '', multi=submulti, callback=return_list)
|
||||||
|
od = OptionDescription('od', '', [multi])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').value.get() == [['val', 'val']]
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
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.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_submulti_list_list():
|
||||||
|
multi = StrOption('multi', '', multi=submulti, callback=return_list2)
|
||||||
|
od = OptionDescription('od', '', [multi])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').value.get() == [['val', 'val']]
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
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.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
def test_groups_with_master_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
|
|
||||||
|
|
||||||
|
def test_groups_with_master_in_config_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
Config(interface1)
|
||||||
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_with_master_and_slaves_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.147"])
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == []
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||||
|
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set('255.255.255.0')")
|
||||||
|
raises(ValueError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set([['255.255.255.0']])")
|
||||||
|
|
||||||
|
|
||||||
|
def test_reset_values_with_master_and_slaves_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||||
|
#
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owner
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_with_master_and_slaves_slave_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
raises(IndexError, "api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])")
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0', '255.255.255.0'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == []
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_with_master_and_slaves_master_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145"])
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(["192.168.230.145", "192.168.230.145"])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['255.255.255.0'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.set(['255.255.255.0'])
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == ['255.255.255.0']
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == ["192.168.230.145"]
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == ['255.255.255.0']
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_with_master_owner_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.get() == owners.default
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.reset()
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owners.default
|
||||||
|
|
||||||
|
|
||||||
|
def test_values_with_master_disabled_submulti():
|
||||||
|
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=submulti)
|
||||||
|
interface1 = MasterSlaves('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.reset()
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145', '192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(1)
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||||
|
|
||||||
|
#delete with value in disabled var
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0').property.pop('disabled')
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.set(['192.168.230.145'])
|
||||||
|
api.option('ip_admin_eth0.netmask_admin_eth0').property.add('disabled')
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.pop(0)
|
||||||
|
|
||||||
|
|
||||||
|
def test__master_is_submulti():
|
||||||
|
ip_admin_eth0 = StrOption('ip_admin_eth0', "ip réseau autorisé", multi=submulti)
|
||||||
|
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])
|
||||||
|
#interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [interface1])
|
||||||
|
api = getapi(Config(maconfig))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert interface1.impl_get_group_type() == groups.master
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.isdefault()
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"]])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145"]]
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').owner.get() == owner
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).owner.isdefault()
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145"], ["192.168.230.147"]])
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 0).value.get() == None
|
||||||
|
assert api.option('ip_admin_eth0.netmask_admin_eth0', 1).value.get() == None
|
||||||
|
api.option('ip_admin_eth0.ip_admin_eth0').value.set([["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]])
|
||||||
|
assert api.option('ip_admin_eth0.ip_admin_eth0').value.get() == [["192.168.230.145", '192.168.1.1'], ["192.168.230.147"]]
|
||||||
|
raises(ValueError, "api.option('ip_admin_eth0.ip_admin_eth0').value.set(['192.168.1.1', '192.168.1.1'])")
|
||||||
|
|
||||||
|
|
||||||
|
def test_callback_submulti():
|
||||||
|
multi = StrOption('multi', '', multi=submulti)
|
||||||
|
multi2 = StrOption('multi2', '', multi=submulti, callback=return_val, callback_params={'': ((multi, False),)})
|
||||||
|
od = OptionDescription('multi', '', [multi, multi2])
|
||||||
|
api = getapi(Config(od))
|
||||||
|
api.property.read_write()
|
||||||
|
owner = api.owner.get()
|
||||||
|
assert api.option('multi').owner.get() == owners.default
|
||||||
|
assert api.option('multi').value.get() == []
|
||||||
|
assert api.option('multi2').value.get() == []
|
||||||
|
api.option('multi').value.set([['val']])
|
||||||
|
assert api.option('multi').owner.get() == owner
|
||||||
|
assert api.option('multi2').owner.get() == owners.default
|
||||||
|
assert api.option('multi').value.get() == [['val']]
|
||||||
|
assert api.option('multi2').value.get() == [['val']]
|
||||||
|
|
||||||
|
|
||||||
|
def test_submulti_unique():
|
||||||
|
i = IntOption('int', '', multi=submulti, unique=True)
|
||||||
|
o = OptionDescription('od', '', [i])
|
||||||
|
api = getapi(Config(o))
|
||||||
|
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([[1, 0, 2, 3, 4, 5, 6, 0, 7], [0]])")
|
||||||
|
api.option('int').value.set([[0, 4, 5, 6], [0]])
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_multi_submulti_meta():
|
||||||
|
# multi = StrOption('multi', '', multi=submulti)
|
||||||
|
# od = OptionDescription('od', '', [multi])
|
||||||
|
# conf1 = Config(od, session_id='conf1')
|
||||||
|
# api1 = getapi(conf1)
|
||||||
|
# api1.property.read_write()
|
||||||
|
# conf2 = Config(od, session_id='conf2')
|
||||||
|
# api2 = getapi(conf2)
|
||||||
|
# api2.property.read_write()
|
||||||
|
# meta = MetaConfig([conf1, conf2])
|
||||||
|
# api3 = getapi(meta)
|
||||||
|
# api3.property.read_write()
|
||||||
|
# api3.option('multi').value.set([['val']])
|
||||||
|
# assert api3.option('multi').value.get() == [['val']]
|
||||||
|
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||||
|
# assert api1.option('multi').value.get() == [['val', None]]
|
||||||
|
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||||
|
# assert api3.option('multi').value.get() == [['val']]
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#def test_multi_submulti_meta_no_cache():
|
||||||
|
# multi = StrOption('multi', '', multi=submulti)
|
||||||
|
# od = OptionDescription('od', '', [multi])
|
||||||
|
# conf1 = Config(od, session_id='conf1_1')
|
||||||
|
# api1 = getapi(conf1)
|
||||||
|
# api1.property.read_write()
|
||||||
|
# conf2 = Config(od, session_id='conf2_1')
|
||||||
|
# api2 = getapi(conf2)
|
||||||
|
# api2.property.read_write()
|
||||||
|
# meta = MetaConfig([conf1, conf2])
|
||||||
|
# api3 = getapi(api2)
|
||||||
|
# api3.property.read_write()
|
||||||
|
# api3.property.pop('cache')
|
||||||
|
# api3.option('multi').value.set([['val']])
|
||||||
|
# assert api3.option('multi').value.get() == [['val']]
|
||||||
|
# api3.config('conf1').option('multi').value.set([['val', None]])
|
||||||
|
# assert api1.option('multi').value.get() == [['val', None]]
|
||||||
|
# assert api3.config('conf1').option('multi').value.get() == [['val', None]]
|
||||||
|
# assert api3.option('multi').value.get() == [['val']]
|
|
@ -297,11 +297,10 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||||
|
|
||||||
@count
|
@count
|
||||||
def pop(self, prop):
|
def pop(self, prop):
|
||||||
props = self.get()
|
self.get_option()
|
||||||
props.remove(prop)
|
self.settings.popproperty(self.path,
|
||||||
self.settings.setproperties(path=self.path,
|
prop,
|
||||||
properties=frozenset(props),
|
self.config_bag)
|
||||||
config_bag=self.config_bag)
|
|
||||||
|
|
||||||
@count
|
@count
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|
|
@ -408,13 +408,13 @@ class SubConfig(object):
|
||||||
'').format(subpath))
|
'').format(subpath))
|
||||||
length = self.cfgimpl_get_length()
|
length = self.cfgimpl_get_length()
|
||||||
if index is not None and index >= length:
|
if index is not None and index >= length:
|
||||||
raise IndexError(_('index ({}) is higher than the master length ({}) '
|
raise IndexError(_('index "{}" is higher than the master length "{}" '
|
||||||
'for "{}"').format(index,
|
'for option "{}"').format(index,
|
||||||
length,
|
length,
|
||||||
option.impl_get_display_name()))
|
option.impl_get_display_name()))
|
||||||
slave_len = self.cfgimpl_get_values()._p_.get_max_length(subpath)
|
slave_len = self.cfgimpl_get_values()._p_.get_max_length(subpath)
|
||||||
if slave_len > length:
|
if slave_len > length:
|
||||||
raise SlaveError(_('slave option "{}" has higher length ({}) than the master length ({})'
|
raise SlaveError(_('slave option "{}" has higher length "{}" than the master length "{}"'
|
||||||
'').format(option.impl_get_display_name(),
|
'').format(option.impl_get_display_name(),
|
||||||
slave_len,
|
slave_len,
|
||||||
length,
|
length,
|
||||||
|
|
|
@ -353,7 +353,7 @@ class Base(object):
|
||||||
return not isinstance(getattr(self, '_informations', dict()), dict)
|
return not isinstance(getattr(self, '_informations', dict()), dict)
|
||||||
|
|
||||||
def impl_getproperties(self):
|
def impl_getproperties(self):
|
||||||
return getattr(self, '_properties', STATIC_TUPLE)
|
return getattr(self, '_properties', frozenset())
|
||||||
|
|
||||||
def _set_readonly(self):
|
def _set_readonly(self):
|
||||||
if not self.impl_is_readonly():
|
if not self.impl_is_readonly():
|
||||||
|
|
|
@ -71,7 +71,7 @@ class MasterSlaves(OptionDescription):
|
||||||
if idx != 0:
|
if idx != 0:
|
||||||
properties = list(child._properties)
|
properties = list(child._properties)
|
||||||
properties.remove('empty')
|
properties.remove('empty')
|
||||||
child._properties = tuple(properties)
|
child._properties = frozenset(properties)
|
||||||
slaves.append(child)
|
slaves.append(child)
|
||||||
child._add_dependency(self)
|
child._add_dependency(self)
|
||||||
child._master_slaves = weakref.ref(self)
|
child._master_slaves = weakref.ref(self)
|
||||||
|
|
|
@ -247,8 +247,7 @@ class Option(OnlyOption):
|
||||||
def do_validation(_value,
|
def do_validation(_value,
|
||||||
_index):
|
_index):
|
||||||
if isinstance(_value, list): # pragma: no cover
|
if isinstance(_value, list): # pragma: no cover
|
||||||
raise ValueError(_('invalid value "{}" for "{}" '
|
raise ValueError(_('which must not be a list').format(_value,
|
||||||
'which must not be a list').format(_value,
|
|
||||||
self.impl_get_display_name()))
|
self.impl_get_display_name()))
|
||||||
#FIXME a revoir ...
|
#FIXME a revoir ...
|
||||||
if _value is not None:
|
if _value is not None:
|
||||||
|
@ -278,6 +277,8 @@ class Option(OnlyOption):
|
||||||
do_validation(val, None)
|
do_validation(val, None)
|
||||||
elif force_index is not None:
|
elif force_index is not None:
|
||||||
if self.impl_is_submulti():
|
if self.impl_is_submulti():
|
||||||
|
if not isinstance(value, list):
|
||||||
|
raise ValueError(_('which must be a list'))
|
||||||
_is_not_unique(value)
|
_is_not_unique(value)
|
||||||
for idx, val in enumerate(value):
|
for idx, val in enumerate(value):
|
||||||
do_validation(val,
|
do_validation(val,
|
||||||
|
@ -290,23 +291,17 @@ class Option(OnlyOption):
|
||||||
else:
|
else:
|
||||||
lst = multi
|
lst = multi
|
||||||
if value in lst:
|
if value in lst:
|
||||||
raise ValueError(_('invalid value "{}", this value is already'
|
raise ValueError(_('this value is not uniq'))
|
||||||
' in "{}"').format(value,
|
|
||||||
self.impl_get_display_name()))
|
|
||||||
do_validation(val,
|
do_validation(val,
|
||||||
force_index)
|
force_index)
|
||||||
elif not isinstance(value, list):
|
elif not isinstance(value, list):
|
||||||
raise ValueError(_('invalid value "{0}" for "{1}" which '
|
raise ValueError(_('which must be a list'))
|
||||||
'must be a list').format(value,
|
|
||||||
self.impl_getname()))
|
|
||||||
elif self.impl_is_submulti():
|
elif self.impl_is_submulti():
|
||||||
for idx, lval in enumerate(value):
|
for idx, lval in enumerate(value):
|
||||||
_is_not_unique(lval)
|
_is_not_unique(lval)
|
||||||
if not isinstance(lval, list):
|
if not isinstance(lval, list):
|
||||||
raise ValueError(_('invalid value "{0}" for "{1}" '
|
raise ValueError(_('which "{}" must be a list of list'
|
||||||
'which must be a list of list'
|
'').format(lval))
|
||||||
'').format(lval,
|
|
||||||
self.impl_getname()))
|
|
||||||
for val in lval:
|
for val in lval:
|
||||||
do_validation(val,
|
do_validation(val,
|
||||||
idx)
|
idx)
|
||||||
|
|
|
@ -612,6 +612,16 @@ class Settings(object):
|
||||||
config_bag,
|
config_bag,
|
||||||
force=True)
|
force=True)
|
||||||
|
|
||||||
|
def popproperty(self,
|
||||||
|
path,
|
||||||
|
property_,
|
||||||
|
config_bag):
|
||||||
|
props = config_bag.option.impl_getproperties()
|
||||||
|
self.setproperties(path,
|
||||||
|
props - {property_},
|
||||||
|
config_bag,
|
||||||
|
force=True)
|
||||||
|
|
||||||
def set_context_permissive(self, permissive):
|
def set_context_permissive(self, permissive):
|
||||||
self.setpermissive(None, None, permissive)
|
self.setpermissive(None, None, permissive)
|
||||||
|
|
||||||
|
|
|
@ -248,7 +248,7 @@ class Values(object):
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
# value is a list, but no index specified
|
# value is a list, but no index specified
|
||||||
_reset_cache()
|
_reset_cache()
|
||||||
if opt.impl_is_submulti() and (value == [] or not isinstance(value[0], list)):
|
if opt.impl_is_submulti() and (value != [] and not isinstance(value[0], list)):
|
||||||
# if submulti, return a list of value
|
# if submulti, return a list of value
|
||||||
return [value]
|
return [value]
|
||||||
# otherwise just return the value
|
# otherwise just return the value
|
||||||
|
|
Loading…
Reference in New Issue