simplify find() in api and PropertiesOptionError

This commit is contained in:
2018-04-10 22:42:20 +02:00
parent 5eb2f04202
commit 9e378faef0
11 changed files with 213 additions and 198 deletions

View File

@ -24,7 +24,7 @@ def return_calc_list(val):
return [val]
def return_error():
def return_error(*args, **kwargs):
raise Exception('test')
@ -83,6 +83,24 @@ def test_choiceoption_function_error():
raises(ConfigError, "api.option('choice').value.set('val1')")
def test_choiceoption_function_error_args():
choice = ChoiceOption('choice', '', values=return_error, values_params={'': ('val1',)})
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
api = getapi(cfg)
api.property.read_write()
raises(ConfigError, "api.option('choice').value.set('val1')")
def test_choiceoption_function_error_kwargs():
choice = ChoiceOption('choice', '', values=return_error, values_params={'kwargs': ('val1',)})
odesc = OptionDescription('od', '', [choice])
cfg = Config(odesc)
api = getapi(cfg)
api.property.read_write()
raises(ConfigError, "api.option('choice').value.set('val1')")
def test_choiceoption_calc_function():
choice = ChoiceOption('choice', "", values=return_calc_list, values_params={'': ('val1',)})
odesc = OptionDescription('od', '', [choice])

View File

@ -195,6 +195,11 @@ def test_find_in_config():
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), api.option('gc.prop').option.get())
#
ret = api.option.find('prop', value=None)
ret = api.option.find('prop')
assert len(ret) == 1
_is_same_opt(ret[0].option.get(), api.option('gc.prop').option.get())
#
api.property.read_write()
raises(AttributeError, "assert api.option.find('prop').option.get()")
ret = api.unrestraint.option.find(name='prop')

View File

@ -48,6 +48,11 @@ def make_metaconfig(double=False):
return api
def test_unknown_config():
api = make_metaconfig()
raises(ConfigError, "api.config('unknown')")
#FIXME ne pas mettre 2 meta dans une config
#FIXME ne pas mettre 2 OD differents dans un meta
def test_none():

View File

@ -10,6 +10,7 @@ from tiramisu import ChoiceOption, BoolOption, IntOption, FloatOption, \
getapi, undefined
from tiramisu.api import TIRAMISU_VERSION
from tiramisu.error import PropertiesOptionError, ConflictError, SlaveError, ConfigError
from tiramisu.i18n import _
def return_val():
@ -652,7 +653,13 @@ def test_consistency_master_and_slaves_master_mandatory_transitive():
maconfig = OptionDescription('rootconfig', '', [interface1, interface2])
api = getapi(Config(maconfig))
api.property.read_write()
raises(PropertiesOptionError, "api.option('val1.val1').value.get()")
err = None
try:
api.option('val1.val1').value.get()
except PropertiesOptionError as error:
err = error
assert err, 'should raises'
assert str(err) == str(_('cannot access to {0} "{1}" because "{2}" has {3} {4}').format('option', 'val1', 'val2', 'property', '"disabled"'))
raises(PropertiesOptionError, "api.option('val3.val3').value.get()")
assert list(api.value.mandatory_warnings()) == []

View File

@ -3,6 +3,7 @@ from .autopath import do_autopath
do_autopath()
from copy import copy
from tiramisu.i18n import _
from tiramisu.setting import groups
from tiramisu import setting
setting.expires_time = 1
@ -93,16 +94,17 @@ def test_requires_invalid():
def test_requires_same_action():
a = BoolOption('activate_service', '', True)
b = BoolOption('activate_service_web', '', True,
requires=[{'option': a, 'expected': False, 'action': 'new'}])
activate_service = BoolOption('activate_service', '', True)
activate_service_web = BoolOption('activate_service_web', '', True,
requires=[{'option': activate_service, 'expected': False,
'action': 'new'}])
d = IPOption('ip_address_service_web', '',
requires=[{'option': b, 'expected': False,
'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}])
od = OptionDescription('service', '', [a, b, d])
api = getapi(Config(od))
ip_address_service_web = IPOption('ip_address_service_web', '',
requires=[{'option': activate_service_web, 'expected': False,
'action': 'disabled', 'inverse': False,
'transitive': True, 'same_action': False}])
od1 = OptionDescription('service', '', [activate_service, activate_service_web, ip_address_service_web])
api = getapi(Config(od1))
api.property.read_write()
api.property.add('new')
api.option('activate_service').value.get()
@ -122,6 +124,8 @@ def test_requires_same_action():
api.option('ip_address_service_web').value.get()
except PropertiesOptionError as err:
props = err.proptype
submsg = '"disabled" (' + _('the value of "{0}" is {1}').format('activate_service', '"False"') + ')'
assert str(err) == str(_('cannot access to {0} "{1}" because has {2} {3}').format('option', 'ip_address_service_web', 'property', submsg))
assert frozenset(props) == frozenset(['disabled'])