| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 77ffbe6 commit ae5840f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | # TODO: | |
| 14 | + # - Add new tests, for example for "dgettext" | ||
| 14 | 15 | # - Tests should have only one assert. | |
| 15 | 16 | ||
| 16 | 17 | GNU_MO_DATA = b'''\ | |
@@ -939,46 +940,24 @@ def test_lazy_import(self): | |||
| 939 | 940 | class DGettextTest(GettextBaseTest): | |
| 940 | 941 | ||
| 941 | 942 | def setUp(self): | |
| 942 | - GettextBaseTest.setUp(self) | ||
| 943 | + super().setUp() | ||
| 943 | 944 | gettext.bindtextdomain('gettext', os.curdir) | |
| 944 | 945 | ||
| 945 | - def test_dgettext_found_translation(self): | ||
| 946 | - result = gettext.dgettext('gettext', 'mullusk') | ||
| 947 | - self.assertEqual(result, 'bacon') | ||
| 946 | + def test_dgettext_translation(self): | ||
| 947 | + translation_cases = [ | ||
| 948 | + ('gettext', 'mullusk', 'bacon'), | ||
| 949 | + ('gettext', 'Raymond Luxury Yach-t', 'Throatwobbler Mangrove'), | ||
| 950 | + ('gettext', 'nudge nudge', 'wink wink'), | ||
| 948 | 951 | ||
| 949 | - def test_dgettext_fallback_cases(self): | ||
| 950 | - test_cases = [ | ||
| 951 | - ('gettext', 'missing message'), | ||
| 952 | - ('nonexistent_domain', 'mullusk'), | ||
| 953 | - ('', 'mullusk'), | ||
| 952 | + ('gettext', 'missing message', 'missing message'), | ||
| 953 | + ('nonexistent_domain', 'mullusk', 'mullusk'), | ||
| 954 | + ('', 'mullusk', gettext.gettext('mullusk')), | ||
| 954 | 955 | ] | |
| 955 | - for domain, message in test_cases: | ||
| 956 | - with self.subTest(domain=domain, message=message): | ||
| 957 | - result = gettext.dgettext(domain, message) | ||
| 958 | - if domain == '': | ||
| 959 | - expected = gettext.gettext(message) | ||
| 960 | - else: | ||
| 961 | - expected = message | ||
| 956 | + for domain, msgid, expected in translation_cases: | ||
| 957 | + with self.subTest(domain=domain, msgid=msgid): | ||
| 958 | + result = gettext.dgettext(domain, msgid) | ||
| 962 | 959 | self.assertEqual(result, expected) | |
| 963 | 960 | ||
| 964 | - def test_dgettext_luxury_yacht_translation(self): | ||
| 965 | - result = gettext.dgettext('gettext', 'Raymond Luxury Yach-t') | ||
| 966 | - self.assertEqual(result, 'Throatwobbler Mangrove') | ||
| 967 | - | ||
| 968 | - def test_dgettext_nudge_nudge_translation(self): | ||
| 969 | - result = gettext.dgettext('gettext', 'nudge nudge') | ||
| 970 | - self.assertEqual(result, 'wink wink') | ||
| 971 | - | ||
| 972 | - def test_dgettext_multiline_translation(self): | ||
| 973 | - message = '''This module provides internationalization and localization | ||
| 974 | - support for your Python programs by providing an interface to the GNU | ||
| 975 | - gettext message catalog library.''' | ||
| 976 | - expected = '''Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba | ||
| 977 | - fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH | ||
| 978 | - trggrkg zrffntr pngnybt yvoenel.''' | ||
| 979 | - result = gettext.dgettext('gettext', message) | ||
| 980 | - self.assertEqual(result, expected) | ||
| 981 | - | ||
| 982 | 961 | ||
| 983 | 962 | if __name__ == '__main__': | |
| 984 | 963 | unittest.main() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments