|
1 | | -import locale |
2 | 1 | import os |
3 | 2 | import base64 |
4 | 3 | import gettext |
@@ -737,30 +736,32 @@ def create_mo_file(self, lang): |
737 | 736 | f.write(GNU_MO_DATA) |
738 | 737 | return mo_file |
739 | 738 |
|
740 | | - @unittest.mock.patch("locale.getlocale", return_value=(None, None)) |
741 | | - def test_find_with_env_vars(self, patch_getlocale): |
742 | | - # test that find correctly finds the environment variables |
743 | | - # when languages are not supplied |
744 | | - mo_file = self.create_mo_file("ga_IE") |
745 | | - for var in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): |
746 | | - self.env.set(var, 'ga_IE') |
747 | | - result = gettext.find("mofile", |
748 | | - localedir=os.path.join(self.tempdir, "locale")) |
749 | | - self.assertEqual(result, mo_file) |
750 | | - self.env.unset(var) |
751 | | - # test fallbacks |
| 739 | + def _for_all_vars(self, mo_file, locale): |
752 | 740 | for var in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'): |
753 | | - self.env.set(var, 'es_ES:ga_IE:fr_FR') |
| 741 | + self.env.set(var, locale) |
754 | 742 | result = gettext.find("mofile", |
755 | 743 | localedir=os.path.join(self.tempdir, "locale")) |
756 | | - self.assertEqual(result, mo_file) |
| 744 | + self.assertEqual(mo_file, result) |
757 | 745 | self.env.unset(var) |
758 | 746 |
|
759 | | - @unittest.mock.patch("locale.getlocale", return_value=('ga_IE', 'UTF-8')) |
760 | | - def test_process_vars_override(self, patch_getlocale): |
| 747 | + @unittest.mock.patch("locale.setlocale", return_value=(None, None)) |
| 748 | + def test_find_with_env_vars(self, patch_getlocale): |
| 749 | + # test that find correctly finds the environment variables |
| 750 | + # when languages are not supplied |
761 | 751 | mo_file = self.create_mo_file("ga_IE") |
762 | | - result = gettext.find("mofile", localedir=os.path.join(self.tempdir, "locale")) |
763 | | - self.assertEqual(result, mo_file) |
| 752 | + self._for_all_vars(mo_file, "ga_IE") |
| 753 | + self._for_all_vars(mo_file, "ga_IE.UTF-8") |
| 754 | + self._for_all_vars(mo_file, "es_ES:ga_IE:fr_FR") |
| 755 | + self._for_all_vars(mo_file, "ga_IE@euro") |
| 756 | + |
| 757 | + def test_process_vars_override(self): |
| 758 | + mo_file = self.create_mo_file("ga_IE") |
| 759 | + with unittest.mock.patch("locale.setlocale", return_value=('ga_IE', 'UTF-8')): |
| 760 | + result = gettext.find("mofile", localedir=os.path.join(self.tempdir, "locale")) |
| 761 | + self.assertEqual(mo_file, result) |
| 762 | + with unittest.mock.patch("locale.setlocale", return_value=('ga_IE', None)): |
| 763 | + result = gettext.find("mofile", localedir=os.path.join(self.tempdir, "locale")) |
| 764 | + self.assertEqual(mo_file, result) |
764 | 765 |
|
765 | 766 | def test_find_with_languages(self): |
766 | 767 | # test that passed languages are used |
|
0 commit comments