comparison babel/messages/tests/pofile.py @ 547:274f9a6485d4

Catalog class should not do decoding of input strings (fixes #256)
author fschwarz
date Sat, 19 Mar 2011 19:34:40 +0000
parents 10de195cfb04
children
comparison
equal deleted inserted replaced
546:10de195cfb04 547:274f9a6485d4
32 def test_preserve_domain(self): 32 def test_preserve_domain(self):
33 buf = StringIO(r'''msgid "foo" 33 buf = StringIO(r'''msgid "foo"
34 msgstr "Voh"''') 34 msgstr "Voh"''')
35 catalog = pofile.read_po(buf, domain='mydomain') 35 catalog = pofile.read_po(buf, domain='mydomain')
36 self.assertEqual('mydomain', catalog.domain) 36 self.assertEqual('mydomain', catalog.domain)
37
38 def test_applies_specified_encoding_during_read(self):
39 buf = StringIO(u'''
40 msgid ""
41 msgstr ""
42 "Project-Id-Version: 3.15\\n"
43 "Report-Msgid-Bugs-To: Fliegender Zirkus <fliegender@zirkus.de>\\n"
44 "POT-Creation-Date: 2007-09-27 11:19+0700\\n"
45 "PO-Revision-Date: 2007-09-27 21:42-0700\\n"
46 "Last-Translator: John <cleese@bavaria.de>\\n"
47 "Language-Team: German Lang <de@babel.org>\\n"
48 "Plural-Forms: nplurals=2; plural=(n != 1)\\n"
49 "MIME-Version: 1.0\\n"
50 "Content-Type: text/plain; charset=iso-8859-1\\n"
51 "Content-Transfer-Encoding: 8bit\\n"
52 "Generated-By: Babel 1.0dev-r313\\n"
53
54 msgid "foo"
55 msgstr "bär"'''.encode('iso-8859-1'))
56 catalog = pofile.read_po(buf, locale='de_DE')
57 self.assertEqual(u'bär', catalog.get('foo').string)
37 58
38 def test_read_multiline(self): 59 def test_read_multiline(self):
39 buf = StringIO(r'''msgid "" 60 buf = StringIO(r'''msgid ""
40 "Here's some text that\n" 61 "Here's some text that\n"
41 "includesareallylongwordthatmightbutshouldnt" 62 "includesareallylongwordthatmightbutshouldnt"
245 buf = StringIO() 266 buf = StringIO()
246 pofile.write_po(buf, catalog, omit_header=True) 267 pofile.write_po(buf, catalog, omit_header=True)
247 self.assertEqual('''#: main.py:1 utils.py:3 268 self.assertEqual('''#: main.py:1 utils.py:3
248 msgid "foo" 269 msgid "foo"
249 msgstr ""''', buf.getvalue().strip()) 270 msgstr ""''', buf.getvalue().strip())
271
272 def test_write_po_file_with_specified_charset(self):
273 catalog = Catalog(charset='iso-8859-1')
274 catalog.add('foo', u'äöü', locations=[('main.py', 1)])
275 buf = StringIO()
276 pofile.write_po(buf, catalog, omit_header=False)
277 po_file = buf.getvalue().strip()
278 assert r'"Content-Type: text/plain; charset=iso-8859-1\n"' in po_file
279 assert u'msgstr "äöü"'.encode('iso-8859-1') in po_file
250 280
251 def test_duplicate_comments(self): 281 def test_duplicate_comments(self):
252 catalog = Catalog() 282 catalog = Catalog()
253 catalog.add(u'foo', auto_comments=['A comment']) 283 catalog.add(u'foo', auto_comments=['A comment'])
254 catalog.add(u'foo', auto_comments=['A comment']) 284 catalog.add(u'foo', auto_comments=['A comment'])
Copyright (C) 2012-2017 Edgewall Software