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