can remove prefix in ValueOptionError
This commit is contained in:
parent
9dbe371bcd
commit
1cda79154e
@ -1743,15 +1743,15 @@ def test_options(paths):
|
||||
pass
|
||||
# for meta in (True,):
|
||||
# for callback in (False,):
|
||||
# for consistency in (False,):
|
||||
# for require in (False,):
|
||||
# for default_multi in (False,):
|
||||
# for consistency in (True,):
|
||||
# for require in (True,):
|
||||
# for default_multi in (True,):
|
||||
# for symlink in (False,):
|
||||
# if callback and default_multi:
|
||||
# continue
|
||||
# for default in (False,):
|
||||
# for multi in (False,):
|
||||
# print(meta, callback, consistency, require, default_multi, symlink, default, multi)
|
||||
# for default in (True,):
|
||||
# for multi in (submulti,):
|
||||
meta, callback, consistency, require, default_multi, symlink, default, multi = (True, False, True, False, True, True, True, True)
|
||||
if multi is submulti and default:
|
||||
continue
|
||||
if multi is submulti and consistency:
|
||||
|
@ -84,6 +84,18 @@ def test_reset_with_multi():
|
||||
raises(ValueError, "api.option('string').value.set(None)")
|
||||
|
||||
|
||||
def test_property_only_raises():
|
||||
s = StrOption("string", "", default=["string"], default_multi="string", multi=True)
|
||||
intoption = IntOption('int', 'Test int option', default=0)
|
||||
stroption = StrOption('str', 'Test string option', default=["abc"], default_multi="abc",
|
||||
requires=[{'option': intoption, 'expected': 1, 'action': 'hidden'}], multi=True)
|
||||
descr = OptionDescription("options", "", [s, intoption, stroption])
|
||||
api = Config(descr)
|
||||
api.property.read_write()
|
||||
assert api.option('str').property.get() == {'empty'}
|
||||
assert api.option('str').property.get(only_raises=True) == set()
|
||||
|
||||
|
||||
def test_default_with_multi():
|
||||
"default with multi is a list"
|
||||
s = StrOption("string", "", default=[], default_multi="string", multi=True)
|
||||
|
@ -297,7 +297,9 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
if option_bag and option_bag.config_bag:
|
||||
self._settings = option_bag.config_bag.context.cfgimpl_get_settings()
|
||||
|
||||
def get(self, apply_requires=True):
|
||||
def get(self,
|
||||
apply_requires=True,
|
||||
only_raises=False):
|
||||
"""Get properties for an option"""
|
||||
option = self._option_bag.option
|
||||
if apply_requires:
|
||||
@ -305,8 +307,12 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
properties = self._option_bag.properties
|
||||
else:
|
||||
properties = self._settings.getproperties(self._option_bag,
|
||||
apply_requires=False)
|
||||
return set(properties)
|
||||
apply_requires=False)
|
||||
if not only_raises:
|
||||
return properties
|
||||
return self._settings.calc_raises_properties(properties,
|
||||
self._option_bag.config_bag.properties,
|
||||
self._option_bag.config_bag.permissives)
|
||||
|
||||
def add(self, prop):
|
||||
"""Add new property for an option"""
|
||||
@ -335,7 +341,7 @@ class TiramisuOptionProperty(CommonTiramisuOption):
|
||||
"""Reset all personalised properties"""
|
||||
option = self._option_bag.option
|
||||
self._settings.reset(self._option_bag,
|
||||
self._option_bag.config_bag.context)
|
||||
self._option_bag.config_bag.context)
|
||||
|
||||
|
||||
class TiramisuOptionPermissive(CommonTiramisuOption):
|
||||
@ -1066,6 +1072,17 @@ class _TiramisuContextConfigReset():
|
||||
# Remove cache
|
||||
self._config_bag.context.cfgimpl_reset_cache(None, None)
|
||||
|
||||
def __call__(self,
|
||||
path: Optional[str]):
|
||||
"""select a child Tiramisu config"""
|
||||
if path is None:
|
||||
return Config(self._config_bag)
|
||||
spaths = path.split('.')
|
||||
config = self._config_bag.context
|
||||
for spath in spaths:
|
||||
config = config.getconfig(spath)
|
||||
return Config(config)
|
||||
|
||||
|
||||
class _TiramisuContextConfig(TiramisuContext, _TiramisuContextConfigReset):
|
||||
"""Actions to Config"""
|
||||
@ -1166,7 +1183,7 @@ class TiramisuAPI(TiramisuHelp):
|
||||
return TiramisuAPI(config_bag)
|
||||
elif subfunc == 'unrestraint':
|
||||
config_bag = self._config_bag.copy()
|
||||
config_bag.properties = frozenset()
|
||||
config_bag.properties = frozenset(['cache'])
|
||||
return TiramisuAPI(config_bag)
|
||||
elif subfunc == 'config':
|
||||
config_type = self._config_bag.context.impl_type
|
||||
|
@ -185,5 +185,29 @@ class ValueWarning(UserWarning):
|
||||
super(ValueWarning, self).__init__(msg)
|
||||
|
||||
|
||||
class ValueOptionError(ValueError):
|
||||
def __init__(self,
|
||||
val,
|
||||
display_type,
|
||||
display_name,
|
||||
err_msg):
|
||||
self.prefix = _('"{0}" is an invalid {1} for "{2}"'
|
||||
'').format(val,
|
||||
display_type,
|
||||
display_name)
|
||||
self.err_msg = err_msg
|
||||
|
||||
def __str__(self):
|
||||
msg = self.prefix
|
||||
if self.err_msg:
|
||||
if msg:
|
||||
msg += ', {}'.format(self.err_msg)
|
||||
else:
|
||||
msg = self.err_msg
|
||||
if not msg:
|
||||
msg = _('invalid value')
|
||||
return msg
|
||||
|
||||
|
||||
class APIError(Exception):
|
||||
pass
|
||||
|
@ -28,7 +28,7 @@ from ..i18n import _
|
||||
from ..setting import log, undefined, OptionBag
|
||||
from ..autolib import carry_out_calculation
|
||||
from ..error import (ConfigError, ValueWarning, PropertiesOptionError,
|
||||
display_list)
|
||||
ValueOptionError, display_list)
|
||||
from ..function import Params, ParamValue
|
||||
ALLOWED_CONST_LIST = ['_cons_not_equal']
|
||||
|
||||
@ -350,14 +350,10 @@ class Option(OnlyOption):
|
||||
check_error,
|
||||
is_warnings_only)
|
||||
except ValueError as err:
|
||||
msg = _('"{0}" is an invalid {1} for "{2}"'
|
||||
'').format(val,
|
||||
self._display_name,
|
||||
option_bag.ori_option.impl_get_display_name())
|
||||
err_msg = '{0}'.format(err)
|
||||
if err_msg:
|
||||
msg += ', {}'.format(err_msg)
|
||||
raise ValueError(msg)
|
||||
raise ValueOptionError(val,
|
||||
self._display_name,
|
||||
option_bag.ori_option.impl_get_display_name(),
|
||||
'{0}'.format(err))
|
||||
|
||||
def _validate_calculator(self,
|
||||
callback,
|
||||
|
Loading…
Reference in New Issue
Block a user