From 63094f7e542b585a81242ad5d4649e748ed9bcb3 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Sat, 13 Apr 2019 22:04:49 +0200 Subject: [PATCH] better error messages with list --- tests/test_option_consistency.py | 4 +-- tests/test_option_setting.py | 4 +-- tiramisu/__init__.py | 2 +- tiramisu/error.py | 4 +-- tiramisu/locale/fr/LC_MESSAGES/tiramisu.po | 39 ++++++++++------------ tiramisu/locale/tiramisu.pot | 28 ++++++++-------- tiramisu/option/baseoption.py | 2 +- tiramisu/option/choiceoption.py | 4 +-- tiramisu/option/option.py | 6 ++-- 9 files changed, 45 insertions(+), 48 deletions(-) diff --git a/tests/test_option_consistency.py b/tests/test_option_consistency.py index f79ffa7..8c4d66b 100644 --- a/tests/test_option_consistency.py +++ b/tests/test_option_consistency.py @@ -99,12 +99,12 @@ def test_consistency_error_prefix(): try: api.option('b').value.set(1) except Exception as err: - assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('1', _('integer'), 'b') + ', ' + _('must be different from the value of "{}"').format('a') + assert str(err) == _('"{0}" is an invalid {1} for "{2}"').format('1', _('integer'), 'b') + ', ' + _('must be different from the value of {}').format('"a"') try: api.option('b').value.set(1) except Exception as err: err.prefix = '' - assert str(err) == _('must be different from the value of "{}"').format('a') + assert str(err) == _('must be different from the value of {}').format('"a"') def test_consistency_warnings_only_option(): diff --git a/tests/test_option_setting.py b/tests/test_option_setting.py index c8355aa..fef7d1c 100644 --- a/tests/test_option_setting.py +++ b/tests/test_option_setting.py @@ -621,9 +621,9 @@ def test_pprint(): except PropertiesOptionError as error: err = error - list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '"1"'), msg_is.format('string2', '"string"')]) + ')' + list_disabled = '"disabled" (' + display_list([msg_is.format('Test int option', '"1"'), msg_is.format('string2', '"string"')], add_quote=False) + ')' list_hidden = '"hidden" (' + msg_is_not.format('Test int option', display_list([2, 3, 4], 'or', add_quote=True)) + ')' - assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden]))) + assert str(err) == _(msg_error.format('option', 'Test string option', properties, display_list([list_disabled, list_hidden], add_quote=False))) del err err = None diff --git a/tiramisu/__init__.py b/tiramisu/__init__.py index bc7a6f1..2a08c8c 100644 --- a/tiramisu/__init__.py +++ b/tiramisu/__init__.py @@ -45,4 +45,4 @@ allfuncs.extend(all_options) del(all_options) __all__ = tuple(allfuncs) del(allfuncs) -__version__ = "3.0rc5" +__version__ = "3.0rc6" diff --git a/tiramisu/error.py b/tiramisu/error.py index 1e27319..f308e89 100644 --- a/tiramisu/error.py +++ b/tiramisu/error.py @@ -94,8 +94,8 @@ class PropertiesOptionError(AttributeError): only_one = len(req) == 1 msg = [] for action, msg_ in req.items(): - msg.append('"{0}" ({1})'.format(action, display_list(msg_))) - msg = display_list(msg) + msg.append('"{0}" ({1})'.format(action, display_list(msg_, add_quote=False))) + msg = display_list(msg, add_quote=False) else: only_one = len(self.proptype) == 1 msg = display_list(list(self.proptype), add_quote=True) diff --git a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po index f4d3684..ddbe7e0 100644 --- a/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po +++ b/tiramisu/locale/fr/LC_MESSAGES/tiramisu.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Tiramisu\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2019-04-08 08:41+CEST\n" +"POT-Creation-Date: 2019-04-13 21:34+CEST\n" "PO-Revision-Date: \n" "Last-Translator: Emmanuel Garette \n" "Language-Team: Tiramisu's team \n" @@ -247,49 +247,46 @@ msgstr "" "toutes les configs d'une metaconfig doivent avoir la même optiondescription" #: tiramisu/config.py:1272 -#, fuzzy -#| msgid "all config in metaconfig must have the same optiondescription" msgid "metaconfig must have the same optiondescription" -msgstr "" -"toutes les configs d'une metaconfig doivent avoir la même optiondescription" +msgstr "metaconfig doivent avoir la même optiondescription" -#: tiramisu/error.py:24 +#: tiramisu/error.py:26 msgid "and" msgstr "et" -#: tiramisu/error.py:26 +#: tiramisu/error.py:28 msgid "or" msgstr "ou" -#: tiramisu/error.py:50 +#: tiramisu/error.py:52 msgid " {} " msgstr " {} " -#: tiramisu/error.py:103 tiramisu/setting.py:579 +#: tiramisu/error.py:105 tiramisu/setting.py:579 msgid "property" msgstr "de la propriété" -#: tiramisu/error.py:105 tiramisu/setting.py:581 +#: tiramisu/error.py:107 tiramisu/setting.py:581 msgid "properties" msgstr "des propriétés" -#: tiramisu/error.py:107 +#: tiramisu/error.py:109 msgid "cannot access to {0} \"{1}\" because \"{2}\" has {3} {4}" msgstr "ne peut accéder à {0} \"{1}\" parce que \"{2}\" a {3} {4}" -#: tiramisu/error.py:114 +#: tiramisu/error.py:116 msgid "cannot access to {0} \"{1}\" because has {2} {3}" msgstr "ne peut accéder à l'{0} \"{1}\" a cause {2} {3}" -#: tiramisu/error.py:189 +#: tiramisu/error.py:191 msgid "invalid value" msgstr "valeur invalide" -#: tiramisu/error.py:194 +#: tiramisu/error.py:196 msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\"" msgstr "attention, \"{0}\" peut être un {1} invalide pour \"{2}\"" -#: tiramisu/error.py:198 tiramisu/error.py:202 +#: tiramisu/error.py:200 tiramisu/error.py:204 msgid "\"{0}\" is an invalid {1} for \"{2}\"" msgstr "\"{0}\" est une valeur invalide pour l'option \"{2}\" de type {1}" @@ -490,8 +487,8 @@ msgid "only \"{0}\" is allowed" msgstr "seul \"{0}\" est autorisé" #: tiramisu/option/choiceoption.py:117 -msgid "only \"{0}\" are allowed" -msgstr "seul \"{0}\" sont autorisés" +msgid "only {0} are allowed" +msgstr "seul {0} sont autorisés" #: tiramisu/option/dateoption.py:31 msgid "date" @@ -824,12 +821,12 @@ msgstr "" "devrait être \"{}\"" #: tiramisu/option/option.py:716 -msgid "should be different from the value of \"{}\"" -msgstr "devrait être différent de la valeur de \"{}\"" +msgid "should be different from the value of {}" +msgstr "devrait être différent de la valeur de {}" #: tiramisu/option/option.py:718 -msgid "must be different from the value of \"{}\"" -msgstr "doit être différent de la valeur de \"{}\"" +msgid "must be different from the value of {}" +msgstr "doit être différent de la valeur de {}" #: tiramisu/option/option.py:721 msgid "value for {} should be different" diff --git a/tiramisu/locale/tiramisu.pot b/tiramisu/locale/tiramisu.pot index 1cbc0d9..bdf6821 100644 --- a/tiramisu/locale/tiramisu.pot +++ b/tiramisu/locale/tiramisu.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2019-04-08 08:41+CEST\n" +"POT-Creation-Date: 2019-04-13 21:34+CEST\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -223,43 +223,43 @@ msgstr "" msgid "metaconfig must have the same optiondescription" msgstr "" -#: tiramisu/error.py:24 +#: tiramisu/error.py:26 msgid "and" msgstr "" -#: tiramisu/error.py:26 +#: tiramisu/error.py:28 msgid "or" msgstr "" -#: tiramisu/error.py:50 +#: tiramisu/error.py:52 msgid " {} " msgstr "" -#: tiramisu/error.py:103 tiramisu/setting.py:579 +#: tiramisu/error.py:105 tiramisu/setting.py:579 msgid "property" msgstr "" -#: tiramisu/error.py:105 tiramisu/setting.py:581 +#: tiramisu/error.py:107 tiramisu/setting.py:581 msgid "properties" msgstr "" -#: tiramisu/error.py:107 +#: tiramisu/error.py:109 msgid "cannot access to {0} \"{1}\" because \"{2}\" has {3} {4}" msgstr "" -#: tiramisu/error.py:114 +#: tiramisu/error.py:116 msgid "cannot access to {0} \"{1}\" because has {2} {3}" msgstr "" -#: tiramisu/error.py:189 +#: tiramisu/error.py:191 msgid "invalid value" msgstr "" -#: tiramisu/error.py:194 +#: tiramisu/error.py:196 msgid "attention, \"{0}\" could be an invalid {1} for \"{2}\"" msgstr "" -#: tiramisu/error.py:198 tiramisu/error.py:202 +#: tiramisu/error.py:200 tiramisu/error.py:204 msgid "\"{0}\" is an invalid {1} for \"{2}\"" msgstr "" @@ -429,7 +429,7 @@ msgid "only \"{0}\" is allowed" msgstr "" #: tiramisu/option/choiceoption.py:117 -msgid "only \"{0}\" are allowed" +msgid "only {0} are allowed" msgstr "" #: tiramisu/option/dateoption.py:31 @@ -729,11 +729,11 @@ msgid "unexpected length of \"{}\" in constency \"{}\", should be \"{}\"" msgstr "" #: tiramisu/option/option.py:716 -msgid "should be different from the value of \"{}\"" +msgid "should be different from the value of {}" msgstr "" #: tiramisu/option/option.py:718 -msgid "must be different from the value of \"{}\"" +msgid "must be different from the value of {}" msgstr "" #: tiramisu/option/option.py:721 diff --git a/tiramisu/option/baseoption.py b/tiramisu/option/baseoption.py index e44a7f4..50e02b2 100644 --- a/tiramisu/option/baseoption.py +++ b/tiramisu/option/baseoption.py @@ -113,7 +113,7 @@ class Base: set_forbidden_properties = calc_properties & properties if set_forbidden_properties != frozenset(): raise ValueError(_('conflict: properties already set in requirement {0} for {1}' - '').format(display_list(set_forbidden_properties), + '').format(display_list(set_forbidden_properties, add_quote=True), name)) def _get_function_args(self, diff --git a/tiramisu/option/choiceoption.py b/tiramisu/option/choiceoption.py index 63f9fcb..5683196 100644 --- a/tiramisu/option/choiceoption.py +++ b/tiramisu/option/choiceoption.py @@ -114,5 +114,5 @@ class ChoiceOption(Option): raise ValueError(_('only "{0}" is allowed' '').format(values[0])) else: - raise ValueError(_('only "{0}" are allowed' - '').format(display_list(values))) + raise ValueError(_('only {0} are allowed' + '').format(display_list(values, add_quote=True))) diff --git a/tiramisu/option/option.py b/tiramisu/option/option.py index 1ddcedb..e03a58c 100644 --- a/tiramisu/option/option.py +++ b/tiramisu/option/option.py @@ -713,9 +713,9 @@ class Option(BaseOption): if equal: if is_current: if warnings_only: - msg = _('should be different from the value of "{}"') + msg = _('should be different from the value of {}') else: - msg = _('must be different from the value of "{}"') + msg = _('must be different from the value of {}') else: if warnings_only: msg = _('value for {} should be different') @@ -724,7 +724,7 @@ class Option(BaseOption): equal_name = [] for opt in equal: equal_name.append(opt.impl_get_display_name()) - raise ValueError(msg.format(display_list(list(equal_name)))) + raise ValueError(msg.format(display_list(list(equal_name), add_quote=True))) def to_dynoption(self, rootpath: str,