cmlenz@3: # -*- coding: utf-8 -*- cmlenz@3: # jruigrok@532: # Copyright (C) 2007-2011 Edgewall Software cmlenz@3: # All rights reserved. cmlenz@3: # cmlenz@3: # This software is licensed as described in the file COPYING, which cmlenz@3: # you should have received as part of this distribution. The terms cmlenz@3: # are also available at http://babel.edgewall.org/wiki/License. cmlenz@3: # cmlenz@3: # This software consists of voluntary contributions made by many cmlenz@3: # individuals. For the exact contribution history, see the revision cmlenz@3: # history and logs, available at http://babel.edgewall.org/log/. cmlenz@3: cmlenz@106: from datetime import datetime cmlenz@3: import doctest cmlenz@26: from StringIO import StringIO cmlenz@3: import unittest cmlenz@3: cmlenz@183: from babel.messages.catalog import Catalog, Message cmlenz@56: from babel.messages import pofile fschwarz@533: from babel.util import FixedOffsetTimezone cmlenz@3: cmlenz@19: cmlenz@108: class ReadPoTestCase(unittest.TestCase): cmlenz@108: cmlenz@198: def test_preserve_locale(self): cmlenz@198: buf = StringIO(r'''msgid "foo" cmlenz@198: msgstr "Voh"''') cmlenz@198: catalog = pofile.read_po(buf, locale='en_US') cmlenz@198: self.assertEqual('en_US', catalog.locale) cmlenz@198: cmlenz@198: def test_preserve_domain(self): cmlenz@198: buf = StringIO(r'''msgid "foo" cmlenz@198: msgstr "Voh"''') cmlenz@198: catalog = pofile.read_po(buf, domain='mydomain') cmlenz@198: self.assertEqual('mydomain', catalog.domain) cmlenz@198: cmlenz@108: def test_read_multiline(self): cmlenz@108: buf = StringIO(r'''msgid "" cmlenz@108: "Here's some text that\n" cmlenz@108: "includesareallylongwordthatmightbutshouldnt" cmlenz@108: " throw us into an infinite " cmlenz@108: "loop\n" cmlenz@108: msgstr ""''') cmlenz@108: catalog = pofile.read_po(buf) cmlenz@108: self.assertEqual(1, len(catalog)) cmlenz@108: message = list(catalog)[1] cmlenz@108: self.assertEqual("Here's some text that\nincludesareallylongwordthat" cmlenz@108: "mightbutshouldnt throw us into an infinite loop\n", cmlenz@108: message.id) cmlenz@198: palgarvio@177: def test_fuzzy_header(self): palgarvio@177: buf = StringIO(r'''\ palgarvio@177: # Translations template for AReallyReallyLongNameForAProject. palgarvio@177: # Copyright (C) 2007 ORGANIZATION palgarvio@177: # This file is distributed under the same license as the palgarvio@177: # AReallyReallyLongNameForAProject project. palgarvio@177: # FIRST AUTHOR , 2007. palgarvio@177: # palgarvio@177: #, fuzzy palgarvio@177: ''') palgarvio@177: catalog = pofile.read_po(buf) palgarvio@177: self.assertEqual(1, len(list(catalog))) palgarvio@177: self.assertEqual(True, list(catalog)[0].fuzzy) cmlenz@198: palgarvio@177: def test_not_fuzzy_header(self): palgarvio@177: buf = StringIO(r'''\ palgarvio@177: # Translations template for AReallyReallyLongNameForAProject. palgarvio@177: # Copyright (C) 2007 ORGANIZATION palgarvio@177: # This file is distributed under the same license as the palgarvio@177: # AReallyReallyLongNameForAProject project. palgarvio@177: # FIRST AUTHOR , 2007. palgarvio@177: # palgarvio@177: ''') palgarvio@177: catalog = pofile.read_po(buf) palgarvio@177: self.assertEqual(1, len(list(catalog))) palgarvio@177: self.assertEqual(False, list(catalog)[0].fuzzy) cmlenz@108: pjenvey@293: def test_header_entry(self): pjenvey@293: buf = StringIO(r'''\ pjenvey@293: # SOME DESCRIPTIVE TITLE. pjenvey@293: # Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER pjenvey@293: # This file is distributed under the same license as the PACKAGE package. pjenvey@293: # FIRST AUTHOR , 2007. pjenvey@293: # pjenvey@293: #, fuzzy pjenvey@293: msgid "" pjenvey@293: msgstr "" pjenvey@293: "Project-Id-Version: 3.15\n" pjenvey@293: "Report-Msgid-Bugs-To: Fliegender Zirkus \n" pjenvey@293: "POT-Creation-Date: 2007-09-27 11:19+0700\n" pjenvey@293: "PO-Revision-Date: 2007-09-27 21:42-0700\n" pjenvey@293: "Last-Translator: John \n" pjenvey@293: "Language-Team: German Lang \n" pjenvey@293: "Plural-Forms: nplurals=2; plural=(n != 1)\n" pjenvey@293: "MIME-Version: 1.0\n" pjenvey@293: "Content-Type: text/plain; charset=iso-8859-2\n" pjenvey@293: "Content-Transfer-Encoding: 8bit\n" pjenvey@293: "Generated-By: Babel 1.0dev-r313\n" pjenvey@293: ''') pjenvey@293: catalog = pofile.read_po(buf) pjenvey@293: self.assertEqual(1, len(list(catalog))) pjenvey@293: self.assertEqual(u'3.15', catalog.version) pjenvey@293: self.assertEqual(u'Fliegender Zirkus ', pjenvey@293: catalog.msgid_bugs_address) pjenvey@293: self.assertEqual(datetime(2007, 9, 27, 11, 19, pjenvey@293: tzinfo=FixedOffsetTimezone(7 * 60)), pjenvey@293: catalog.creation_date) pjenvey@293: self.assertEqual(u'John ', catalog.last_translator) pjenvey@293: self.assertEqual(u'German Lang ', catalog.language_team) pjenvey@293: self.assertEqual(u'iso-8859-2', catalog.charset) pjenvey@293: self.assertEqual(True, list(catalog)[0].fuzzy) pjenvey@293: cmlenz@201: def test_obsolete_message(self): cmlenz@201: buf = StringIO(r'''# This is an obsolete message cmlenz@201: #~ msgid "foo" cmlenz@201: #~ msgstr "Voh" cmlenz@201: cmlenz@201: # This message is not obsolete cmlenz@201: #: main.py:1 cmlenz@201: msgid "bar" cmlenz@201: msgstr "Bahr" cmlenz@201: ''') cmlenz@201: catalog = pofile.read_po(buf) cmlenz@201: self.assertEqual(1, len(catalog)) cmlenz@201: self.assertEqual(1, len(catalog.obsolete)) cmlenz@201: message = catalog.obsolete[u'foo'] cmlenz@201: self.assertEqual(u'foo', message.id) cmlenz@201: self.assertEqual(u'Voh', message.string) cmlenz@201: self.assertEqual(['This is an obsolete message'], message.user_comments) cmlenz@201: cmlenz@201: def test_obsolete_message_ignored(self): cmlenz@201: buf = StringIO(r'''# This is an obsolete message cmlenz@201: #~ msgid "foo" cmlenz@201: #~ msgstr "Voh" cmlenz@201: cmlenz@201: # This message is not obsolete cmlenz@201: #: main.py:1 cmlenz@201: msgid "bar" cmlenz@201: msgstr "Bahr" cmlenz@201: ''') cmlenz@201: catalog = pofile.read_po(buf, ignore_obsolete=True) cmlenz@201: self.assertEqual(1, len(catalog)) cmlenz@201: self.assertEqual(0, len(catalog.obsolete)) cmlenz@201: cmlenz@337: def test_with_context(self): cmlenz@337: buf = StringIO(r'''# Some string in the menu cmlenz@337: #: main.py:1 cmlenz@337: msgctxt "Menu" cmlenz@337: msgid "foo" cmlenz@337: msgstr "Voh" cmlenz@337: cmlenz@337: # Another string in the menu cmlenz@337: #: main.py:2 cmlenz@337: msgctxt "Menu" cmlenz@337: msgid "bar" cmlenz@337: msgstr "Bahr" cmlenz@337: ''') cmlenz@337: catalog = pofile.read_po(buf, ignore_obsolete=True) cmlenz@337: self.assertEqual(2, len(catalog)) cmlenz@352: message = catalog.get('foo', context='Menu') cmlenz@337: self.assertEqual('Menu', message.context) cmlenz@352: message = catalog.get('bar', context='Menu') cmlenz@337: self.assertEqual('Menu', message.context) cmlenz@337: palgarvio@423: # And verify it pass through write_po palgarvio@423: out_buf = StringIO() palgarvio@423: pofile.write_po(out_buf, catalog, omit_header=True) palgarvio@423: assert out_buf.getvalue().strip() == buf.getvalue().strip(), \ palgarvio@423: out_buf.getvalue() palgarvio@423: cmlenz@430: def test_with_context_two(self): cmlenz@430: buf = StringIO(r'''msgctxt "Menu" cmlenz@430: msgid "foo" cmlenz@430: msgstr "Voh" cmlenz@430: cmlenz@430: msgctxt "Mannu" cmlenz@430: msgid "bar" cmlenz@430: msgstr "Bahr" cmlenz@430: ''') cmlenz@430: catalog = pofile.read_po(buf, ignore_obsolete=True) cmlenz@430: self.assertEqual(2, len(catalog)) cmlenz@430: message = catalog.get('foo', context='Menu') cmlenz@430: self.assertEqual('Menu', message.context) cmlenz@430: message = catalog.get('bar', context='Mannu') cmlenz@430: self.assertEqual('Mannu', message.context) cmlenz@430: cmlenz@430: # And verify it pass through write_po cmlenz@430: out_buf = StringIO() cmlenz@430: pofile.write_po(out_buf, catalog, omit_header=True) cmlenz@430: assert out_buf.getvalue().strip() == buf.getvalue().strip(), out_buf.getvalue() cmlenz@430: jruigrok@445: def test_single_plural_form(self): jruigrok@445: buf = StringIO(r'''msgid "foo" jruigrok@448: msgid_plural "foos" jruigrok@445: msgstr[0] "Voh"''') jruigrok@445: catalog = pofile.read_po(buf, locale='ja_JP') jruigrok@445: self.assertEqual(1, len(catalog)) jruigrok@445: self.assertEqual(1, catalog.num_plurals) jruigrok@445: message = catalog['foo'] jruigrok@445: self.assertEqual(1, len(message.string)) jruigrok@445: jruigrok@444: def test_singular_plural_form(self): palgarvio@372: buf = StringIO(r'''msgid "foo" jruigrok@448: msgid_plural "foos" palgarvio@372: msgstr[0] "Voh" jruigrok@444: msgstr[1] "Vohs"''') jruigrok@444: catalog = pofile.read_po(buf, locale='nl_NL') palgarvio@372: self.assertEqual(1, len(catalog)) jruigrok@444: self.assertEqual(2, catalog.num_plurals) cmlenz@379: message = catalog['foo'] jruigrok@444: self.assertEqual(2, len(message.string)) jruigrok@443: palgarvio@372: def test_more_than_two_plural_forms(self): palgarvio@372: buf = StringIO(r'''msgid "foo" jruigrok@448: msgid_plural "foos" palgarvio@372: msgstr[0] "Voh" jruigrok@447: msgstr[1] "Vohs" jruigrok@447: msgstr[2] "Vohss"''') palgarvio@372: catalog = pofile.read_po(buf, locale='lv_LV') palgarvio@372: self.assertEqual(1, len(catalog)) palgarvio@372: self.assertEqual(3, catalog.num_plurals) cmlenz@379: message = catalog['foo'] palgarvio@372: self.assertEqual(3, len(message.string)) jruigrok@447: self.assertEqual(u'Vohss', message.string[2]) palgarvio@372: jruigrok@446: def test_plural_with_square_brackets(self): jruigrok@446: buf = StringIO(r'''msgid "foo" jruigrok@448: msgid_plural "foos" jruigrok@446: msgstr[0] "Voh [text]" jruigrok@446: msgstr[1] "Vohs [text]"''') jruigrok@446: catalog = pofile.read_po(buf, locale='nb_NO') jruigrok@446: self.assertEqual(1, len(catalog)) jruigrok@446: self.assertEqual(2, catalog.num_plurals) jruigrok@446: message = catalog['foo'] jruigrok@446: self.assertEqual(2, len(message.string)) jruigrok@446: cmlenz@108: cmlenz@106: class WritePoTestCase(unittest.TestCase): cmlenz@26: cmlenz@26: def test_join_locations(self): cmlenz@58: catalog = Catalog() cmlenz@58: catalog.add(u'foo', locations=[('main.py', 1)]) cmlenz@58: catalog.add(u'foo', locations=[('utils.py', 3)]) cmlenz@26: buf = StringIO() cmlenz@106: pofile.write_po(buf, catalog, omit_header=True) cmlenz@26: self.assertEqual('''#: main.py:1 utils.py:3 cmlenz@26: msgid "foo" cmlenz@26: msgstr ""''', buf.getvalue().strip()) cmlenz@26: cmlenz@230: def test_duplicate_comments(self): cmlenz@230: catalog = Catalog() cmlenz@230: catalog.add(u'foo', auto_comments=['A comment']) cmlenz@230: catalog.add(u'foo', auto_comments=['A comment']) cmlenz@230: buf = StringIO() cmlenz@230: pofile.write_po(buf, catalog, omit_header=True) cmlenz@230: self.assertEqual('''#. A comment cmlenz@230: msgid "foo" cmlenz@230: msgstr ""''', buf.getvalue().strip()) cmlenz@230: cmlenz@26: def test_wrap_long_lines(self): cmlenz@26: text = """Here's some text where cmlenz@26: white space and line breaks matter, and should cmlenz@26: cmlenz@26: not be removed cmlenz@26: cmlenz@26: """ cmlenz@58: catalog = Catalog() cmlenz@58: catalog.add(text, locations=[('main.py', 1)]) cmlenz@26: buf = StringIO() cmlenz@106: pofile.write_po(buf, catalog, no_location=True, omit_header=True, cmlenz@58: width=42) cmlenz@26: self.assertEqual(r'''msgid "" cmlenz@26: "Here's some text where \n" cmlenz@26: "white space and line breaks matter, and" cmlenz@26: " should\n" cmlenz@26: "\n" cmlenz@26: "not be removed\n" cmlenz@26: "\n" cmlenz@26: msgstr ""''', buf.getvalue().strip()) cmlenz@26: cmlenz@26: def test_wrap_long_lines_with_long_word(self): cmlenz@26: text = """Here's some text that cmlenz@26: includesareallylongwordthatmightbutshouldnt throw us into an infinite loop cmlenz@26: """ cmlenz@58: catalog = Catalog() cmlenz@58: catalog.add(text, locations=[('main.py', 1)]) cmlenz@26: buf = StringIO() cmlenz@106: pofile.write_po(buf, catalog, no_location=True, omit_header=True, cmlenz@58: width=32) cmlenz@26: self.assertEqual(r'''msgid "" cmlenz@26: "Here's some text that\n" cmlenz@26: "includesareallylongwordthatmightbutshouldnt" cmlenz@26: " throw us into an infinite " cmlenz@26: "loop\n" cmlenz@26: msgstr ""''', buf.getvalue().strip()) palgarvio@82: cmlenz@105: def test_wrap_long_lines_in_header(self): cmlenz@105: """ cmlenz@105: Verify that long lines in the header comment are wrapped correctly. cmlenz@105: """ cmlenz@106: catalog = Catalog(project='AReallyReallyLongNameForAProject', cmlenz@106: revision_date=datetime(2007, 4, 1)) cmlenz@105: buf = StringIO() cmlenz@106: pofile.write_po(buf, catalog) cmlenz@105: self.assertEqual('''\ cmlenz@105: # Translations template for AReallyReallyLongNameForAProject. cmlenz@105: # Copyright (C) 2007 ORGANIZATION cmlenz@105: # This file is distributed under the same license as the cmlenz@105: # AReallyReallyLongNameForAProject project. cmlenz@106: # FIRST AUTHOR , 2007. cmlenz@105: # cmlenz@105: #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) cmlenz@105: cmlenz@317: def test_wrap_locations_with_hyphens(self): cmlenz@317: catalog = Catalog() cmlenz@317: catalog.add(u'foo', locations=[ cmlenz@317: ('doupy/templates/base/navmenu.inc.html.py', 60) cmlenz@317: ]) cmlenz@317: catalog.add(u'foo', locations=[ cmlenz@317: ('doupy/templates/job-offers/helpers.html', 22) cmlenz@317: ]) cmlenz@317: buf = StringIO() cmlenz@317: pofile.write_po(buf, catalog, omit_header=True) cmlenz@317: self.assertEqual('''#: doupy/templates/base/navmenu.inc.html.py:60 cmlenz@317: #: doupy/templates/job-offers/helpers.html:22 cmlenz@317: msgid "foo" cmlenz@317: msgstr ""''', buf.getvalue().strip()) palgarvio@425: palgarvio@425: def test_no_wrap_and_width_behaviour_on_comments(self): palgarvio@425: catalog = Catalog() palgarvio@425: catalog.add("Pretty dam long message id, which must really be big " palgarvio@425: "to test this wrap behaviour, if not it won't work.", palgarvio@425: locations=[("fake.py", n) for n in range(1, 30)]) palgarvio@425: buf = StringIO() palgarvio@425: pofile.write_po(buf, catalog, width=None, omit_header=True) palgarvio@425: self.assertEqual("""\ palgarvio@425: #: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 palgarvio@425: #: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14 palgarvio@425: #: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21 palgarvio@425: #: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28 palgarvio@425: #: fake.py:29 palgarvio@425: msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work." palgarvio@425: msgstr "" palgarvio@425: palgarvio@425: """, buf.getvalue().lower()) palgarvio@425: buf = StringIO() palgarvio@425: pofile.write_po(buf, catalog, width=100, omit_header=True) palgarvio@425: self.assertEqual("""\ palgarvio@425: #: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 fake.py:8 fake.py:9 fake.py:10 palgarvio@425: #: fake.py:11 fake.py:12 fake.py:13 fake.py:14 fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 palgarvio@425: #: fake.py:20 fake.py:21 fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28 palgarvio@425: #: fake.py:29 palgarvio@425: msgid "" palgarvio@425: "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't" palgarvio@425: " work." palgarvio@425: msgstr "" palgarvio@425: palgarvio@425: """, buf.getvalue().lower()) cmlenz@317: palgarvio@82: def test_pot_with_translator_comments(self): palgarvio@82: catalog = Catalog() palgarvio@82: catalog.add(u'foo', locations=[('main.py', 1)], palgarvio@107: auto_comments=['Comment About `foo`']) palgarvio@82: catalog.add(u'bar', locations=[('utils.py', 3)], palgarvio@107: user_comments=['Comment About `bar` with', palgarvio@107: 'multiple lines.']) palgarvio@82: buf = StringIO() cmlenz@106: pofile.write_po(buf, catalog, omit_header=True) palgarvio@82: self.assertEqual('''#. Comment About `foo` palgarvio@82: #: main.py:1 palgarvio@82: msgid "foo" palgarvio@82: msgstr "" palgarvio@82: palgarvio@107: # Comment About `bar` with palgarvio@107: # multiple lines. palgarvio@82: #: utils.py:3 palgarvio@82: msgid "bar" palgarvio@82: msgstr ""''', buf.getvalue().strip()) cmlenz@26: cmlenz@192: def test_po_with_obsolete_message(self): cmlenz@183: catalog = Catalog() cmlenz@183: catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) cmlenz@183: catalog.obsolete['bar'] = Message(u'bar', u'Bahr', cmlenz@183: locations=[('utils.py', 3)], cmlenz@183: user_comments=['User comment']) cmlenz@183: buf = StringIO() cmlenz@183: pofile.write_po(buf, catalog, omit_header=True) cmlenz@183: self.assertEqual('''#: main.py:1 cmlenz@183: msgid "foo" cmlenz@183: msgstr "Voh" cmlenz@183: cmlenz@183: # User comment cmlenz@183: #~ msgid "bar" cmlenz@183: #~ msgstr "Bahr"''', buf.getvalue().strip()) cmlenz@183: cmlenz@192: def test_po_with_multiline_obsolete_message(self): cmlenz@192: catalog = Catalog() cmlenz@192: catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) cmlenz@192: msgid = r"""Here's a message that covers cmlenz@192: multiple lines, and should still be handled cmlenz@192: correctly. cmlenz@192: """ cmlenz@192: msgstr = r"""Here's a message that covers cmlenz@192: multiple lines, and should still be handled cmlenz@192: correctly. cmlenz@192: """ cmlenz@192: catalog.obsolete[msgid] = Message(msgid, msgstr, cmlenz@192: locations=[('utils.py', 3)]) cmlenz@192: buf = StringIO() cmlenz@192: pofile.write_po(buf, catalog, omit_header=True) cmlenz@192: self.assertEqual(r'''#: main.py:1 cmlenz@192: msgid "foo" cmlenz@192: msgstr "Voh" cmlenz@192: cmlenz@192: #~ msgid "" cmlenz@192: #~ "Here's a message that covers\n" cmlenz@192: #~ "multiple lines, and should still be handled\n" cmlenz@192: #~ "correctly.\n" cmlenz@192: #~ msgstr "" cmlenz@192: #~ "Here's a message that covers\n" cmlenz@192: #~ "multiple lines, and should still be handled\n" cmlenz@192: #~ "correctly.\n"''', buf.getvalue().strip()) cmlenz@192: cmlenz@193: def test_po_with_obsolete_message_ignored(self): cmlenz@193: catalog = Catalog() cmlenz@193: catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) cmlenz@193: catalog.obsolete['bar'] = Message(u'bar', u'Bahr', cmlenz@193: locations=[('utils.py', 3)], cmlenz@193: user_comments=['User comment']) cmlenz@193: buf = StringIO() cmlenz@193: pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True) cmlenz@193: self.assertEqual('''#: main.py:1 cmlenz@193: msgid "foo" cmlenz@193: msgstr "Voh"''', buf.getvalue().strip()) cmlenz@193: cmlenz@205: def test_po_with_previous_msgid(self): cmlenz@205: catalog = Catalog() cmlenz@205: catalog.add(u'foo', u'Voh', locations=[('main.py', 1)], cmlenz@205: previous_id=u'fo') cmlenz@205: buf = StringIO() cmlenz@205: pofile.write_po(buf, catalog, omit_header=True, include_previous=True) cmlenz@205: self.assertEqual('''#: main.py:1 cmlenz@205: #| msgid "fo" cmlenz@205: msgid "foo" cmlenz@205: msgstr "Voh"''', buf.getvalue().strip()) cmlenz@205: cmlenz@205: def test_po_with_previous_msgid_plural(self): cmlenz@205: catalog = Catalog() cmlenz@205: catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), cmlenz@205: locations=[('main.py', 1)], previous_id=(u'fo', u'fos')) cmlenz@205: buf = StringIO() cmlenz@205: pofile.write_po(buf, catalog, omit_header=True, include_previous=True) cmlenz@205: self.assertEqual('''#: main.py:1 cmlenz@205: #| msgid "fo" cmlenz@205: #| msgid_plural "fos" cmlenz@205: msgid "foo" cmlenz@205: msgid_plural "foos" cmlenz@205: msgstr[0] "Voh" cmlenz@205: msgstr[1] "Voeh"''', buf.getvalue().strip()) cmlenz@205: pjenvey@251: def test_sorted_po(self): pjenvey@251: catalog = Catalog() pjenvey@251: catalog.add(u'bar', locations=[('utils.py', 3)], pjenvey@251: user_comments=['Comment About `bar` with', pjenvey@251: 'multiple lines.']) pjenvey@251: catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), pjenvey@251: locations=[('main.py', 1)]) pjenvey@251: buf = StringIO() pjenvey@251: pofile.write_po(buf, catalog, sort_output=True) pjenvey@251: value = buf.getvalue().strip() pjenvey@251: assert '''\ pjenvey@251: # Comment About `bar` with pjenvey@251: # multiple lines. pjenvey@251: #: utils.py:3 pjenvey@251: msgid "bar" pjenvey@251: msgstr "" pjenvey@251: pjenvey@251: #: main.py:1 pjenvey@251: msgid "foo" pjenvey@251: msgid_plural "foos" pjenvey@251: msgstr[0] "Voh" pjenvey@251: msgstr[1] "Voeh"''' in value pjenvey@251: assert value.find('msgid ""') < value.find('msgid "bar"') < value.find('msgid "foo"') cmlenz@26: aronacher@358: def test_silent_location_fallback(self): aronacher@358: buf = StringIO('''\ aronacher@358: #: broken_file.py aronacher@358: msgid "missing line number" aronacher@358: msgstr "" aronacher@358: aronacher@358: #: broken_file.py:broken_line_number aronacher@358: msgid "broken line number" aronacher@358: msgstr ""''') aronacher@358: catalog = pofile.read_po(buf) cmlenz@379: self.assertEqual(catalog['missing line number'].locations, []) cmlenz@379: self.assertEqual(catalog['broken line number'].locations, []) aronacher@358: cmlenz@3: def suite(): cmlenz@3: suite = unittest.TestSuite() fschwarz@546: suite.addTest(doctest.DocTestSuite(pofile, optionflags=doctest.ELLIPSIS)) cmlenz@108: suite.addTest(unittest.makeSuite(ReadPoTestCase)) cmlenz@106: suite.addTest(unittest.makeSuite(WritePoTestCase)) cmlenz@3: return suite cmlenz@3: cmlenz@3: if __name__ == '__main__': cmlenz@3: unittest.main(defaultTest='suite')