Skip to content

[3.13] gh-130655: Increase test coverage of gettext._expand_lang() (GH-130656) #130671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import base64
import gettext
import unittest
import unittest.mock
from functools import partial

from test import support
Expand Down Expand Up @@ -741,6 +742,32 @@ def test_cache(self):
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):
def test__all__(self):
support.check__all__(self, gettext,
Expand Down
Loading