From e1896697b74fe68671842eac4044314077b17a5c Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 22 Feb 2025 13:40:51 +0100 Subject: [PATCH] Test gettext._expand_lang --- Lib/test/test_gettext.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index cddd859001d818..970ab9fe7acb4a 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -2,6 +2,7 @@ import base64 import gettext import unittest +import unittest.mock from functools import partial from test import support @@ -691,6 +692,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,