Mercurial > babel > old > mirror
comparison babel/messages/tests/mofile.py @ 251:3b9d993b7aa3
added test cases for correct po/mofile sorting, following up r264
author | pjenvey |
---|---|
date | Mon, 13 Aug 2007 04:16:16 +0000 |
parents | 661cb602781d |
children | a7dff175b14f |
comparison
equal
deleted
inserted
replaced
250:194f927d8c5a | 251:3b9d993b7aa3 |
---|---|
10 # This software consists of voluntary contributions made by many | 10 # This software consists of voluntary contributions made by many |
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://babel.edgewall.org/log/. | 12 # history and logs, available at http://babel.edgewall.org/log/. |
13 | 13 |
14 import doctest | 14 import doctest |
15 import gettext | |
15 import unittest | 16 import unittest |
17 from StringIO import StringIO | |
16 | 18 |
17 from babel.messages import mofile | 19 from babel.messages import mofile, Catalog |
20 | |
21 class WriteMoTestCase(unittest.TestCase): | |
22 | |
23 def test_sorting(self): | |
24 # Ensure the header is sorted to the first entry so that its charset | |
25 # can be applied to all subsequent messages by GNUTranslations | |
26 # (ensuring all messages are safely converted to unicode) | |
27 catalog = Catalog(locale='en_US') | |
28 catalog.add(u'', '''\ | |
29 "Content-Type: text/plain; charset=utf-8\n" | |
30 "Content-Transfer-Encoding: 8bit\n''') | |
31 catalog.add(u'foo', 'Voh') | |
32 catalog.add((u'There is', u'There are'), (u'Es gibt', u'Es gibt')) | |
33 catalog.add(u'Fizz', '') | |
34 catalog.add(('Fuzz', 'Fuzzes'), ('', '')) | |
35 buf = StringIO() | |
36 mofile.write_mo(buf, catalog) | |
37 buf.seek(0) | |
38 translations = gettext.GNUTranslations(fp=buf) | |
39 self.assertEqual(u'Voh', translations.ugettext('foo')) | |
40 assert isinstance(translations.ugettext('foo'), unicode) | |
41 self.assertEqual(u'Es gibt', translations.ungettext('There is', 'There are', 1)) | |
42 assert isinstance(translations.ungettext('There is', 'There are', 1), unicode) | |
43 self.assertEqual(u'Fizz', translations.ugettext('Fizz')) | |
44 assert isinstance(translations.ugettext('Fizz'), unicode) | |
45 self.assertEqual(u'Fuzz', translations.ugettext('Fuzz')) | |
46 assert isinstance(translations.ugettext('Fuzz'), unicode) | |
47 self.assertEqual(u'Fuzzes', translations.ugettext('Fuzzes')) | |
48 assert isinstance(translations.ugettext('Fuzzes'), unicode) | |
18 | 49 |
19 def suite(): | 50 def suite(): |
20 suite = unittest.TestSuite() | 51 suite = unittest.TestSuite() |
21 suite.addTest(doctest.DocTestSuite(mofile)) | 52 suite.addTest(doctest.DocTestSuite(mofile)) |
53 suite.addTest(unittest.makeSuite(WriteMoTestCase)) | |
22 return suite | 54 return suite |
23 | 55 |
24 if __name__ == '__main__': | 56 if __name__ == '__main__': |
25 unittest.main(defaultTest='suite') | 57 unittest.main(defaultTest='suite') |