From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 28 Feb 2025 09:02:18 +0000 (+0100) Subject: [3.13] gh-130655: Increase test coverage of gettext._expand_lang() (GH-130656) (GH... X-Git-Tag: v3.13.3~194 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b223dc70cdddc6d3f21840b629e99c98b16433eb;p=thirdparty%2FPython%2Fcpython.git [3.13] gh-130655: Increase test coverage of gettext._expand_lang() (GH-130656) (GH-130671) (cherry picked from commit 24c52cb14c4b044154bd46bd1b2a9c37076caeb9) Co-authored-by: Tomas R --- diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index e0cd6a7e3cc4..a0d77dcceeff 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -2,6 +2,7 @@ import os import base64 import gettext import unittest +import unittest.mock from functools import partial from test import support @@ -741,6 +742,32 @@ class GettextCacheTestCase(GettextBaseTest): 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,