mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-23 15:40:01 -06:00
Improve the robustness FreeIPA's i18n module and its tests
Prevent false positive errors reported by `ipatests/i18n.py` and `ipatests/test_ipalib/test_text.py` when LANGUAGE env variable is set in the environment. Additionally, also set LC_ALL and LC_MESSAGES during checks to further improve the robustness. https://fedorahosted.org/freeipa/ticket/6512 Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
parent
6bbbce4473
commit
211c944a35
@ -602,8 +602,11 @@ def test_translations(po_file, lang, domain, locale_dir):
|
||||
# use a dummy language not associated with any real language,
|
||||
# but the setlocale function demands the locale be a valid
|
||||
# known locale, Zambia Xhosa is a reasonable choice :)
|
||||
locale_envs = ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG')
|
||||
|
||||
os.environ['LANG'] = lang
|
||||
os.environ.update(
|
||||
{locale_env: lang for locale_env in locale_envs}
|
||||
)
|
||||
|
||||
# Create a gettext translation object specifying our domain as
|
||||
# 'ipa' and the locale_dir as 'test_locale' (i.e. where to
|
||||
|
@ -52,11 +52,36 @@ def test_create_translation():
|
||||
|
||||
|
||||
class test_TestLang(object):
|
||||
lang_env_vars = {'LC_ALL', 'LC_MESSAGES', 'LANGUAGE', 'LANG'}
|
||||
|
||||
def setup_lang(self):
|
||||
"""
|
||||
Set all env variables used by gettext to localize translation files
|
||||
to xh_ZA
|
||||
"""
|
||||
self.lang = 'xh_ZA'
|
||||
self.saved_locale = {
|
||||
k: v for k, v in os.environ.items() if k in self.lang_env_vars}
|
||||
|
||||
os.environ.update(
|
||||
{env_var: self.lang for env_var in self.lang_env_vars}
|
||||
)
|
||||
|
||||
def teardown_lang(self):
|
||||
"""
|
||||
Revert the locale settings to original values. If the original env
|
||||
variable was not set before, it will be popped off os.environ
|
||||
"""
|
||||
for env_var in self.lang_env_vars:
|
||||
if env_var not in self.saved_locale:
|
||||
os.environ.pop(env_var, None)
|
||||
|
||||
os.environ.update(self.saved_locale)
|
||||
|
||||
def setup(self):
|
||||
self.tmp_dir = None
|
||||
self.saved_lang = None
|
||||
self.setup_lang()
|
||||
|
||||
self.lang = 'xh_ZA'
|
||||
self.domain = 'ipa'
|
||||
|
||||
self.pot_basename = '%s.pot' % self.domain
|
||||
@ -64,7 +89,6 @@ class test_TestLang(object):
|
||||
self.mo_basename = '%s.mo' % self.domain
|
||||
|
||||
self.tmp_dir = tempfile.mkdtemp()
|
||||
self.saved_lang = os.environ['LANG']
|
||||
|
||||
self.locale_dir = os.path.join(self.tmp_dir, 'test_locale')
|
||||
self.msg_dir = os.path.join(self.locale_dir, self.lang, 'LC_MESSAGES')
|
||||
@ -93,8 +117,7 @@ class test_TestLang(object):
|
||||
self.po_file_iterate = po_file_iterate
|
||||
|
||||
def teardown(self):
|
||||
if self.saved_lang is not None:
|
||||
os.environ['LANG'] = self.saved_lang
|
||||
self.teardown_lang()
|
||||
|
||||
if self.tmp_dir is not None:
|
||||
shutil.rmtree(self.tmp_dir)
|
||||
@ -107,7 +130,6 @@ class test_TestLang(object):
|
||||
# but the setlocale function demands the locale be a valid
|
||||
# known locale, Zambia Xhosa is a reasonable choice :)
|
||||
|
||||
os.environ['LANG'] = self.lang
|
||||
|
||||
# Create a gettext translation object specifying our domain as
|
||||
# 'ipa' and the locale_dir as 'test_locale' (i.e. where to
|
||||
|
Loading…
Reference in New Issue
Block a user