[mod] during tests failed to translate string is an error

This commit is contained in:
Laurent Peuch 2019-07-28 21:29:50 +02:00
parent fdf9a719f1
commit 2403ee1b7d
2 changed files with 21 additions and 4 deletions

View file

@ -15,6 +15,10 @@ from moulinette.cache import get_cachedir
logger = logging.getLogger('moulinette.core')
def during_unittests_run():
return "TESTS_RUN" in os.environ
# Internationalization -------------------------------------------------
class Translator(object):
@ -97,7 +101,10 @@ class Translator(object):
key, unformatted_string, args, kwargs, e.__class__.__name__, e
)
logger.exception(error_message)
if not during_unittests_run():
logger.exception(error_message)
else:
raise Exception(error_message)
failed_to_format = True
@ -112,11 +119,20 @@ class Translator(object):
error_message = "Failed to format translatable string '%s': '%s' with arguments '%s' and '%s', raising error: %s(%s) (don't panic this is just a warning)" % (
key, unformatted_string, args, kwargs, e.__class__.__name__, e
)
logger.exception(error_message)
if not during_unittests_run():
logger.exception(error_message)
else:
raise Exception(error_message)
return self._translations[self.locale][key].encode('utf-8')
logger.exception("unable to retrieve string to translate with key '%s' for default locale 'locales/%s.json' file (don't panic this is just a warning)",
key, self.default_locale)
error_message = "unable to retrieve string to translate with key '%s' for default locale 'locales/%s.json' file (don't panic this is just a warning)" % key, self.default_locale
if not during_unittests_run():
logger.exception(error_message)
else:
raise Exception(error_message)
return key
def _load_translations(self, locale, overwrite=False):

View file

@ -4,3 +4,4 @@ norecursedirs = dist doc build .tox .eggs
testpaths = test/
env =
MOULINETTE_LOCALES_DIR = {PWD}/locales
TESTS_RUN = True