Skip to content

Commit 535f12d

Browse files
tomasr8miss-islington
authored andcommitted
pythongh-130655: Increase test coverage of gettext._expand_lang() (pythonGH-130656)
(cherry picked from commit 24c52cb) Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
1 parent ad97027 commit 535f12d

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_gettext.py

+27
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import base64
33
import gettext
44
import unittest
5+
import unittest.mock
56
from functools import partial
67

78
from test import support
@@ -741,6 +742,32 @@ def test_cache(self):
741742
self.assertEqual(t.__class__, DummyGNUTranslations)
742743

743744

745+
class ExpandLangTestCase(unittest.TestCase):
746+
def test_expand_lang(self):
747+
# Test all combinations of territory, charset and
748+
# modifier (locale extension)
749+
locales = {
750+
'cs': ['cs'],
751+
'cs_CZ': ['cs_CZ', 'cs'],
752+
'cs.ISO8859-2': ['cs.ISO8859-2', 'cs'],
753+
'cs@euro': ['cs@euro', 'cs'],
754+
'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'cs_CZ', 'cs.ISO8859-2',
755+
'cs'],
756+
'cs_CZ@euro': ['cs_CZ@euro', 'cs@euro', 'cs_CZ', 'cs'],
757+
'cs.ISO8859-2@euro': ['cs.ISO8859-2@euro', 'cs@euro',
758+
'cs.ISO8859-2', 'cs'],
759+
'cs_CZ.ISO8859-2@euro': ['cs_CZ.ISO8859-2@euro', 'cs_CZ@euro',
760+
'cs.ISO8859-2@euro', 'cs@euro',
761+
'cs_CZ.ISO8859-2', 'cs_CZ',
762+
'cs.ISO8859-2', 'cs'],
763+
}
764+
for locale, expanded in locales.items():
765+
with self.subTest(locale=locale):
766+
with unittest.mock.patch("locale.normalize",
767+
return_value=locale):
768+
self.assertEqual(gettext._expand_lang(locale), expanded)
769+
770+
744771
class MiscTestCase(unittest.TestCase):
745772
def test__all__(self):
746773
support.check__all__(self, gettext,

0 commit comments

Comments
 (0)