diff --git a/test/test_config.py b/test/test_config.py index d66e27e..cacb7d6 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -264,6 +264,23 @@ def test_config_multi(): assert config.option('test3').value.get() == [2, 1] +def test_prefix_error(): + i1 = IntOption('test1', '') + od = OptionDescription('test', '', [i1]) + config = Config(od) + config.property.read_write() + config.option('test1').value.set(1) + try: + config.option('test1').value.set('yes') + except Exception as err: + assert str(err) == '"yes" is an invalid integer for "test1"' + try: + config.option('test1').value.set('yes') + except Exception as err: + err.prefix = '' + assert str(err) == 'invalid value' + + def test_no_validation(): i1 = IntOption('test1', '') od = OptionDescription('test', '', [i1]) diff --git a/test/test_mandatory.py b/test/test_mandatory.py index 0afe902..c3966c8 100644 --- a/test/test_mandatory.py +++ b/test/test_mandatory.py @@ -417,6 +417,7 @@ def test_mandatory_leader(): api = Config(descr) api.property.read_only() raises(PropertiesOptionError, "api.option('ip_admin_eth0.ip_admin_eth0').value.get()") + raises(PropertiesOptionError, "api.value.dict()") def test_mandatory_warnings_leader(): diff --git a/test/test_metaconfig.py b/test/test_metaconfig.py index cfb24aa..4a1ae52 100644 --- a/test/test_metaconfig.py +++ b/test/test_metaconfig.py @@ -63,6 +63,12 @@ def test_unknown_config(): raises(ConfigError, "meta.config('unknown')") +def test_error_metaconfig(): + od2 = make_description() + conf1 = Config(od2, session_id='conf1') + raises(TypeError, "MetaConfig([GroupConfig([conf1])], session_id='meta')") + + def test_path(): meta = make_metaconfig() assert meta.config.path() == 'meta' diff --git a/test/test_option_consistency.py b/test/test_option_consistency.py index 137ec99..9097997 100644 --- a/test/test_option_consistency.py +++ b/test/test_option_consistency.py @@ -88,6 +88,24 @@ def test_consistency_warnings_only_more_option(): assert len(w) == 1 +def test_consistency_error_prefix(): + a = IntOption('a', '') + b = IntOption('b', '') + od = OptionDescription('od', '', [a, b]) + a.impl_add_consistency('not_equal', b) + api = Config(od) + api.option('a').value.set(1) + try: + api.option('b').value.set(1) + except Exception as err: + assert str(err) == '"1" is an invalid integer for "b", must be different from the value of "a"' + try: + api.option('b').value.set(1) + except Exception as err: + err.prefix = '' + assert str(err) == 'must be different from the value of "a"' + + def test_consistency_warnings_only_option(): a = IntOption('a', '') b = IntOption('b', '', warnings_only=True) diff --git a/tiramisu/config.py b/tiramisu/config.py index b0cbb3d..4ecfc6f 100644 --- a/tiramisu/config.py +++ b/tiramisu/config.py @@ -1198,12 +1198,13 @@ class KernelMetaConfig(KernelMixConfig): if not isinstance(child, _CommonConfig): try: child = child._config - except: + except Exception: raise TypeError(_("{}config's children " "should be config, not {}" ).format(self.impl_type, type(child))) - if not isinstance(child, (KernelConfig, KernelMetaConfig)): + if __debug__ and not isinstance(child, (KernelConfig, + KernelMetaConfig)): raise TypeError(_("child must be a Config or MetaConfig")) if descr is None: descr = child.cfgimpl_get_description() diff --git a/tiramisu/option/netmaskoption.py b/tiramisu/option/netmaskoption.py index cc7af39..5fbfda5 100644 --- a/tiramisu/option/netmaskoption.py +++ b/tiramisu/option/netmaskoption.py @@ -19,6 +19,7 @@ # the whole pypy projet is under MIT licence # ____________________________________________________________ from ipaddress import ip_interface, ip_network +from typing import List from ..error import ConfigError from ..setting import undefined, OptionBag, Undefined @@ -49,11 +50,11 @@ class NetmaskOption(StrOption): raise ValueError() def _cons_network_netmask(self, - current_opt, - opts, - vals, - warnings_only, - context): + current_opt: Option, + opts: List[Option], + vals: List[str], + warnings_only: bool, + context: 'Config'): if context is undefined and len(vals) != 2: raise ConfigError(_('network_netmask needs a network and a netmask')) if None in vals or len(vals) != 2: @@ -71,12 +72,12 @@ class NetmaskOption(StrOption): opt_network.impl_get_display_name())) def _cons_ip_netmask(self, - current_opt, - opts, - vals, - warnings_only, - context, - _cidr=False): + current_opt: Option, + opts: List[Option], + vals: List[str], + warnings_only: bool, + context: 'config', + _cidr: bool=False): if context is undefined and len(vals) != 2: raise ConfigError(_('ip_netmask needs an IP and a netmask')) if None in vals or len(vals) != 2: