Mercurial > babel > old > babel-test
annotate babel/messages/tests/pofile.py @ 508:dbb70d75718a stable-0.9.x
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
author | fschwarz |
---|---|
date | Fri, 04 Mar 2011 14:16:15 +0000 |
parents | 2d1c17275e5b |
children |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
448
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
3 # Copyright (C) 2007-2010 Edgewall Software |
1 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://babel.edgewall.org/wiki/License. | |
9 # | |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
12 # history and logs, available at http://babel.edgewall.org/log/. | |
13 | |
104
22f222e23b86
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 | 15 import doctest |
24
4fad20ab7cca
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 | 17 import unittest |
508
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
487
diff
changeset
|
18 import sys |
1 | 19 |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
20 from babel.messages.catalog import Catalog, Message |
54
b3395b285104
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
51
diff
changeset
|
21 from babel.messages import pofile |
293 | 22 from babel.util import FixedOffsetTimezone, LOCALTZ |
1 | 23 |
17
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
24 |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
25 class ReadPoTestCase(unittest.TestCase): |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
26 |
196
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
27 def test_preserve_locale(self): |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
28 buf = StringIO(r'''msgid "foo" |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
29 msgstr "Voh"''') |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
30 catalog = pofile.read_po(buf, locale='en_US') |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
31 self.assertEqual('en_US', catalog.locale) |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
32 |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
33 def test_preserve_domain(self): |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
34 buf = StringIO(r'''msgid "foo" |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
35 msgstr "Voh"''') |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
36 catalog = pofile.read_po(buf, domain='mydomain') |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
37 self.assertEqual('mydomain', catalog.domain) |
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
38 |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
39 def test_read_multiline(self): |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
40 buf = StringIO(r'''msgid "" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
41 "Here's some text that\n" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
42 "includesareallylongwordthatmightbutshouldnt" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
43 " throw us into an infinite " |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
44 "loop\n" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
45 msgstr ""''') |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
46 catalog = pofile.read_po(buf) |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
47 self.assertEqual(1, len(catalog)) |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
48 message = list(catalog)[1] |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
49 self.assertEqual("Here's some text that\nincludesareallylongwordthat" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
50 "mightbutshouldnt throw us into an infinite loop\n", |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
51 message.id) |
196
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
52 |
175
3c4718fb7435
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 def test_fuzzy_header(self): |
3c4718fb7435
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 buf = StringIO(r'''\ |
3c4718fb7435
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 # Translations template for AReallyReallyLongNameForAProject. |
3c4718fb7435
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 # Copyright (C) 2007 ORGANIZATION |
3c4718fb7435
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 # This file is distributed under the same license as the |
3c4718fb7435
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 # AReallyReallyLongNameForAProject project. |
3c4718fb7435
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 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
3c4718fb7435
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 # |
3c4718fb7435
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 #, fuzzy |
3c4718fb7435
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 ''') |
3c4718fb7435
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 catalog = pofile.read_po(buf) |
3c4718fb7435
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(1, len(list(catalog))) |
3c4718fb7435
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
|
65 self.assertEqual(True, list(catalog)[0].fuzzy) |
196
93a922d31eca
Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents:
191
diff
changeset
|
66 |
175
3c4718fb7435
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 def test_not_fuzzy_header(self): |
3c4718fb7435
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 buf = StringIO(r'''\ |
3c4718fb7435
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 # Translations template for AReallyReallyLongNameForAProject. |
3c4718fb7435
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 # Copyright (C) 2007 ORGANIZATION |
3c4718fb7435
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 # This file is distributed under the same license as the |
3c4718fb7435
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 # AReallyReallyLongNameForAProject project. |
3c4718fb7435
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 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
3c4718fb7435
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 # |
3c4718fb7435
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 ''') |
3c4718fb7435
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 catalog = pofile.read_po(buf) |
3c4718fb7435
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(1, len(list(catalog))) |
3c4718fb7435
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
|
78 self.assertEqual(False, list(catalog)[0].fuzzy) |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
79 |
293 | 80 def test_header_entry(self): |
81 buf = StringIO(r'''\ | |
82 # SOME DESCRIPTIVE TITLE. | |
83 # Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER | |
84 # This file is distributed under the same license as the PACKAGE package. | |
85 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. | |
86 # | |
87 #, fuzzy | |
88 msgid "" | |
89 msgstr "" | |
90 "Project-Id-Version: 3.15\n" | |
91 "Report-Msgid-Bugs-To: Fliegender Zirkus <fliegender@zirkus.de>\n" | |
92 "POT-Creation-Date: 2007-09-27 11:19+0700\n" | |
93 "PO-Revision-Date: 2007-09-27 21:42-0700\n" | |
94 "Last-Translator: John <cleese@bavaria.de>\n" | |
95 "Language-Team: German Lang <de@babel.org>\n" | |
96 "Plural-Forms: nplurals=2; plural=(n != 1)\n" | |
97 "MIME-Version: 1.0\n" | |
98 "Content-Type: text/plain; charset=iso-8859-2\n" | |
99 "Content-Transfer-Encoding: 8bit\n" | |
100 "Generated-By: Babel 1.0dev-r313\n" | |
101 ''') | |
102 catalog = pofile.read_po(buf) | |
103 self.assertEqual(1, len(list(catalog))) | |
104 self.assertEqual(u'3.15', catalog.version) | |
105 self.assertEqual(u'Fliegender Zirkus <fliegender@zirkus.de>', | |
106 catalog.msgid_bugs_address) | |
107 self.assertEqual(datetime(2007, 9, 27, 11, 19, | |
108 tzinfo=FixedOffsetTimezone(7 * 60)), | |
109 catalog.creation_date) | |
110 self.assertEqual(u'John <cleese@bavaria.de>', catalog.last_translator) | |
111 self.assertEqual(u'German Lang <de@babel.org>', catalog.language_team) | |
112 self.assertEqual(u'iso-8859-2', catalog.charset) | |
113 self.assertEqual(True, list(catalog)[0].fuzzy) | |
114 | |
199
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
115 def test_obsolete_message(self): |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
116 buf = StringIO(r'''# This is an obsolete message |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
117 #~ msgid "foo" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
118 #~ msgstr "Voh" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
119 |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
120 # This message is not obsolete |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
121 #: main.py:1 |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
122 msgid "bar" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
123 msgstr "Bahr" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
124 ''') |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
125 catalog = pofile.read_po(buf) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
126 self.assertEqual(1, len(catalog)) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
127 self.assertEqual(1, len(catalog.obsolete)) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
128 message = catalog.obsolete[u'foo'] |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
129 self.assertEqual(u'foo', message.id) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
130 self.assertEqual(u'Voh', message.string) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
131 self.assertEqual(['This is an obsolete message'], message.user_comments) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
132 |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
133 def test_obsolete_message_ignored(self): |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
134 buf = StringIO(r'''# This is an obsolete message |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
135 #~ msgid "foo" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
136 #~ msgstr "Voh" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
137 |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
138 # This message is not obsolete |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
139 #: main.py:1 |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
140 msgid "bar" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
141 msgstr "Bahr" |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
142 ''') |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
143 catalog = pofile.read_po(buf, ignore_obsolete=True) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
144 self.assertEqual(1, len(catalog)) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
145 self.assertEqual(0, len(catalog.obsolete)) |
ace575fff5ac
Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents:
196
diff
changeset
|
146 |
487 | 147 def test_single_plural_form(self): |
379 | 148 buf = StringIO(r'''msgid "foo" |
487 | 149 msgid_plural "foos" |
150 msgstr[0] "Voh"''') | |
379 | 151 catalog = pofile.read_po(buf, locale='ja_JP') |
152 self.assertEqual(1, len(catalog)) | |
153 self.assertEqual(1, catalog.num_plurals) | |
154 message = catalog['foo'] | |
155 self.assertEqual(1, len(message.string)) | |
487 | 156 |
157 def test_singular_plural_form(self): | |
158 buf = StringIO(r'''msgid "foo" | |
159 msgid_plural "foos" | |
160 msgstr[0] "Voh" | |
161 msgstr[1] "Vohs"''') | |
162 catalog = pofile.read_po(buf, locale='nl_NL') | |
163 self.assertEqual(1, len(catalog)) | |
164 self.assertEqual(2, catalog.num_plurals) | |
165 message = catalog['foo'] | |
166 self.assertEqual(2, len(message.string)) | |
167 | |
379 | 168 def test_more_than_two_plural_forms(self): |
169 buf = StringIO(r'''msgid "foo" | |
487 | 170 msgid_plural "foos" |
379 | 171 msgstr[0] "Voh" |
487 | 172 msgstr[1] "Vohs" |
173 msgstr[2] "Vohss"''') | |
379 | 174 catalog = pofile.read_po(buf, locale='lv_LV') |
175 self.assertEqual(1, len(catalog)) | |
176 self.assertEqual(3, catalog.num_plurals) | |
177 message = catalog['foo'] | |
178 self.assertEqual(3, len(message.string)) | |
487 | 179 self.assertEqual(u'Vohss', message.string[2]) |
379 | 180 |
448
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
181 def test_plural_with_square_brackets(self): |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
182 buf = StringIO(r'''msgid "foo" |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
183 msgid_plural "foos" |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
184 msgstr[0] "Voh [text]" |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
185 msgstr[1] "Vohs [text]"''') |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
186 catalog = pofile.read_po(buf, locale='nb_NO') |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
187 self.assertEqual(1, len(catalog)) |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
188 self.assertEqual(2, catalog.num_plurals) |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
189 message = catalog['foo'] |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
190 self.assertEqual(2, len(message.string)) |
c6babc3bbc10
Backport r483. This fixes messages containing square brackets from failing
jruigrok
parents:
379
diff
changeset
|
191 |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
192 |
104
22f222e23b86
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
|
193 class WritePoTestCase(unittest.TestCase): |
24
4fad20ab7cca
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
|
194 |
4fad20ab7cca
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
|
195 def test_join_locations(self): |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
196 catalog = Catalog() |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
197 catalog.add(u'foo', locations=[('main.py', 1)]) |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
198 catalog.add(u'foo', locations=[('utils.py', 3)]) |
24
4fad20ab7cca
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
|
199 buf = StringIO() |
104
22f222e23b86
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
|
200 pofile.write_po(buf, catalog, omit_header=True) |
24
4fad20ab7cca
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
|
201 self.assertEqual('''#: main.py:1 utils.py:3 |
4fad20ab7cca
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
|
202 msgid "foo" |
4fad20ab7cca
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
|
203 msgstr ""''', buf.getvalue().strip()) |
4fad20ab7cca
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
|
204 |
228
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
205 def test_duplicate_comments(self): |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
206 catalog = Catalog() |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
207 catalog.add(u'foo', auto_comments=['A comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
208 catalog.add(u'foo', auto_comments=['A comment']) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
209 buf = StringIO() |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
210 pofile.write_po(buf, catalog, omit_header=True) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
211 self.assertEqual('''#. A comment |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
212 msgid "foo" |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
213 msgstr ""''', buf.getvalue().strip()) |
fd29fabdc986
Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents:
203
diff
changeset
|
214 |
24
4fad20ab7cca
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
|
215 def test_wrap_long_lines(self): |
4fad20ab7cca
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
|
216 text = """Here's some text where |
4fad20ab7cca
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
|
217 white space and line breaks matter, and should |
4fad20ab7cca
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
|
218 |
4fad20ab7cca
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 not be removed |
4fad20ab7cca
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 |
4fad20ab7cca
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
|
221 """ |
56
27fba894d3ca
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 = Catalog() |
27fba894d3ca
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(text, locations=[('main.py', 1)]) |
24
4fad20ab7cca
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
22f222e23b86
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, no_location=True, omit_header=True, |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
226 width=42) |
24
4fad20ab7cca
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 self.assertEqual(r'''msgid "" |
4fad20ab7cca
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 "Here's some text where \n" |
4fad20ab7cca
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 "white space and line breaks matter, and" |
4fad20ab7cca
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
|
230 " should\n" |
4fad20ab7cca
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
|
231 "\n" |
4fad20ab7cca
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
|
232 "not be removed\n" |
4fad20ab7cca
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
|
233 "\n" |
4fad20ab7cca
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
|
234 msgstr ""''', buf.getvalue().strip()) |
4fad20ab7cca
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
|
235 |
4fad20ab7cca
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
|
236 def test_wrap_long_lines_with_long_word(self): |
4fad20ab7cca
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
|
237 text = """Here's some text that |
4fad20ab7cca
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
|
238 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop |
4fad20ab7cca
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
|
239 """ |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
240 catalog = Catalog() |
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
241 catalog.add(text, locations=[('main.py', 1)]) |
24
4fad20ab7cca
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 buf = StringIO() |
104
22f222e23b86
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
|
243 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
56
27fba894d3ca
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
244 width=32) |
24
4fad20ab7cca
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 self.assertEqual(r'''msgid "" |
4fad20ab7cca
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 "Here's some text that\n" |
4fad20ab7cca
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
|
247 "includesareallylongwordthatmightbutshouldnt" |
4fad20ab7cca
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
|
248 " throw us into an infinite " |
4fad20ab7cca
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 "loop\n" |
4fad20ab7cca
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
|
250 msgstr ""''', buf.getvalue().strip()) |
80
9c84b9fa5d30
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
|
251 |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
252 def test_wrap_long_lines_in_header(self): |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
253 """ |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
254 Verify that long lines in the header comment are wrapped correctly. |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
255 """ |
104
22f222e23b86
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
|
256 catalog = Catalog(project='AReallyReallyLongNameForAProject', |
22f222e23b86
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
|
257 revision_date=datetime(2007, 4, 1)) |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
258 buf = StringIO() |
104
22f222e23b86
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
|
259 pofile.write_po(buf, catalog) |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
260 self.assertEqual('''\ |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
261 # Translations template for AReallyReallyLongNameForAProject. |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
262 # Copyright (C) 2007 ORGANIZATION |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
263 # This file is distributed under the same license as the |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
264 # AReallyReallyLongNameForAProject project. |
104
22f222e23b86
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
|
265 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
266 # |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
267 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
268 |
316 | 269 def test_wrap_locations_with_hyphens(self): |
270 catalog = Catalog() | |
271 catalog.add(u'foo', locations=[ | |
272 ('doupy/templates/base/navmenu.inc.html.py', 60) | |
273 ]) | |
274 catalog.add(u'foo', locations=[ | |
275 ('doupy/templates/job-offers/helpers.html', 22) | |
276 ]) | |
277 buf = StringIO() | |
278 pofile.write_po(buf, catalog, omit_header=True) | |
279 self.assertEqual('''#: doupy/templates/base/navmenu.inc.html.py:60 | |
280 #: doupy/templates/job-offers/helpers.html:22 | |
281 msgid "foo" | |
282 msgstr ""''', buf.getvalue().strip()) | |
476 | 283 |
284 def test_no_wrap_and_width_behaviour_on_comments(self): | |
285 catalog = Catalog() | |
286 catalog.add("Pretty dam long message id, which must really be big " | |
287 "to test this wrap behaviour, if not it won't work.", | |
288 locations=[("fake.py", n) for n in range(1, 30)]) | |
289 buf = StringIO() | |
290 pofile.write_po(buf, catalog, width=None, omit_header=True) | |
291 self.assertEqual("""\ | |
292 #: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7 | |
293 #: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14 | |
294 #: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21 | |
295 #: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28 | |
296 #: fake.py:29 | |
297 msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work." | |
298 msgstr "" | |
299 | |
300 """, buf.getvalue().lower()) | |
301 buf = StringIO() | |
302 pofile.write_po(buf, catalog, width=100, omit_header=True) | |
303 self.assertEqual("""\ | |
304 #: 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 | |
305 #: 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 | |
306 #: 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 | |
307 #: fake.py:29 | |
308 msgid "" | |
309 "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't" | |
310 " work." | |
311 msgstr "" | |
312 | |
313 """, buf.getvalue().lower()) | |
316 | 314 |
80
9c84b9fa5d30
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
|
315 def test_pot_with_translator_comments(self): |
9c84b9fa5d30
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
|
316 catalog = Catalog() |
9c84b9fa5d30
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
|
317 catalog.add(u'foo', locations=[('main.py', 1)], |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
318 auto_comments=['Comment About `foo`']) |
80
9c84b9fa5d30
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
|
319 catalog.add(u'bar', locations=[('utils.py', 3)], |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
320 user_comments=['Comment About `bar` with', |
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
321 'multiple lines.']) |
80
9c84b9fa5d30
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
|
322 buf = StringIO() |
104
22f222e23b86
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
|
323 pofile.write_po(buf, catalog, omit_header=True) |
80
9c84b9fa5d30
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
|
324 self.assertEqual('''#. Comment About `foo` |
9c84b9fa5d30
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
|
325 #: main.py:1 |
9c84b9fa5d30
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
|
326 msgid "foo" |
9c84b9fa5d30
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
|
327 msgstr "" |
9c84b9fa5d30
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
|
328 |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
329 # Comment About `bar` with |
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
330 # multiple lines. |
80
9c84b9fa5d30
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
|
331 #: utils.py:3 |
9c84b9fa5d30
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
|
332 msgid "bar" |
9c84b9fa5d30
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
|
333 msgstr ""''', buf.getvalue().strip()) |
24
4fad20ab7cca
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
|
334 |
190
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
335 def test_po_with_obsolete_message(self): |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
336 catalog = Catalog() |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
337 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
338 catalog.obsolete['bar'] = Message(u'bar', u'Bahr', |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
339 locations=[('utils.py', 3)], |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
340 user_comments=['User comment']) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
341 buf = StringIO() |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
342 pofile.write_po(buf, catalog, omit_header=True) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
343 self.assertEqual('''#: main.py:1 |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
344 msgid "foo" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
345 msgstr "Voh" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
346 |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
347 # User comment |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
348 #~ msgid "bar" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
349 #~ msgstr "Bahr"''', buf.getvalue().strip()) |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
350 |
190
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
351 def test_po_with_multiline_obsolete_message(self): |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
352 catalog = Catalog() |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
353 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
354 msgid = r"""Here's a message that covers |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
355 multiple lines, and should still be handled |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
356 correctly. |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
357 """ |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
358 msgstr = r"""Here's a message that covers |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
359 multiple lines, and should still be handled |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
360 correctly. |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
361 """ |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
362 catalog.obsolete[msgid] = Message(msgid, msgstr, |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
363 locations=[('utils.py', 3)]) |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
364 buf = StringIO() |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
365 pofile.write_po(buf, catalog, omit_header=True) |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
366 self.assertEqual(r'''#: main.py:1 |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
367 msgid "foo" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
368 msgstr "Voh" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
369 |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
370 #~ msgid "" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
371 #~ "Here's a message that covers\n" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
372 #~ "multiple lines, and should still be handled\n" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
373 #~ "correctly.\n" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
374 #~ msgstr "" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
375 #~ "Here's a message that covers\n" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
376 #~ "multiple lines, and should still be handled\n" |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
377 #~ "correctly.\n"''', buf.getvalue().strip()) |
84193e6612f8
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
181
diff
changeset
|
378 |
191
cf09490f22b3
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
|
379 def test_po_with_obsolete_message_ignored(self): |
cf09490f22b3
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
|
380 catalog = Catalog() |
cf09490f22b3
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
|
381 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
cf09490f22b3
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
|
382 catalog.obsolete['bar'] = Message(u'bar', u'Bahr', |
cf09490f22b3
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
|
383 locations=[('utils.py', 3)], |
cf09490f22b3
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
|
384 user_comments=['User comment']) |
cf09490f22b3
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
|
385 buf = StringIO() |
cf09490f22b3
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
|
386 pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True) |
cf09490f22b3
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
|
387 self.assertEqual('''#: main.py:1 |
cf09490f22b3
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
|
388 msgid "foo" |
cf09490f22b3
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
|
389 msgstr "Voh"''', buf.getvalue().strip()) |
cf09490f22b3
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
|
390 |
203 | 391 def test_po_with_previous_msgid(self): |
392 catalog = Catalog() | |
393 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)], | |
394 previous_id=u'fo') | |
395 buf = StringIO() | |
396 pofile.write_po(buf, catalog, omit_header=True, include_previous=True) | |
397 self.assertEqual('''#: main.py:1 | |
398 #| msgid "fo" | |
399 msgid "foo" | |
400 msgstr "Voh"''', buf.getvalue().strip()) | |
401 | |
402 def test_po_with_previous_msgid_plural(self): | |
403 catalog = Catalog() | |
404 catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), | |
405 locations=[('main.py', 1)], previous_id=(u'fo', u'fos')) | |
406 buf = StringIO() | |
407 pofile.write_po(buf, catalog, omit_header=True, include_previous=True) | |
408 self.assertEqual('''#: main.py:1 | |
409 #| msgid "fo" | |
410 #| msgid_plural "fos" | |
411 msgid "foo" | |
412 msgid_plural "foos" | |
413 msgstr[0] "Voh" | |
414 msgstr[1] "Voeh"''', buf.getvalue().strip()) | |
415 | |
249
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
416 def test_sorted_po(self): |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
417 catalog = Catalog() |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
418 catalog.add(u'bar', locations=[('utils.py', 3)], |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
419 user_comments=['Comment About `bar` with', |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
420 'multiple lines.']) |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
421 catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'), |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
422 locations=[('main.py', 1)]) |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
423 buf = StringIO() |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
424 pofile.write_po(buf, catalog, sort_output=True) |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
425 value = buf.getvalue().strip() |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
426 assert '''\ |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
427 # Comment About `bar` with |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
428 # multiple lines. |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
429 #: utils.py:3 |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
430 msgid "bar" |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
431 msgstr "" |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
432 |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
433 #: main.py:1 |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
434 msgid "foo" |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
435 msgid_plural "foos" |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
436 msgstr[0] "Voh" |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
437 msgstr[1] "Voeh"''' in value |
00960ab0a631
added test cases for correct po/mofile sorting, following up r264
pjenvey
parents:
228
diff
changeset
|
438 assert value.find('msgid ""') < value.find('msgid "bar"') < value.find('msgid "foo"') |
24
4fad20ab7cca
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
|
439 |
369 | 440 def test_silent_location_fallback(self): |
441 buf = StringIO('''\ | |
442 #: broken_file.py | |
443 msgid "missing line number" | |
444 msgstr "" | |
445 | |
446 #: broken_file.py:broken_line_number | |
447 msgid "broken line number" | |
448 msgstr ""''') | |
449 catalog = pofile.read_po(buf) | |
450 self.assertEqual(catalog['missing line number'].locations, []) | |
451 self.assertEqual(catalog['broken line number'].locations, []) | |
452 | |
1 | 453 def suite(): |
454 suite = unittest.TestSuite() | |
508
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
487
diff
changeset
|
455 is_py23 = sys.version_info[0:2] == (2, 3) |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
487
diff
changeset
|
456 if not is_py23: |
dbb70d75718a
Fix Python 2.3 compatibility for 0.9 branch (closes #233)
fschwarz
parents:
487
diff
changeset
|
457 suite.addTest(doctest.DocTestSuite(pofile)) |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
458 suite.addTest(unittest.makeSuite(ReadPoTestCase)) |
104
22f222e23b86
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
|
459 suite.addTest(unittest.makeSuite(WritePoTestCase)) |
1 | 460 return suite |
461 | |
462 if __name__ == '__main__': | |
463 unittest.main(defaultTest='suite') |