|
2 | 2 | import base64
|
3 | 3 | import gettext
|
4 | 4 | import unittest
|
| 5 | +import unittest.mock |
5 | 6 | from functools import partial
|
6 | 7 |
|
7 | 8 | from test import support
|
@@ -739,6 +740,32 @@ def test_cache(self):
|
739 | 740 | self.assertEqual(t.__class__, DummyGNUTranslations)
|
740 | 741 |
|
741 | 742 |
|
| 743 | +class ExpandLangTestCase(unittest.TestCase): |
| 744 | + def test_expand_lang(self): |
| 745 | + # Test all combinations of territory, charset and |
| 746 | + # modifier (locale extension) |
| 747 | + locales = { |
| 748 | + 'cs': ['cs'], |
| 749 | + 'cs_CZ': ['cs_CZ', 'cs'], |
| 750 | + 'cs.ISO8859-2': ['cs.ISO8859-2', 'cs'], |
| 751 | + 'cs@euro': ['cs@euro', 'cs'], |
| 752 | + 'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'cs_CZ', 'cs.ISO8859-2', |
| 753 | + 'cs'], |
| 754 | + 'cs_CZ@euro': ['cs_CZ@euro', 'cs@euro', 'cs_CZ', 'cs'], |
| 755 | + 'cs.ISO8859-2@euro': ['cs.ISO8859-2@euro', 'cs@euro', |
| 756 | + 'cs.ISO8859-2', 'cs'], |
| 757 | + 'cs_CZ.ISO8859-2@euro': ['cs_CZ.ISO8859-2@euro', 'cs_CZ@euro', |
| 758 | + 'cs.ISO8859-2@euro', 'cs@euro', |
| 759 | + 'cs_CZ.ISO8859-2', 'cs_CZ', |
| 760 | + 'cs.ISO8859-2', 'cs'], |
| 761 | + } |
| 762 | + for locale, expanded in locales.items(): |
| 763 | + with self.subTest(locale=locale): |
| 764 | + with unittest.mock.patch("locale.normalize", |
| 765 | + return_value=locale): |
| 766 | + self.assertEqual(gettext._expand_lang(locale), expanded) |
| 767 | + |
| 768 | + |
742 | 769 | class MiscTestCase(unittest.TestCase):
|
743 | 770 | def test__all__(self):
|
744 | 771 | support.check__all__(self, gettext,
|
|
0 commit comments