|
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 |
@@ -691,6 +692,32 @@ def test_cache(self): |
691 | 692 | self.assertEqual(t.__class__, DummyGNUTranslations) |
692 | 693 |
|
693 | 694 |
|
| 695 | +class ExpandLangTestCase(unittest.TestCase): |
| 696 | + def test_expand_lang(self): |
| 697 | + # Test all combinations of territory, charset and |
| 698 | + # modifier (locale extension) |
| 699 | + locales = { |
| 700 | + 'cs': ['cs'], |
| 701 | + 'cs_CZ': ['cs_CZ', 'cs'], |
| 702 | + 'cs.ISO8859-2': ['cs.ISO8859-2', 'cs'], |
| 703 | + 'cs@euro': ['cs@euro', 'cs'], |
| 704 | + 'cs_CZ.ISO8859-2': ['cs_CZ.ISO8859-2', 'cs_CZ', 'cs.ISO8859-2', |
| 705 | + 'cs'], |
| 706 | + 'cs_CZ@euro': ['cs_CZ@euro', 'cs@euro', 'cs_CZ', 'cs'], |
| 707 | + 'cs.ISO8859-2@euro': ['cs.ISO8859-2@euro', 'cs@euro', |
| 708 | + 'cs.ISO8859-2', 'cs'], |
| 709 | + 'cs_CZ.ISO8859-2@euro': ['cs_CZ.ISO8859-2@euro', 'cs_CZ@euro', |
| 710 | + 'cs.ISO8859-2@euro', 'cs@euro', |
| 711 | + 'cs_CZ.ISO8859-2', 'cs_CZ', |
| 712 | + 'cs.ISO8859-2', 'cs'], |
| 713 | + } |
| 714 | + for locale, expanded in locales.items(): |
| 715 | + with self.subTest(locale=locale): |
| 716 | + with unittest.mock.patch("locale.normalize", |
| 717 | + return_value=locale): |
| 718 | + self.assertEqual(gettext._expand_lang(locale), expanded) |
| 719 | + |
| 720 | + |
694 | 721 | class MiscTestCase(unittest.TestCase): |
695 | 722 | def test__all__(self): |
696 | 723 | support.check__all__(self, gettext, |
|
0 commit comments