improvemnt information
This commit is contained in:
parent
a521a6d322
commit
98200ecae5
|
@ -7,6 +7,7 @@ do_autopath()
|
||||||
from py.test import raises
|
from py.test import raises
|
||||||
|
|
||||||
from tiramisu.option import IntOption, OptionDescription
|
from tiramisu.option import IntOption, OptionDescription
|
||||||
|
from tiramisu.config import Config
|
||||||
|
|
||||||
|
|
||||||
def a_func():
|
def a_func():
|
||||||
|
@ -65,6 +66,7 @@ def test_option_get_information():
|
||||||
description = "it's ok"
|
description = "it's ok"
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
i = IntOption('test', description)
|
i = IntOption('test', description)
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
i.impl_set_information('info', string)
|
i.impl_set_information('info', string)
|
||||||
assert i.impl_get_information('info') == string
|
assert i.impl_get_information('info') == string
|
||||||
raises(ValueError, "i.impl_get_information('noinfo')")
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
@ -73,6 +75,38 @@ def test_option_get_information():
|
||||||
assert i.impl_getdoc() == description
|
assert i.impl_getdoc() == description
|
||||||
|
|
||||||
|
|
||||||
|
def test_option_get_information_config():
|
||||||
|
description = "it's ok"
|
||||||
|
string = 'some informations'
|
||||||
|
string
|
||||||
|
i = IntOption('test', description)
|
||||||
|
od = OptionDescription('od', '', [i])
|
||||||
|
Config(od)
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
raises(AttributeError, "i.impl_set_information('info', string)")
|
||||||
|
# assert i.impl_get_information('info') == string
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||||
|
assert i.impl_get_information('doc') == description
|
||||||
|
assert i.impl_getdoc() == description
|
||||||
|
|
||||||
|
|
||||||
|
def test_option_get_information_config2():
|
||||||
|
description = "it's ok"
|
||||||
|
string = 'some informations'
|
||||||
|
i = IntOption('test', description)
|
||||||
|
i.impl_set_information('info', string)
|
||||||
|
od = OptionDescription('od', '', [i])
|
||||||
|
Config(od)
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
raises(AttributeError, "i.impl_set_information('info', 'hello')")
|
||||||
|
assert i.impl_get_information('info') == string
|
||||||
|
raises(ValueError, "i.impl_get_information('noinfo')")
|
||||||
|
assert i.impl_get_information('noinfo', 'default') == 'default'
|
||||||
|
assert i.impl_get_information('doc') == description
|
||||||
|
assert i.impl_getdoc() == description
|
||||||
|
|
||||||
|
|
||||||
def test_optiondescription_get_information():
|
def test_optiondescription_get_information():
|
||||||
description = "it's ok"
|
description = "it's ok"
|
||||||
string = 'some informations'
|
string = 'some informations'
|
||||||
|
|
|
@ -630,3 +630,27 @@ def test_master_slave_requires():
|
||||||
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||||
assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None
|
||||||
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
||||||
|
|
||||||
|
|
||||||
|
def test_master_slave_requires_no_master():
|
||||||
|
activate = BoolOption('activate', "Activer l'accès au réseau", True)
|
||||||
|
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,
|
||||||
|
requires=[{'option': activate, 'expected': False, 'action': 'disabled'}])
|
||||||
|
interface1 = OptionDescription('ip_admin_eth0', '', [ip_admin_eth0, netmask_admin_eth0])
|
||||||
|
interface1.impl_set_group_type(groups.master)
|
||||||
|
maconfig = OptionDescription('toto', '', [activate, interface1])
|
||||||
|
cfg = Config(maconfig)
|
||||||
|
cfg.read_write()
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == []
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == []
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.2')
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0 == [None]
|
||||||
|
assert cfg.ip_admin_eth0.netmask_admin_eth0[0] is None
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.2']
|
||||||
|
cfg.activate = False
|
||||||
|
cfg.ip_admin_eth0.ip_admin_eth0.append('192.168.1.1')
|
||||||
|
assert cfg.ip_admin_eth0.ip_admin_eth0 == ['192.168.1.2', '192.168.1.1']
|
||||||
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0")
|
||||||
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[0]")
|
||||||
|
raises(PropertiesOptionError, "cfg.ip_admin_eth0.netmask_admin_eth0[1]")
|
||||||
|
|
|
@ -633,9 +633,13 @@ class Settings(object):
|
||||||
" '{0}' with requirement on: "
|
" '{0}' with requirement on: "
|
||||||
"'{1}'").format(path, reqpath))
|
"'{1}'").format(path, reqpath))
|
||||||
try:
|
try:
|
||||||
|
if option.impl_is_multi():
|
||||||
|
idx = index
|
||||||
|
else:
|
||||||
|
idx = None
|
||||||
value = context.getattr(reqpath, force_permissive=True,
|
value = context.getattr(reqpath, force_permissive=True,
|
||||||
_setting_properties=setting_properties,
|
_setting_properties=setting_properties,
|
||||||
index=index)
|
index=idx)
|
||||||
except PropertiesOptionError as err:
|
except PropertiesOptionError as err:
|
||||||
if not transitive:
|
if not transitive:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -107,6 +107,13 @@ class StorageBase(object):
|
||||||
:param key: information's key (ex: "help", "doc"
|
:param key: information's key (ex: "help", "doc"
|
||||||
:param value: information's value (ex: "the help string")
|
:param value: information's value (ex: "the help string")
|
||||||
"""
|
"""
|
||||||
|
if self.impl_is_readonly():
|
||||||
|
raise AttributeError(_("'{0}' ({1}) object attribute '{2}' is"
|
||||||
|
" read-only").format(
|
||||||
|
self.__class__.__name__,
|
||||||
|
self,
|
||||||
|
#self.impl_getname(),
|
||||||
|
key))
|
||||||
self._informations[key] = value
|
self._informations[key] = value
|
||||||
|
|
||||||
def impl_get_information(self, key, default=undefined):
|
def impl_get_information(self, key, default=undefined):
|
||||||
|
@ -119,15 +126,18 @@ class StorageBase(object):
|
||||||
if dico is None or isinstance(dico, str) or isinstance(dico, unicode):
|
if dico is None or isinstance(dico, str) or isinstance(dico, unicode):
|
||||||
if key == 'doc':
|
if key == 'doc':
|
||||||
return dico
|
return dico
|
||||||
|
if default is not undefined:
|
||||||
|
return default
|
||||||
error = True
|
error = True
|
||||||
elif isinstance(dico, tuple):
|
elif isinstance(dico, tuple):
|
||||||
try:
|
try:
|
||||||
return dico[1][dico[0].index(key)]
|
return dico[1][dico[0].index(key)]
|
||||||
except AttributeError:
|
except ValueError:
|
||||||
if default is not undefined:
|
if default is not undefined:
|
||||||
return default
|
return default
|
||||||
error = True
|
error = True
|
||||||
else:
|
else:
|
||||||
|
# dict
|
||||||
if default is not undefined:
|
if default is not undefined:
|
||||||
return self._informations.get(key, default)
|
return self._informations.get(key, default)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -162,9 +162,9 @@ class Values(Cache):
|
||||||
else:
|
else:
|
||||||
if isinstance(self._values[1][idx], list):
|
if isinstance(self._values[1][idx], list):
|
||||||
if index is None:
|
if index is None:
|
||||||
raise ValueError('list but no index')
|
raise ValueError('index is mandatory')
|
||||||
elif index is not None:
|
elif index is not None:
|
||||||
raise ValueError('index set but not a list')
|
raise ValueError('index is forbidden')
|
||||||
|
|
||||||
if self._values[1][idx] is None:
|
if self._values[1][idx] is None:
|
||||||
if index is None:
|
if index is None:
|
||||||
|
|
Loading…
Reference in New Issue