[Python-checkins] python/dist/src/Lib/test test_gettext.py,1.15,1.16
bwarsaw@users.sourceforge.net
bwarsaw@users.sourceforge.net
Tue, 20 May 2003 10:28:56 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv24984
Modified Files:
test_gettext.py
Log Message:
Added a test for the fix of SF bug #658233, where continuation lines
in .po metadata caused a crash.
Also, removed some unnecessary code.
Backport candidate.
Index: test_gettext.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_gettext.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** test_gettext.py 27 Apr 2003 19:42:41 -0000 1.15
--- test_gettext.py 20 May 2003 17:28:54 -0000 1.16
***************
*** 44,50 ****
--- 44,62 ----
'''
+ MMO_DATA = '''\
+ 3hIElQAAAAABAAAAHAAAACQAAAADAAAALAAAAAAAAAA4AAAAeAEAADkAAAABAAAAAAAAAAAAAAAA
+ UHJvamVjdC1JZC1WZXJzaW9uOiBObyBQcm9qZWN0IDAuMApQT1QtQ3JlYXRpb24tRGF0ZTogV2Vk
+ IERlYyAxMSAwNzo0NDoxNSAyMDAyClBPLVJldmlzaW9uLURhdGU6IDIwMDItMDgtMTQgMDE6MTg6
+ NTgrMDA6MDAKTGFzdC1UcmFuc2xhdG9yOiBKb2huIERvZSA8amRvZUBleGFtcGxlLmNvbT4KSmFu
+ ZSBGb29iYXIgPGpmb29iYXJAZXhhbXBsZS5jb20+Ckxhbmd1YWdlLVRlYW06IHh4IDx4eEBleGFt
+ cGxlLmNvbT4KTUlNRS1WZXJzaW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFy
+ c2V0PWlzby04ODU5LTE1CkNvbnRlbnQtVHJhbnNmZXItRW5jb2Rpbmc6IHF1b3RlZC1wcmludGFi
+ bGUKR2VuZXJhdGVkLUJ5OiBweWdldHRleHQucHkgMS4zCgA=
+ '''
+
LOCALEDIR = os.path.join('xx', 'LC_MESSAGES')
MOFILE = os.path.join(LOCALEDIR, 'gettext.mo')
UMOFILE = os.path.join(LOCALEDIR, 'ugettext.mo')
+ MMOFILE = os.path.join(LOCALEDIR, 'metadata.mo')
try:
LANG = os.environ['LANGUAGE']
***************
*** 62,65 ****
--- 74,80 ----
fp.write(base64.decodestring(UMO_DATA))
fp.close()
+ fp = open(MMOFILE, 'wb')
+ fp.write(base64.decodestring(MMO_DATA))
+ fp.close()
os.environ['LANGUAGE'] = 'xx'
***************
*** 76,82 ****
gettext.install('gettext', self.localedir)
- def tearDown(self):
- GettextBaseTest.tearDown(self)
-
def test_some_translations(self):
eq = self.assertEqual
--- 91,94 ----
***************
*** 145,151 ****
self._ = gettext.gettext
- def tearDown(self):
- GettextBaseTest.tearDown(self)
-
def test_bindtextdomain(self):
self.assertEqual(gettext.bindtextdomain('gettext'), self.localedir)
--- 157,160 ----
***************
*** 202,208 ****
self.mofile = MOFILE
- def tearDown(self):
- GettextBaseTest.tearDown(self)
-
def test_plural_forms1(self):
eq = self.assertEqual
--- 211,214 ----
***************
*** 293,299 ****
self._ = self.t.ugettext
- def tearDown(self):
- GettextBaseTest.tearDown(self)
-
def test_unicode_msgid(self):
unless = self.failUnless
--- 299,302 ----
***************
*** 306,309 ****
--- 309,331 ----
+ class WeirdMetadataTest(GettextBaseTest):
+ def setUp(self):
+ GettextBaseTest.setUp(self)
+ fp = open(MMOFILE, 'rb')
+ try:
+ try:
+ self.t = gettext.GNUTranslations(fp)
+ except:
+ self.tearDown()
+ raise
+ finally:
+ fp.close()
+
+ def test_weird_metadata(self):
+ info = self.t.info()
+ self.assertEqual(info['last-translator'],
+ 'John Doe <jdoe@example.com>\nJane Foobar <jfoobar@example.com>')
+
+
def suite():
suite = unittest.TestSuite()
***************
*** 312,315 ****
--- 334,338 ----
suite.addTest(unittest.makeSuite(PluralFormsTestCase))
suite.addTest(unittest.makeSuite(UnicodeTranslationsTest))
+ suite.addTest(unittest.makeSuite(WeirdMetadataTest))
return suite
***************
*** 407,409 ****
--- 430,449 ----
msgid "ab\xc3\x9e"
msgstr "\xc2\xa4yz"
+ '''
+
+ # Here's the third example po file, used to generate MMO_DATA
+
+ '''
+ msgid ""
+ msgstr ""
+ "Project-Id-Version: No Project 0.0\n"
+ "POT-Creation-Date: Wed Dec 11 07:44:15 2002\n"
+ "PO-Revision-Date: 2002-08-14 01:18:58+00:00\n"
+ "Last-Translator: John Doe <jdoe@example.com>\n"
+ "Jane Foobar <jfoobar@example.com>\n"
+ "Language-Team: xx <xx@example.com>\n"
+ "MIME-Version: 1.0\n"
+ "Content-Type: text/plain; charset=iso-8859-15\n"
+ "Content-Transfer-Encoding: quoted-printable\n"
+ "Generated-By: pygettext.py 1.3\n"
'''