diff options
author | Barry Warsaw <barry@python.org> | 2000-08-30 03:32:07 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2000-08-30 03:32:07 (GMT) |
commit | 64dab4602e17878e816ae1d3f48b2f589ceebdfb (patch) | |
tree | 79feda5854806c40c26f6b6f04a7cf53731e0602 /Lib/test/test_gettext.py | |
parent | 47eceeaaa4d1b3e07427c59c79e6434cad55cf60 (diff) | |
download | cpython-64dab4602e17878e816ae1d3f48b2f589ceebdfb.zip cpython-64dab4602e17878e816ae1d3f48b2f589ceebdfb.tar.gz cpython-64dab4602e17878e816ae1d3f48b2f589ceebdfb.tar.bz2 |
Expand the test suite to test both the GNU gettext and translation
class-based APIs.
Diffstat (limited to 'Lib/test/test_gettext.py')
-rw-r--r-- | Lib/test/test_gettext.py | 380 |
1 files changed, 128 insertions, 252 deletions
diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index 77a6e96..5e61ba5 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -2,36 +2,36 @@ import os import base64 import gettext -def test(localedir, mofile): + +def test_api_1(localedir, mofile): + print 'test api 1' + # Test basic interface os.environ['LANGUAGE'] = 'xx' print 'installing gettext' - gettext.install() - - print _('calling bindtextdomain with localedir %s') % localedir - print gettext.bindtextdomain('gettext', localedir) - print gettext.bindtextdomain() - - print gettext.textdomain('gettext') - print gettext.textdomain() + gettext.install('gettext', localedir) # test some translations + print _('albatross') print _(u'mullusk') print _(r'Raymond Luxury Yach-t') print _(ur'nudge nudge') # double quotes + print _("albatross") print _(u"mullusk") print _(r"Raymond Luxury Yach-t") print _(ur"nudge nudge") # triple single quotes + print _('''albatross''') print _(u'''mullusk''') print _(r'''Raymond Luxury Yach-t''') print _(ur'''nudge nudge''') # triple double quotes + print _("""albatross""") print _(u"""mullusk""") print _(r"""Raymond Luxury Yach-t""") print _(ur"""nudge nudge""") @@ -41,62 +41,89 @@ def test(localedir, mofile): support for your Python programs by providing an interface to the GNU gettext message catalog library.''') - print gettext.dgettext('gettext', 'nudge nudge') - # test the alternative interface fp = open(os.path.join(mofile), 'rb') t = gettext.GNUTranslations(fp) fp.close() - gettext.set(t) - print t == gettext.get() + t.install() print _('nudge nudge') + # try unicode return type + t.install(unicode=1) + + print _('mullusk') + + + +def test_api_2(localedir, mofile): + print 'test api 2' + + gettext.bindtextdomain('gettext', localedir) + print gettext.bindtextdomain('gettext') == localedir + + gettext.textdomain('gettext') + # should return 'gettext' + print gettext.textdomain() + + # local function override builtin + _ = gettext.gettext + + # test some translations + print _('albatross') + print _(u'mullusk') + print _(r'Raymond Luxury Yach-t') + print _(ur'nudge nudge') + + # double quotes + print _("albatross") + print _(u"mullusk") + print _(r"Raymond Luxury Yach-t") + print _(ur"nudge nudge") + + # triple single quotes + print _('''albatross''') + print _(u'''mullusk''') + print _(r'''Raymond Luxury Yach-t''') + print _(ur'''nudge nudge''') + + # triple double quotes + print _("""albatross""") + print _(u"""mullusk""") + print _(r"""Raymond Luxury Yach-t""") + print _(ur"""nudge nudge""") + + # multiline strings + print _('''This module provides internationalization and localization +support for your Python programs by providing an interface to the GNU +gettext message catalog library.''') + + # Now test dgettext() + def _(message): + return gettext.dgettext('gettext') + + + GNU_MO_DATA = '''\ 3hIElQAAAAAFAAAAHAAAAEQAAAAHAAAAbAAAAAAAAACIAAAAFQAAAIkAAAChAAAAnwAAAAcAAABB -AQAACwAAAEkBAAAWAQAAVQEAABYAAABsAgAAoQAAAIMCAAAFAAAAJQMAAAkAAAArAwAAAQAAAAQA +AQAACwAAAEkBAAAbAQAAVQEAABYAAABxAgAAoQAAAIgCAAAFAAAAKgMAAAkAAAAwAwAAAQAAAAQA AAACAAAAAAAAAAUAAAAAAAAAAwAAAABSYXltb25kIEx1eHVyeSBZYWNoLXQAVGhpcyBtb2R1bGUg cHJvdmlkZXMgaW50ZXJuYXRpb25hbGl6YXRpb24gYW5kIGxvY2FsaXphdGlvbgpzdXBwb3J0IGZv ciB5b3VyIFB5dGhvbiBwcm9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== ''' + LOCALEDIR = os.path.join('xx', 'LC_MESSAGES') MOFILE = os.path.join(LOCALEDIR, 'gettext.mo') @@ -111,214 +138,63 @@ def teardown(): os.removedirs(LOCALEDIR) - try: setup() - test('.', MOFILE) + test_api_1('.', MOFILE) + test_api_2('.', MOFILE) finally: teardown() pass -# For reference, here's the .pot and .po files used to created the .mo data -# above. The .pot file was generated by pygettext. - -# =============================== messages.pot - -### SOME DESCRIPTIVE TITLE. -### Copyright (C) YEAR ORGANIZATION -### FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. -### -##msgid "" -##msgstr "" -##"Project-Id-Version: PACKAGE VERSION\n" -##"PO-Revision-Date: Fri Aug 18 20:45:03 2000\n" -##"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -##"Language-Team: LANGUAGE <LL@li.org>\n" -##"MIME-Version: 1.0\n" -##"Content-Type: text/plain; charset=CHARSET\n" -##"Content-Transfer-Encoding: ENCODING\n" -##"Generated-By: pygettext.py 1.1\n" - - -###: Lib/test/test_gettext.py:34 -##msgid "calling textdomain" -##msgstr "" - -###: Lib/test/test_gettext.py:94 -##msgid "dgettext failed" -##msgstr "" - -###: Lib/test/test_gettext.py:25 -##msgid "gettext installed" -##msgstr "" - -###: Lib/test/test_gettext.py:32 -##msgid "bindtextdomain(None) failed" -##msgstr "" - -###: Lib/test/test_gettext.py:44 Lib/test/test_gettext.py:54 -###: Lib/test/test_gettext.py:64 Lib/test/test_gettext.py:74 -##msgid "Raymond Luxury Yach-t" -##msgstr "" - -###: Lib/test/test_gettext.py:41 Lib/test/test_gettext.py:51 -###: Lib/test/test_gettext.py:61 Lib/test/test_gettext.py:71 -##msgid "mullusk" -##msgstr "" - -###: Lib/test/test_gettext.py:38 -##msgid "text domain didn't get set properly" -##msgstr "" - -###: Lib/test/test_gettext.py:98 -##msgid "dcgettext failed" -##msgstr "" - -###: Lib/test/test_gettext.py:47 Lib/test/test_gettext.py:57 -###: Lib/test/test_gettext.py:67 Lib/test/test_gettext.py:77 -##msgid "nudge nudge" -##msgstr "" - -###: Lib/test/test_gettext.py:45 Lib/test/test_gettext.py:55 -###: Lib/test/test_gettext.py:65 Lib/test/test_gettext.py:75 -##msgid "raw string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:30 -##msgid "got unexpected localedir" -##msgstr "" - -###: Lib/test/test_gettext.py:48 Lib/test/test_gettext.py:58 -###: Lib/test/test_gettext.py:68 Lib/test/test_gettext.py:78 -##msgid "raw Unicode string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:42 Lib/test/test_gettext.py:52 -###: Lib/test/test_gettext.py:62 Lib/test/test_gettext.py:72 -##msgid "Unicode translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:90 -##msgid "multiline string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:81 -##msgid "" -##"This module provides internationalization and localization\n" -##"support for your Python programs by providing an interface to the GNU\n" -##"gettext message catalog library." -##msgstr "" - -###: Lib/test/test_gettext.py:26 -##msgid "calling bindtextdomain with localdir %s" -##msgstr "" - -# =============================== messages.po - -### Dummy translation for Python's test_gettext.py module. -### Copyright (C) 2000 BeOpen.com -### Barry Warsaw <bwarsaw@beopen.com>, 2000. -### -###, fuzzy -##msgid "" -##msgstr "" -##"Project-Id-Version: PACKAGE VERSION\n" -##"PO-Revision-Date: 2000-08-18 21:01-04:00\n" -##"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" -##"Language-Team: LANGUAGE <LL@li.org>\n" -##"MIME-Version: 1.0\n" -##"Content-Type: text/plain; charset=CHARSET\n" -##"Content-Transfer-Encoding: ENCODING\n" - -### SOME DESCRIPTIVE TITLE. -### Copyright (C) YEAR ORGANIZATION -### FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. -### -##msgid "" -##msgstr "" -##"Project-Id-Version: 2.0\n" -##"PO-Revision-Date: Fri Aug 18 20:45:03 2000\n" -##"Last-Translator: Barry Warsaw <bwarsaw@beopen.com>\n" -##"Language-Team: XX <python-dev@python.org>\n" -##"MIME-Version: 1.0\n" -##"Content-Type: text/plain; charset=en\n" -##"Content-Transfer-Encoding: none\n" -##"Generated-By: pygettext.py 1.1\n" - - -###: Lib/test/test_gettext.py:34 -##msgid "calling textdomain" -##msgstr "" - -###: Lib/test/test_gettext.py:94 -##msgid "dgettext failed" -##msgstr "" - -###: Lib/test/test_gettext.py:25 -##msgid "gettext installed" -##msgstr "" - -###: Lib/test/test_gettext.py:32 -##msgid "bindtextdomain(None) failed" -##msgstr "" - -###: Lib/test/test_gettext.py:44 Lib/test/test_gettext.py:54 -###: Lib/test/test_gettext.py:64 Lib/test/test_gettext.py:74 -##msgid "Raymond Luxury Yach-t" -##msgstr "Throatwobbler Mangrove" - -###: Lib/test/test_gettext.py:41 Lib/test/test_gettext.py:51 -###: Lib/test/test_gettext.py:61 Lib/test/test_gettext.py:71 -##msgid "mullusk" -##msgstr "bacon" - -###: Lib/test/test_gettext.py:38 -##msgid "text domain didn't get set properly" -##msgstr "" - -###: Lib/test/test_gettext.py:98 -##msgid "dcgettext failed" -##msgstr "" - -###: Lib/test/test_gettext.py:47 Lib/test/test_gettext.py:57 -###: Lib/test/test_gettext.py:67 Lib/test/test_gettext.py:77 -##msgid "nudge nudge" -##msgstr "wink wink" - -###: Lib/test/test_gettext.py:45 Lib/test/test_gettext.py:55 -###: Lib/test/test_gettext.py:65 Lib/test/test_gettext.py:75 -##msgid "raw string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:30 -##msgid "got unexpected localedir" -##msgstr "" - -###: Lib/test/test_gettext.py:48 Lib/test/test_gettext.py:58 -###: Lib/test/test_gettext.py:68 Lib/test/test_gettext.py:78 -##msgid "raw Unicode string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:42 Lib/test/test_gettext.py:52 -###: Lib/test/test_gettext.py:62 Lib/test/test_gettext.py:72 -##msgid "Unicode translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:90 -##msgid "multiline string translation failed" -##msgstr "" - -###: Lib/test/test_gettext.py:81 -##msgid "" -##"This module provides internationalization and localization\n" -##"support for your Python programs by providing an interface to the GNU\n" -##"gettext message catalog library." -##msgstr "Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba\n" -##"fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH\n" -##"trggrkg zrffntr pngnybt yvoenel." - -###: Lib/test/test_gettext.py:26 -##msgid "calling bindtextdomain with localdir %s" -##msgstr "" +# For reference, here's the .po file used to created the .mo data above. + +''' +# Dummy translation for Python's test_gettext.py module. +# Copyright (C) 2000 BeOpen.com +# Barry Warsaw <bwarsaw@beopen.com>, 2000. +# +msgid "" +msgstr "" +"Project-Id-Version: 2.0\n" +"PO-Revision-Date: 2000-08-29 12:19-04:00\n" +"Last-Translator: Barry A. Warsaw <bwarsaw@beopen.com>\n" +"Language-Team: XX <python-dev@python.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=koi8_r\n" +"Content-Transfer-Encoding: none\n" +"Generated-By: pygettext.py 1.1\n" + +#: test_gettext.py:19 test_gettext.py:25 test_gettext.py:31 test_gettext.py:37 +#: test_gettext.py:51 test_gettext.py:80 test_gettext.py:86 test_gettext.py:92 +#: test_gettext.py:98 +msgid "nudge nudge" +msgstr "wink wink" + +#: test_gettext.py:16 test_gettext.py:22 test_gettext.py:28 test_gettext.py:34 +#: test_gettext.py:77 test_gettext.py:83 test_gettext.py:89 test_gettext.py:95 +msgid "albatross" +msgstr "" + +#: test_gettext.py:18 test_gettext.py:24 test_gettext.py:30 test_gettext.py:36 +#: test_gettext.py:79 test_gettext.py:85 test_gettext.py:91 test_gettext.py:97 +msgid "Raymond Luxury Yach-t" +msgstr "Throatwobbler Mangrove" + +#: test_gettext.py:17 test_gettext.py:23 test_gettext.py:29 test_gettext.py:35 +#: test_gettext.py:56 test_gettext.py:78 test_gettext.py:84 test_gettext.py:90 +#: test_gettext.py:96 +msgid "mullusk" +msgstr "bacon" + +#: test_gettext.py:40 test_gettext.py:101 +msgid "" +"This module provides internationalization and localization\n" +"support for your Python programs by providing an interface to the GNU\n" +"gettext message catalog library." +msgstr "" +"Guvf zbqhyr cebivqrf vagreangvbanyvmngvba naq ybpnyvmngvba\n" +"fhccbeg sbe lbhe Clguba cebtenzf ol cebivqvat na vagresnpr gb gur TAH\n" +"trggrkg zrffntr pngnybt yvoenel." +''' |