#6512 Improve the robustness FreeIPA's i18n module and its tests
Closed: Fixed None Opened 8 years ago by mbabinsk.

FreeIPA's i18n module and the unit tests set LANG environment variable during some checks. However, according to Gettext documentation, LANG is acutally the last of the variables ("...LANGUAGE, LC_ALL, LC_MESSAGES, and LANG respectively." [1]) checked by Gettext in order to locate translation files. This means that setting one of the preceding variables breaks ipalib/test_text.py and i18n.py --test-gettext command called during make polint.

We should make sure that all these variables are set to test language so that there are no false negatives errors, and also to future-proof our code in the unlikely scenario that the order of their importance will be changed.

Example steps to reproduce:

1.) run LANGUAGE="C" make polint or LANGUAGE="C" ./make-tests test_ipalib/test_text.py

Expected results:

The first command succesfully validates all transations, while the second one produces green tests

Actual results:

The first command fails on IOError: [Errno 2] No translation file found for domain: 'ipa'

The second on eresults in failing test_test_lang

def test_test_lang(self):
        print("test_test_lang")
        # The test installs the test message catalog under the xh_ZA
        # (e.g. Zambia Xhosa) language by default. It would be nice to
        # 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 :)

        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
        # look for the message catalog). Then use that translation
        # object to obtain the translation functions.

        def get_msgstr(msg):
            gt = text.GettextFactory(localedir=self.locale_dir)(msg)
            return unicode(gt)

        def get_msgstr_plural(singular, plural, count):
            ng = text.NGettextFactory(localedir=self.locale_dir)(singular, plural, count)
            return ng(count)

        result = self.po_file_iterate(self.po_file, get_msgstr, get_msgstr_plural)
>       assert result == 0
E       assert 1 == 0

ipatests/test_ipalib/test_text.py:126: AssertionError
---------------------------------------------------------------------------------------------------------- Captured stdout setup -----------------------------------------------------------------------------------------------------------
Wrote: /tmp/tmp4nID6F/xh_ZA.po
Wrote: /tmp/tmp4nID6F/test_locale/xh_ZA/LC_MESSAGES/ipa.mo
----------------------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------------------
test_test_lang
----------------------------------------------------------------------------------------------------------- Captured stderr call -----------------------------------------------------------------------------------------------------------
ERROR: First char in translated string "Failed members" not equal to prefix "→"
ERROR: First char in translated string "Failed source hosts/hostgroups" not equal to prefix "→"
ERROR: First char in translated string "Failed hosts/hostgroups" not equal to prefix "→"
ERROR: First char in translated string "Failed users/groups" not equal to prefix "→"
ERROR: First char in translated string "%(count)d %(type)s record skipped. Only one value per DNS record type can be modified at one time." not equal to prefix "→"
ERROR: First char in translated string "%(count)d %(type)s records skipped. Only one value per DNS record type can be modified at one time." not equal to prefix "→"
ERROR: 6 failures out of 5 translations

[1] https://docs.python.org/2.7/library/gettext.html


master:

  • 211c944 Improve the robustness FreeIPA's i18n module and its tests

Metadata Update from @mbabinsk:
- Issue assigned to mbabinsk
- Issue set to the milestone: FreeIPA 4.5

8 years ago

Log in to comment on this ticket.

Metadata