[3.12] gh-130655: Increase test coverage of gettext._expand_lang() (GH-130656) (GH-130672)

(cherry picked from commit 24c52cb14c)

Co-authored-by: Tomas R <tomas.roun8@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-02-28 09:58:09 +01:00 committed by GitHub
parent 500ea3b0ee
commit aa91a11c40
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@ import os
import base64 import base64
import gettext import gettext
import unittest import unittest
import unittest.mock
from functools import partial from functools import partial
from test import support from test import support
@ -739,6 +740,32 @@ class GettextCacheTestCase(GettextBaseTest):
self.assertEqual(t.__class__, DummyGNUTranslations) self.assertEqual(t.__class__, DummyGNUTranslations)
class ExpandLangTestCase(unittest.TestCase):
def test_expand_lang(self):
# Test all combinations of territory, charset and
# modifier (locale extension)
locales = {
'cs': ['cs'],
'cs_CZ': ['cs_CZ', 'cs'],
'cs.ISO8859-2': ['cs.ISO8859-2', 'cs'],
'cs@euro': ['cs@euro', 'cs'],
'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'cs_CZ', 'cs.ISO8859-2',
'cs'],
'cs_CZ@euro': ['cs_CZ@euro', 'cs@euro', 'cs_CZ', 'cs'],
'cs.ISO8859-2@euro': ['cs.ISO8859-2@euro', 'cs@euro',
'cs.ISO8859-2', 'cs'],
'cs_CZ.ISO8859-2@euro': ['cs_CZ.ISO8859-2@euro', 'cs_CZ@euro',
'cs.ISO8859-2@euro', 'cs@euro',
'cs_CZ.ISO8859-2', 'cs_CZ',
'cs.ISO8859-2', 'cs'],
}
for locale, expanded in locales.items():
with self.subTest(locale=locale):
with unittest.mock.patch("locale.normalize",
return_value=locale):
self.assertEqual(gettext._expand_lang(locale), expanded)
class MiscTestCase(unittest.TestCase): class MiscTestCase(unittest.TestCase):
def test__all__(self): def test__all__(self):
support.check__all__(self, gettext, support.check__all__(self, gettext,