Added i18n unittest

This commit is contained in:
Manuel Cortez 2018-12-30 10:29:57 -06:00
parent eded301016
commit f70ef51551
3 changed files with 30 additions and 1 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import unittest import unittest
testmodules = ['test.test_storage', 'test.test_extractors', 'test.test_fixes'] testmodules = ['test.test_storage', 'test.test_extractors', 'test.test_fixes', 'test.test_i18n']
suite = unittest.TestSuite() suite = unittest.TestSuite()

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
""" Unittests for fixers applied in some cases. """ """ Unittests for fixers applied in some cases. """
from __future__ import unicode_literals from __future__ import unicode_literals
import os import os

28
src/test/test_i18n.py Normal file
View File

@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
""" Unittests for internationalization features. This test is here for avoiding breaking things between gettext for python 2 and 3. """
from __future__ import unicode_literals
import os
import unittest
import sys
import i18n
# Python 2/3 compat.
if sys.version[0] == "2":
strtype = unicode
else:
strtype = str
class i18nTestCase(unittest.TestCase):
def test_i18n_unicode(self):
""" Testing gettext function so it will generate only unicode strings both in python 2 and 3. """
i18n.setup()
# If something happened to i18n, it should raise a traceback in the next call
translated_str = _("This is a string with no special characters.")
self.assertIsInstance(translated_str, strtype)
# Test something with a special character here.
localized_fake_str = _("Привет всем")
self.assertIsInstance(localized_fake_str, strtype)
if __name__ == "__main__":
unittest.main()