annotate babel/messages/tests/pofile.py @ 428:a974d298400f trunk

Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
author cmlenz
date Tue, 17 Mar 2009 22:26:03 +0000
parents fb926f48efba
children 942afedbb3d7
rev   line source
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
2 #
335
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
3 # Copyright (C) 2007-2008 Edgewall Software
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
5 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
9 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
13
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
14 from datetime import datetime
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
15 import doctest
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
16 from StringIO import StringIO
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
17 import unittest
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
18
181
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
19 from babel.messages.catalog import Catalog, Message
54
7dbcbc3f07e0 Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents: 51
diff changeset
20 from babel.messages import pofile
291
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
21 from babel.util import FixedOffsetTimezone, LOCALTZ
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
22
17
55e22bc56f0c Recognize python-format messages also for unnamed parameters.
cmlenz
parents: 12
diff changeset
23
106
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
24 class ReadPoTestCase(unittest.TestCase):
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
25
196
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
26 def test_preserve_locale(self):
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
27 buf = StringIO(r'''msgid "foo"
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
28 msgstr "Voh"''')
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
29 catalog = pofile.read_po(buf, locale='en_US')
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
30 self.assertEqual('en_US', catalog.locale)
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
31
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
32 def test_preserve_domain(self):
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
33 buf = StringIO(r'''msgid "foo"
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
34 msgstr "Voh"''')
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
35 catalog = pofile.read_po(buf, domain='mydomain')
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
36 self.assertEqual('mydomain', catalog.domain)
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
37
106
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
38 def test_read_multiline(self):
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
39 buf = StringIO(r'''msgid ""
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
40 "Here's some text that\n"
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
41 "includesareallylongwordthatmightbutshouldnt"
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
42 " throw us into an infinite "
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
43 "loop\n"
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
44 msgstr ""''')
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
45 catalog = pofile.read_po(buf)
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
46 self.assertEqual(1, len(catalog))
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
47 message = list(catalog)[1]
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
48 self.assertEqual("Here's some text that\nincludesareallylongwordthat"
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
49 "mightbutshouldnt throw us into an infinite loop\n",
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
50 message.id)
196
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
51
175
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
52 def test_fuzzy_header(self):
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
53 buf = StringIO(r'''\
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
54 # Translations template for AReallyReallyLongNameForAProject.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
55 # Copyright (C) 2007 ORGANIZATION
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
56 # This file is distributed under the same license as the
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
57 # AReallyReallyLongNameForAProject project.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
58 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
59 #
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
60 #, fuzzy
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
61 ''')
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
62 catalog = pofile.read_po(buf)
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
63 self.assertEqual(1, len(list(catalog)))
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
64 self.assertEqual(True, list(catalog)[0].fuzzy)
196
b38a6b220ea2 Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
65
175
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
66 def test_not_fuzzy_header(self):
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
67 buf = StringIO(r'''\
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
68 # Translations template for AReallyReallyLongNameForAProject.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
69 # Copyright (C) 2007 ORGANIZATION
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
70 # This file is distributed under the same license as the
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
71 # AReallyReallyLongNameForAProject project.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
72 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
73 #
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
74 ''')
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
75 catalog = pofile.read_po(buf)
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
76 self.assertEqual(1, len(list(catalog)))
5d32098d8352 Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents: 106
diff changeset
77 self.assertEqual(False, list(catalog)[0].fuzzy)
106
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
78
291
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
79 def test_header_entry(self):
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
80 buf = StringIO(r'''\
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
81 # SOME DESCRIPTIVE TITLE.
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
82 # Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
83 # This file is distributed under the same license as the PACKAGE package.
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
84 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
85 #
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
86 #, fuzzy
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
87 msgid ""
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
88 msgstr ""
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
89 "Project-Id-Version: 3.15\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
90 "Report-Msgid-Bugs-To: Fliegender Zirkus <fliegender@zirkus.de>\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
91 "POT-Creation-Date: 2007-09-27 11:19+0700\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
92 "PO-Revision-Date: 2007-09-27 21:42-0700\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
93 "Last-Translator: John <cleese@bavaria.de>\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
94 "Language-Team: German Lang <de@babel.org>\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
95 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
96 "MIME-Version: 1.0\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
97 "Content-Type: text/plain; charset=iso-8859-2\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
98 "Content-Transfer-Encoding: 8bit\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
99 "Generated-By: Babel 1.0dev-r313\n"
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
100 ''')
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
101 catalog = pofile.read_po(buf)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
102 self.assertEqual(1, len(list(catalog)))
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
103 self.assertEqual(u'3.15', catalog.version)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
104 self.assertEqual(u'Fliegender Zirkus <fliegender@zirkus.de>',
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
105 catalog.msgid_bugs_address)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
106 self.assertEqual(datetime(2007, 9, 27, 11, 19,
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
107 tzinfo=FixedOffsetTimezone(7 * 60)),
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
108 catalog.creation_date)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
109 self.assertEqual(u'John <cleese@bavaria.de>', catalog.last_translator)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
110 self.assertEqual(u'German Lang <de@babel.org>', catalog.language_team)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
111 self.assertEqual(u'iso-8859-2', catalog.charset)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
112 self.assertEqual(True, list(catalog)[0].fuzzy)
2f6b2b06a428 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
113
199
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
114 def test_obsolete_message(self):
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
115 buf = StringIO(r'''# This is an obsolete message
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
116 #~ msgid "foo"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
117 #~ msgstr "Voh"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
118
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
119 # This message is not obsolete
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
120 #: main.py:1
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
121 msgid "bar"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
122 msgstr "Bahr"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
123 ''')
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
124 catalog = pofile.read_po(buf)
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
125 self.assertEqual(1, len(catalog))
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
126 self.assertEqual(1, len(catalog.obsolete))
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
127 message = catalog.obsolete[u'foo']
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
128 self.assertEqual(u'foo', message.id)
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
129 self.assertEqual(u'Voh', message.string)
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
130 self.assertEqual(['This is an obsolete message'], message.user_comments)
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
131
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
132 def test_obsolete_message_ignored(self):
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
133 buf = StringIO(r'''# This is an obsolete message
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
134 #~ msgid "foo"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
135 #~ msgstr "Voh"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
136
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
137 # This message is not obsolete
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
138 #: main.py:1
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
139 msgid "bar"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
140 msgstr "Bahr"
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
141 ''')
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
142 catalog = pofile.read_po(buf, ignore_obsolete=True)
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
143 self.assertEqual(1, len(catalog))
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
144 self.assertEqual(0, len(catalog.obsolete))
a0d22f2f2df0 Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
145
335
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
146 def test_with_context(self):
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
147 buf = StringIO(r'''# Some string in the menu
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
148 #: main.py:1
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
149 msgctxt "Menu"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
150 msgid "foo"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
151 msgstr "Voh"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
152
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
153 # Another string in the menu
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
154 #: main.py:2
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
155 msgctxt "Menu"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
156 msgid "bar"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
157 msgstr "Bahr"
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
158 ''')
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
159 catalog = pofile.read_po(buf, ignore_obsolete=True)
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
160 self.assertEqual(2, len(catalog))
350
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 335
diff changeset
161 message = catalog.get('foo', context='Menu')
335
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
162 self.assertEqual('Menu', message.context)
350
9166eab61e29 More work on msgctxt support (#54).
cmlenz
parents: 335
diff changeset
163 message = catalog.get('bar', context='Menu')
335
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
164 self.assertEqual('Menu', message.context)
4db404d0c19b More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
165
421
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
166 # And verify it pass through write_po
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
167 out_buf = StringIO()
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
168 pofile.write_po(out_buf, catalog, omit_header=True)
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
169 assert out_buf.getvalue().strip() == buf.getvalue().strip(), \
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
170 out_buf.getvalue()
fcde0f2ff278 Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
171
428
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
172 def test_with_context_two(self):
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
173 buf = StringIO(r'''msgctxt "Menu"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
174 msgid "foo"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
175 msgstr "Voh"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
176
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
177 msgctxt "Mannu"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
178 msgid "bar"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
179 msgstr "Bahr"
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
180 ''')
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
181 catalog = pofile.read_po(buf, ignore_obsolete=True)
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
182 self.assertEqual(2, len(catalog))
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
183 message = catalog.get('foo', context='Menu')
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
184 self.assertEqual('Menu', message.context)
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
185 message = catalog.get('bar', context='Mannu')
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
186 self.assertEqual('Mannu', message.context)
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
187
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
188 # And verify it pass through write_po
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
189 out_buf = StringIO()
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
190 pofile.write_po(out_buf, catalog, omit_header=True)
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
191 assert out_buf.getvalue().strip() == buf.getvalue().strip(), out_buf.getvalue()
a974d298400f Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
192
370
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
193 def test_singlular_plural_form(self):
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
194 buf = StringIO(r'''msgid "foo"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
195 msgid_plural "foo"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
196 msgstr[0] "Voh"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
197 msgstr[1] "Vohs"''') # This is a bad po, ja_JP only uses msgstr[0]
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
198 catalog = pofile.read_po(buf, locale='ja_JP')
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
199 self.assertEqual(1, len(catalog))
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
200 self.assertEqual(1, catalog.num_plurals)
377
d0ee047cd3ae Use item access to catalog messages in tests, so that they can be easily ported back to the 0.9.x branch.
cmlenz
parents: 370
diff changeset
201 message = catalog['foo']
370
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
202 self.assertEqual(1, len(message.string))
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
203
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
204 def test_more_than_two_plural_forms(self):
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
205 buf = StringIO(r'''msgid "foo"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
206 msgid_plural "foo"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
207 msgstr[0] "Voh"
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
208 msgstr[1] "Vohs"''') # last translation form is missing
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
209 #msgstr[2] "Vohss"''')
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
210 catalog = pofile.read_po(buf, locale='lv_LV')
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
211 self.assertEqual(1, len(catalog))
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
212 self.assertEqual(3, catalog.num_plurals)
377
d0ee047cd3ae Use item access to catalog messages in tests, so that they can be easily ported back to the 0.9.x branch.
cmlenz
parents: 370
diff changeset
213 message = catalog['foo']
370
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
214 self.assertEqual(3, len(message.string))
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
215 self.assertEqual('', message.string[2])
bc18179832b7 We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
216
106
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
217
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
218 class WritePoTestCase(unittest.TestCase):
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
219
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
220 def test_join_locations(self):
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
221 catalog = Catalog()
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
222 catalog.add(u'foo', locations=[('main.py', 1)])
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
223 catalog.add(u'foo', locations=[('utils.py', 3)])
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
224 buf = StringIO()
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
225 pofile.write_po(buf, catalog, omit_header=True)
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
226 self.assertEqual('''#: main.py:1 utils.py:3
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
227 msgid "foo"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
228 msgstr ""''', buf.getvalue().strip())
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
229
228
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
230 def test_duplicate_comments(self):
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
231 catalog = Catalog()
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
232 catalog.add(u'foo', auto_comments=['A comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
233 catalog.add(u'foo', auto_comments=['A comment'])
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
234 buf = StringIO()
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
235 pofile.write_po(buf, catalog, omit_header=True)
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
236 self.assertEqual('''#. A comment
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
237 msgid "foo"
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
238 msgstr ""''', buf.getvalue().strip())
6582494abc36 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
239
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
240 def test_wrap_long_lines(self):
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
241 text = """Here's some text where
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
242 white space and line breaks matter, and should
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
243
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
244 not be removed
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
245
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
246 """
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
247 catalog = Catalog()
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
248 catalog.add(text, locations=[('main.py', 1)])
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
249 buf = StringIO()
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
250 pofile.write_po(buf, catalog, no_location=True, omit_header=True,
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
251 width=42)
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
252 self.assertEqual(r'''msgid ""
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
253 "Here's some text where \n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
254 "white space and line breaks matter, and"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
255 " should\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
256 "\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
257 "not be removed\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
258 "\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
259 msgstr ""''', buf.getvalue().strip())
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
260
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
261 def test_wrap_long_lines_with_long_word(self):
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
262 text = """Here's some text that
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
263 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
264 """
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
265 catalog = Catalog()
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
266 catalog.add(text, locations=[('main.py', 1)])
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
267 buf = StringIO()
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
268 pofile.write_po(buf, catalog, no_location=True, omit_header=True,
56
f40fc143439c Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents: 54
diff changeset
269 width=32)
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
270 self.assertEqual(r'''msgid ""
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
271 "Here's some text that\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
272 "includesareallylongwordthatmightbutshouldnt"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
273 " throw us into an infinite "
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
274 "loop\n"
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
275 msgstr ""''', buf.getvalue().strip())
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
276
103
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
277 def test_wrap_long_lines_in_header(self):
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
278 """
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
279 Verify that long lines in the header comment are wrapped correctly.
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
280 """
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
281 catalog = Catalog(project='AReallyReallyLongNameForAProject',
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
282 revision_date=datetime(2007, 4, 1))
103
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
283 buf = StringIO()
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
284 pofile.write_po(buf, catalog)
103
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
285 self.assertEqual('''\
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
286 # Translations template for AReallyReallyLongNameForAProject.
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
287 # Copyright (C) 2007 ORGANIZATION
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
288 # This file is distributed under the same license as the
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
289 # AReallyReallyLongNameForAProject project.
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
290 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
103
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
291 #
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
292 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7]))
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
293
315
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
294 def test_wrap_locations_with_hyphens(self):
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
295 catalog = Catalog()
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
296 catalog.add(u'foo', locations=[
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
297 ('doupy/templates/base/navmenu.inc.html.py', 60)
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
298 ])
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
299 catalog.add(u'foo', locations=[
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
300 ('doupy/templates/job-offers/helpers.html', 22)
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
301 ])
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
302 buf = StringIO()
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
303 pofile.write_po(buf, catalog, omit_header=True)
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
304 self.assertEqual('''#: doupy/templates/base/navmenu.inc.html.py:60
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
305 #: doupy/templates/job-offers/helpers.html:22
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
306 msgid "foo"
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
307 msgstr ""''', buf.getvalue().strip())
423
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
308
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
309 def test_no_wrap_and_width_behaviour_on_comments(self):
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
310 catalog = Catalog()
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
311 catalog.add("Pretty dam long message id, which must really be big "
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
312 "to test this wrap behaviour, if not it won't work.",
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
313 locations=[("fake.py", n) for n in range(1, 30)])
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
314 buf = StringIO()
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
315 pofile.write_po(buf, catalog, width=None, omit_header=True)
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
316 self.assertEqual("""\
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
317 #: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
318 #: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
319 #: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
320 #: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
321 #: fake.py:29
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
322 msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
323 msgstr ""
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
324
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
325 """, buf.getvalue().lower())
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
326 buf = StringIO()
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
327 pofile.write_po(buf, catalog, width=100, omit_header=True)
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
328 self.assertEqual("""\
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
329 #: 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
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
330 #: 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
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
331 #: 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
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
332 #: fake.py:29
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
333 msgid ""
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
334 "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
335 " work."
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
336 msgstr ""
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
337
fb926f48efba Now, the `--width` option, although with a default value of 76, it's not set to any value initially so that the `--no-wrap` option can be passed without throwing an error. Fixes #145.
palgarvio
parents: 421
diff changeset
338 """, buf.getvalue().lower())
315
59c7849d8b32 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
339
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
340 def test_pot_with_translator_comments(self):
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
341 catalog = Catalog()
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
342 catalog.add(u'foo', locations=[('main.py', 1)],
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
343 auto_comments=['Comment About `foo`'])
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
344 catalog.add(u'bar', locations=[('utils.py', 3)],
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
345 user_comments=['Comment About `bar` with',
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
346 'multiple lines.'])
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
347 buf = StringIO()
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
348 pofile.write_po(buf, catalog, omit_header=True)
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
349 self.assertEqual('''#. Comment About `foo`
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
350 #: main.py:1
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
351 msgid "foo"
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
352 msgstr ""
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
353
105
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
354 # Comment About `bar` with
c62b68a0b65e `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
355 # multiple lines.
80
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
356 #: utils.py:3
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
357 msgid "bar"
116e34b8cefa Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents: 56
diff changeset
358 msgstr ""''', buf.getvalue().strip())
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
359
190
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
360 def test_po_with_obsolete_message(self):
181
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
361 catalog = Catalog()
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
362 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
363 catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
364 locations=[('utils.py', 3)],
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
365 user_comments=['User comment'])
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
366 buf = StringIO()
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
367 pofile.write_po(buf, catalog, omit_header=True)
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
368 self.assertEqual('''#: main.py:1
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
369 msgid "foo"
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
370 msgstr "Voh"
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
371
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
372 # User comment
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
373 #~ msgid "bar"
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
374 #~ msgstr "Bahr"''', buf.getvalue().strip())
8a762ce37bf7 The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
375
190
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
376 def test_po_with_multiline_obsolete_message(self):
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
377 catalog = Catalog()
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
378 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
379 msgid = r"""Here's a message that covers
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
380 multiple lines, and should still be handled
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
381 correctly.
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
382 """
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
383 msgstr = r"""Here's a message that covers
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
384 multiple lines, and should still be handled
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
385 correctly.
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
386 """
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
387 catalog.obsolete[msgid] = Message(msgid, msgstr,
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
388 locations=[('utils.py', 3)])
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
389 buf = StringIO()
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
390 pofile.write_po(buf, catalog, omit_header=True)
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
391 self.assertEqual(r'''#: main.py:1
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
392 msgid "foo"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
393 msgstr "Voh"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
394
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
395 #~ msgid ""
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
396 #~ "Here's a message that covers\n"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
397 #~ "multiple lines, and should still be handled\n"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
398 #~ "correctly.\n"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
399 #~ msgstr ""
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
400 #~ "Here's a message that covers\n"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
401 #~ "multiple lines, and should still be handled\n"
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
402 #~ "correctly.\n"''', buf.getvalue().strip())
5041d90edf0c Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
403
191
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
404 def test_po_with_obsolete_message_ignored(self):
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
405 catalog = Catalog()
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
406 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
407 catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
408 locations=[('utils.py', 3)],
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
409 user_comments=['User comment'])
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
410 buf = StringIO()
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
411 pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True)
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
412 self.assertEqual('''#: main.py:1
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
413 msgid "foo"
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
414 msgstr "Voh"''', buf.getvalue().strip())
c171a0041ad2 Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents: 190
diff changeset
415
203
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
416 def test_po_with_previous_msgid(self):
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
417 catalog = Catalog()
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
418 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)],
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
419 previous_id=u'fo')
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
420 buf = StringIO()
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
421 pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
422 self.assertEqual('''#: main.py:1
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
423 #| msgid "fo"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
424 msgid "foo"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
425 msgstr "Voh"''', buf.getvalue().strip())
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
426
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
427 def test_po_with_previous_msgid_plural(self):
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
428 catalog = Catalog()
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
429 catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
430 locations=[('main.py', 1)], previous_id=(u'fo', u'fos'))
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
431 buf = StringIO()
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
432 pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
433 self.assertEqual('''#: main.py:1
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
434 #| msgid "fo"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
435 #| msgid_plural "fos"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
436 msgid "foo"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
437 msgid_plural "foos"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
438 msgstr[0] "Voh"
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
439 msgstr[1] "Voeh"''', buf.getvalue().strip())
fc1f8cd448fc Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
440
249
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
441 def test_sorted_po(self):
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
442 catalog = Catalog()
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
443 catalog.add(u'bar', locations=[('utils.py', 3)],
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
444 user_comments=['Comment About `bar` with',
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
445 'multiple lines.'])
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
446 catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
447 locations=[('main.py', 1)])
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
448 buf = StringIO()
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
449 pofile.write_po(buf, catalog, sort_output=True)
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
450 value = buf.getvalue().strip()
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
451 assert '''\
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
452 # Comment About `bar` with
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
453 # multiple lines.
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
454 #: utils.py:3
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
455 msgid "bar"
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
456 msgstr ""
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
457
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
458 #: main.py:1
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
459 msgid "foo"
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
460 msgid_plural "foos"
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
461 msgstr[0] "Voh"
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
462 msgstr[1] "Voeh"''' in value
51a1f6101fa6 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
463 assert value.find('msgid ""') < value.find('msgid "bar"') < value.find('msgid "foo"')
24
b09e90803d1b Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents: 17
diff changeset
464
356
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
465 def test_silent_location_fallback(self):
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
466 buf = StringIO('''\
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
467 #: broken_file.py
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
468 msgid "missing line number"
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
469 msgstr ""
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
470
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
471 #: broken_file.py:broken_line_number
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
472 msgid "broken line number"
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
473 msgstr ""''')
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
474 catalog = pofile.read_po(buf)
377
d0ee047cd3ae Use item access to catalog messages in tests, so that they can be easily ported back to the 0.9.x branch.
cmlenz
parents: 370
diff changeset
475 self.assertEqual(catalog['missing line number'].locations, [])
d0ee047cd3ae Use item access to catalog messages in tests, so that they can be easily ported back to the 0.9.x branch.
cmlenz
parents: 370
diff changeset
476 self.assertEqual(catalog['broken line number'].locations, [])
356
4cdca48fc832 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
477
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
478 def suite():
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
479 suite = unittest.TestSuite()
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
480 suite.addTest(doctest.DocTestSuite(pofile))
106
2cd83f77cc98 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
481 suite.addTest(unittest.makeSuite(ReadPoTestCase))
104
395704fda00b Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents: 103
diff changeset
482 suite.addTest(unittest.makeSuite(WritePoTestCase))
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
483 return suite
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
484
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
485 if __name__ == '__main__':
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
486 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software