better propertyerror message
This commit is contained in:
@ -4,6 +4,8 @@ do_autopath()
|
||||
|
||||
from py.test import raises
|
||||
|
||||
from tiramisu.i18n import _
|
||||
from tiramisu.error import display_list
|
||||
from tiramisu.setting import owners, groups
|
||||
from tiramisu.config import Config
|
||||
from tiramisu.option import ChoiceOption, BoolOption, IntOption, FloatOption, \
|
||||
@ -471,3 +473,65 @@ def test_reset_properties_force_store_value():
|
||||
setting.reset(all_properties=True)
|
||||
assert setting._p_.get_modified_properties() == {}
|
||||
raises(ValueError, 'setting.reset(all_properties=True, opt=option)')
|
||||
|
||||
|
||||
def test_pprint():
|
||||
msg_error = _('cannot access to {} {} because has {} {}')
|
||||
msg_is = _("the value of {0} is {1}")
|
||||
msg_is_not = _("the value of {0} is not {1}")
|
||||
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True, properties=('hidden', 'disabled'))
|
||||
s2 = StrOption("string2", "", default="string")
|
||||
s3 = StrOption("string3", "", default=["string"], default_multi="string", multi=True, properties=('hidden',))
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default="abc",
|
||||
requires=[{'option': intoption, 'expected': 2, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 3, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 4, 'action': 'hidden', 'inverse': True},
|
||||
{'option': intoption, 'expected': 1, 'action': 'disabled'},
|
||||
{'option': s2, 'expected': 'string', 'action': 'disabled'}])
|
||||
|
||||
val2 = StrOption('val2', "")
|
||||
descr2 = OptionDescription("options", "", [val2], requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}])
|
||||
|
||||
val3 = StrOption('val3', "", requires=[{'option': stroption, 'expected': '2', 'action': 'hidden', 'inverse': True}])
|
||||
|
||||
descr = OptionDescription("options", "", [s, s2, s3, intoption, stroption, descr2, val3])
|
||||
config = Config(descr)
|
||||
setting = config.cfgimpl_get_settings()
|
||||
config.read_write()
|
||||
config.int = 1
|
||||
try:
|
||||
config.str
|
||||
except Exception, err:
|
||||
pass
|
||||
|
||||
assert str(err) == msg_error.format('option', 'str', 'properties', display_list(['disabled (' + display_list([msg_is.format('int', '1'), msg_is.format('string2', 'string')]) + ')', 'hidden (' + msg_is_not.format('int', display_list([2, 3, 4], 'or')) + ')']))
|
||||
|
||||
try:
|
||||
config.options.val2
|
||||
except Exception, err:
|
||||
pass
|
||||
|
||||
assert str(err) == msg_error.format('optiondescription', 'options', 'property', 'hidden (' + msg_is.format('int', 1) + ')')
|
||||
|
||||
try:
|
||||
config.val3
|
||||
except Exception, err:
|
||||
pass
|
||||
|
||||
assert str(err) == msg_error.format('option', 'val3', 'property', 'hidden (' + display_list([msg_is.format('int', 1), msg_is.format('string2', 'string'), msg_is_not.format('int', display_list([2, 3, 4], 'or'))]) + ')')
|
||||
|
||||
try:
|
||||
config.string
|
||||
except Exception, err:
|
||||
pass
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string', 'properties', display_list(['disabled', 'hidden']))
|
||||
|
||||
try:
|
||||
config.string3
|
||||
except Exception, err:
|
||||
pass
|
||||
|
||||
assert str(err) == msg_error.format('option', 'string3', 'property', 'hidden')
|
||||
|
Reference in New Issue
Block a user