Skip to content

Commit 24c52cb

Browse files
authored
pythongh-130655: Increase test coverage of gettext._expand_lang() (pythonGH-130656)
1 parent 7f39137 commit 24c52cb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Lib/test/test_gettext.py

Lines changed: 27 additions & 0 deletions
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
@@ -691,6 +692,32 @@ def test_cache(self):
691692
self.assertEqual(t.__class__, DummyGNUTranslations)
692693

693694

695+
class ExpandLangTestCase(unittest.TestCase):
696+
def test_expand_lang(self):
697+
# Test all combinations of territory, charset and
698+
# modifier (locale extension)
699+
locales = {
700+
'cs': ['cs'],
701+
'cs_CZ': ['cs_CZ', 'cs'],
702+
'cs.ISO8859-2': ['cs.ISO8859-2', 'cs'],
703+
'cs@euro': ['cs@euro', 'cs'],
704+
'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'cs_CZ', 'cs.ISO8859-2',
705+
'cs'],
706+
'cs_CZ@euro': ['cs_CZ@euro', 'cs@euro', 'cs_CZ', 'cs'],
707+
'cs.ISO8859-2@euro': ['cs.ISO8859-2@euro', 'cs@euro',
708+
'cs.ISO8859-2', 'cs'],
709+
'cs_CZ.ISO8859-2@euro': ['cs_CZ.ISO8859-2@euro', 'cs_CZ@euro',
710+
'cs.ISO8859-2@euro', 'cs@euro',
711+
'cs_CZ.ISO8859-2', 'cs_CZ',
712+
'cs.ISO8859-2', 'cs'],
713+
}
714+
for locale, expanded in locales.items():
715+
with self.subTest(locale=locale):
716+
with unittest.mock.patch("locale.normalize",
717+
return_value=locale):
718+
self.assertEqual(gettext._expand_lang(locale), expanded)
719+
720+
694721
class MiscTestCase(unittest.TestCase):
695722
def test__all__(self):
696723
support.check__all__(self, gettext,

0 commit comments

Comments
 (0)