annotate babel/messages/tests/pofile.py @ 530:85e1beadacb0

Update the copyright line.
author jruigrok
date Sat, 05 Mar 2011 15:22:28 +0000
parents 6567aab3fce1
children f642c81ce8cc
rev   line source
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
2 #
530
85e1beadacb0 Update the copyright line.
jruigrok
parents: 447
diff changeset
3 # Copyright (C) 2007-2011 Edgewall Software
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
5 #
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
9 #
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
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
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
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
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
17 import unittest
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
18
181
9a1acb41e7dd 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
b3395b285104 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
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
21 from babel.util import FixedOffsetTimezone, LOCALTZ
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
22
17
6aa4c4df8871 Recognize python-format messages also for unnamed parameters.
cmlenz
parents: 12
diff changeset
23
106
9b22b36066f6 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):
9b22b36066f6 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
25
196
93a922d31eca 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):
93a922d31eca 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"
93a922d31eca Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
28 msgstr "Voh"''')
93a922d31eca 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')
93a922d31eca 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)
93a922d31eca Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
31
93a922d31eca 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):
93a922d31eca 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"
93a922d31eca Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
34 msgstr "Voh"''')
93a922d31eca 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')
93a922d31eca 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)
93a922d31eca Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
37
106
9b22b36066f6 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):
9b22b36066f6 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 ""
9b22b36066f6 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"
9b22b36066f6 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
41 "includesareallylongwordthatmightbutshouldnt"
9b22b36066f6 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 "
9b22b36066f6 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
43 "loop\n"
9b22b36066f6 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
44 msgstr ""''')
9b22b36066f6 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)
9b22b36066f6 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))
9b22b36066f6 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]
9b22b36066f6 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"
9b22b36066f6 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",
9b22b36066f6 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
93a922d31eca Fix for #35, and a minor improvement to how we parse the catalog fuzzy bit.
cmlenz
parents: 191
diff changeset
51
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
52 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
53 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
54 # 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
55 # 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
56 # 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
57 # 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
58 # 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
59 #
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 #, 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
61 ''')
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 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
63 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
64 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
65
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
66 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
67 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
68 # 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
69 # 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
70 # 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
71 # 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
72 # 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
73 #
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 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
76 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
77 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
78
291
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
79 def test_header_entry(self):
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
80 buf = StringIO(r'''\
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
81 # SOME DESCRIPTIVE TITLE.
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
82 # Copyright (C) 2007 THE PACKAGE'S COPYRIGHT HOLDER
400f01be1537 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.
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
84 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
85 #
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
86 #, fuzzy
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
87 msgid ""
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
88 msgstr ""
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
89 "Project-Id-Version: 3.15\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
90 "Report-Msgid-Bugs-To: Fliegender Zirkus <fliegender@zirkus.de>\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
91 "POT-Creation-Date: 2007-09-27 11:19+0700\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
92 "PO-Revision-Date: 2007-09-27 21:42-0700\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
93 "Last-Translator: John <cleese@bavaria.de>\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
94 "Language-Team: German Lang <de@babel.org>\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
95 "Plural-Forms: nplurals=2; plural=(n != 1)\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
96 "MIME-Version: 1.0\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
97 "Content-Type: text/plain; charset=iso-8859-2\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
98 "Content-Transfer-Encoding: 8bit\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
99 "Generated-By: Babel 1.0dev-r313\n"
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
100 ''')
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
101 catalog = pofile.read_po(buf)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
102 self.assertEqual(1, len(list(catalog)))
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
103 self.assertEqual(u'3.15', catalog.version)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
104 self.assertEqual(u'Fliegender Zirkus <fliegender@zirkus.de>',
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
105 catalog.msgid_bugs_address)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
106 self.assertEqual(datetime(2007, 9, 27, 11, 19,
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
107 tzinfo=FixedOffsetTimezone(7 * 60)),
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
108 catalog.creation_date)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
109 self.assertEqual(u'John <cleese@bavaria.de>', catalog.last_translator)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
110 self.assertEqual(u'German Lang <de@babel.org>', catalog.language_team)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
111 self.assertEqual(u'iso-8859-2', catalog.charset)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
112 self.assertEqual(True, list(catalog)[0].fuzzy)
400f01be1537 fix catalogs' charset values not being recognized
pjenvey
parents: 249
diff changeset
113
199
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
114 def test_obsolete_message(self):
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
115 buf = StringIO(r'''# This is an obsolete message
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
116 #~ msgid "foo"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
117 #~ msgstr "Voh"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
118
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
119 # This message is not obsolete
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
120 #: main.py:1
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
121 msgid "bar"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
122 msgstr "Bahr"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
123 ''')
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
124 catalog = pofile.read_po(buf)
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
125 self.assertEqual(1, len(catalog))
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
126 self.assertEqual(1, len(catalog.obsolete))
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
127 message = catalog.obsolete[u'foo']
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
128 self.assertEqual(u'foo', message.id)
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
129 self.assertEqual(u'Voh', message.string)
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
130 self.assertEqual(['This is an obsolete message'], message.user_comments)
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
131
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
132 def test_obsolete_message_ignored(self):
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
133 buf = StringIO(r'''# This is an obsolete message
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
134 #~ msgid "foo"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
135 #~ msgstr "Voh"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
136
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
137 # This message is not obsolete
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
138 #: main.py:1
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
139 msgid "bar"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
140 msgstr "Bahr"
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
141 ''')
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
142 catalog = pofile.read_po(buf, ignore_obsolete=True)
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
143 self.assertEqual(1, len(catalog))
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
144 self.assertEqual(0, len(catalog.obsolete))
ace575fff5ac Handle obsolete messages when parsing catalogs. Closes #32.
cmlenz
parents: 196
diff changeset
145
335
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
146 def test_with_context(self):
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
147 buf = StringIO(r'''# Some string in the menu
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
148 #: main.py:1
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
149 msgctxt "Menu"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
150 msgid "foo"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
151 msgstr "Voh"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
152
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
153 # Another string in the menu
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
154 #: main.py:2
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
155 msgctxt "Menu"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
156 msgid "bar"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
157 msgstr "Bahr"
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
158 ''')
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
159 catalog = pofile.read_po(buf, ignore_obsolete=True)
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
160 self.assertEqual(2, len(catalog))
350
24b8e5ca7a76 More work on msgctxt support (#54).
cmlenz
parents: 335
diff changeset
161 message = catalog.get('foo', context='Menu')
335
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
162 self.assertEqual('Menu', message.context)
350
24b8e5ca7a76 More work on msgctxt support (#54).
cmlenz
parents: 335
diff changeset
163 message = catalog.get('bar', context='Menu')
335
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
164 self.assertEqual('Menu', message.context)
9c41fe73e2e6 More preparation for msgctxt support (#54).
cmlenz
parents: 315
diff changeset
165
421
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
166 # And verify it pass through write_po
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
167 out_buf = StringIO()
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
168 pofile.write_po(out_buf, catalog, omit_header=True)
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
169 assert out_buf.getvalue().strip() == buf.getvalue().strip(), \
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
170 out_buf.getvalue()
14bebc7817eb Include patch from Asheesh Laroia. Fixes #45.
palgarvio
parents: 377
diff changeset
171
428
6a62763f2fc4 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):
6a62763f2fc4 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"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
174 msgid "foo"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
175 msgstr "Voh"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
176
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
177 msgctxt "Mannu"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
178 msgid "bar"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
179 msgstr "Bahr"
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
180 ''')
6a62763f2fc4 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)
6a62763f2fc4 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))
6a62763f2fc4 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')
6a62763f2fc4 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)
6a62763f2fc4 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')
6a62763f2fc4 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)
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
187
6a62763f2fc4 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
6a62763f2fc4 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()
6a62763f2fc4 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)
6a62763f2fc4 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()
6a62763f2fc4 Fix for msgctxt parsing in PO files. Thanks to Asheesh Laroia for the patch. Closes #159.
cmlenz
parents: 423
diff changeset
192
443
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
193 def test_single_plural_form(self):
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
194 buf = StringIO(r'''msgid "foo"
446
02a4a0f6e6d0 Actually make the msgid_plural be a plural as per typical use case.
jruigrok
parents: 445
diff changeset
195 msgid_plural "foos"
443
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
196 msgstr[0] "Voh"''')
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
197 catalog = pofile.read_po(buf, locale='ja_JP')
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
198 self.assertEqual(1, len(catalog))
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
199 self.assertEqual(1, catalog.num_plurals)
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
200 message = catalog['foo']
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
201 self.assertEqual(1, len(message.string))
6672771289bd Add a test for a locale with one plural form.
jruigrok
parents: 442
diff changeset
202
442
ee29b66fafbf Fix testcase name typo.
jruigrok
parents: 441
diff changeset
203 def test_singular_plural_form(self):
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
204 buf = StringIO(r'''msgid "foo"
446
02a4a0f6e6d0 Actually make the msgid_plural be a plural as per typical use case.
jruigrok
parents: 445
diff changeset
205 msgid_plural "foos"
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
206 msgstr[0] "Voh"
442
ee29b66fafbf Fix testcase name typo.
jruigrok
parents: 441
diff changeset
207 msgstr[1] "Vohs"''')
ee29b66fafbf Fix testcase name typo.
jruigrok
parents: 441
diff changeset
208 catalog = pofile.read_po(buf, locale='nl_NL')
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
209 self.assertEqual(1, len(catalog))
442
ee29b66fafbf Fix testcase name typo.
jruigrok
parents: 441
diff changeset
210 self.assertEqual(2, catalog.num_plurals)
377
6611cc6363b6 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
211 message = catalog['foo']
442
ee29b66fafbf Fix testcase name typo.
jruigrok
parents: 441
diff changeset
212 self.assertEqual(2, len(message.string))
441
f4c0d8fe8af9 Make sure to only strip on the first occurence of ].
jruigrok
parents: 428
diff changeset
213
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
214 def test_more_than_two_plural_forms(self):
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
215 buf = StringIO(r'''msgid "foo"
446
02a4a0f6e6d0 Actually make the msgid_plural be a plural as per typical use case.
jruigrok
parents: 445
diff changeset
216 msgid_plural "foos"
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
217 msgstr[0] "Voh"
445
1056b2e7bad2 More than two plural forms work nowadays. Adjust the test.
jruigrok
parents: 444
diff changeset
218 msgstr[1] "Vohs"
1056b2e7bad2 More than two plural forms work nowadays. Adjust the test.
jruigrok
parents: 444
diff changeset
219 msgstr[2] "Vohss"''')
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
220 catalog = pofile.read_po(buf, locale='lv_LV')
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
221 self.assertEqual(1, len(catalog))
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
222 self.assertEqual(3, catalog.num_plurals)
377
6611cc6363b6 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
223 message = catalog['foo']
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
224 self.assertEqual(3, len(message.string))
445
1056b2e7bad2 More than two plural forms work nowadays. Adjust the test.
jruigrok
parents: 444
diff changeset
225 self.assertEqual(u'Vohss', message.string[2])
370
6129d2e770bc We no longer neglect `catalog.plurals`. Added tests for it. Fixes #120.
palgarvio
parents: 356
diff changeset
226
444
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
227 def test_plural_with_square_brackets(self):
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
228 buf = StringIO(r'''msgid "foo"
446
02a4a0f6e6d0 Actually make the msgid_plural be a plural as per typical use case.
jruigrok
parents: 445
diff changeset
229 msgid_plural "foos"
444
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
230 msgstr[0] "Voh [text]"
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
231 msgstr[1] "Vohs [text]"''')
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
232 catalog = pofile.read_po(buf, locale='nb_NO')
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
233 self.assertEqual(1, len(catalog))
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
234 self.assertEqual(2, catalog.num_plurals)
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
235 message = catalog['foo']
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
236 self.assertEqual(2, len(message.string))
02c3b114a122 Put the square brackets test after all the normal plural tests. It's more
jruigrok
parents: 443
diff changeset
237
106
9b22b36066f6 Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents: 105
diff changeset
238
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
239 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
240
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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250
228
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
251 def test_duplicate_comments(self):
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
252 catalog = Catalog()
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
253 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
254 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
255 buf = StringIO()
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
256 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
257 self.assertEqual('''#. A comment
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
258 msgid "foo"
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
259 msgstr ""''', buf.getvalue().strip())
fd29fabdc986 Follow-up to [239]: also combine duplicate comments when writing PO files.
cmlenz
parents: 203
diff changeset
260
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
261 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
262 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
263 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
264
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
265 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
266
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
267 """
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
268 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
269 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
270 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
271 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
272 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
273 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
274 "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
275 "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
276 " 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
277 "\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
278 "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
279 "\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
280 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
281
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
282 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
283 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
284 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
285 """
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
286 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
287 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
288 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
289 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
290 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
291 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
292 "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
293 "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
294 " 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
295 "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
296 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
297
103
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
298 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
299 """
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
300 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
301 """
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
302 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
303 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
304 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
305 pofile.write_po(buf, catalog)
103
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
306 self.assertEqual('''\
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
307 # Translations template for AReallyReallyLongNameForAProject.
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
308 # Copyright (C) 2007 ORGANIZATION
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
309 # 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
310 # 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
311 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007.
103
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
312 #
7cdf89eb9007 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
313 #, 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
314
315
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
315 def test_wrap_locations_with_hyphens(self):
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
316 catalog = Catalog()
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
317 catalog.add(u'foo', locations=[
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
318 ('doupy/templates/base/navmenu.inc.html.py', 60)
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
319 ])
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
320 catalog.add(u'foo', locations=[
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
321 ('doupy/templates/job-offers/helpers.html', 22)
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
322 ])
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
323 buf = StringIO()
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
324 pofile.write_po(buf, catalog, omit_header=True)
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
325 self.assertEqual('''#: doupy/templates/base/navmenu.inc.html.py:60
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
326 #: doupy/templates/job-offers/helpers.html:22
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
327 msgid "foo"
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
328 msgstr ""''', buf.getvalue().strip())
423
8f91314df0b9 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
8f91314df0b9 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 def test_no_wrap_and_width_behaviour_on_comments(self):
8f91314df0b9 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 catalog = Catalog()
8f91314df0b9 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 catalog.add("Pretty dam long message id, which must really be big "
8f91314df0b9 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 "to test this wrap behaviour, if not it won't work.",
8f91314df0b9 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 locations=[("fake.py", n) for n in range(1, 30)])
8f91314df0b9 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 buf = StringIO()
8f91314df0b9 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 pofile.write_po(buf, catalog, width=None, omit_header=True)
8f91314df0b9 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 self.assertEqual("""\
8f91314df0b9 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 #: fake.py:1 fake.py:2 fake.py:3 fake.py:4 fake.py:5 fake.py:6 fake.py:7
8f91314df0b9 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
339 #: fake.py:8 fake.py:9 fake.py:10 fake.py:11 fake.py:12 fake.py:13 fake.py:14
8f91314df0b9 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
340 #: fake.py:15 fake.py:16 fake.py:17 fake.py:18 fake.py:19 fake.py:20 fake.py:21
8f91314df0b9 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
341 #: fake.py:22 fake.py:23 fake.py:24 fake.py:25 fake.py:26 fake.py:27 fake.py:28
8f91314df0b9 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
342 #: fake.py:29
8f91314df0b9 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
343 msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
8f91314df0b9 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
344 msgstr ""
8f91314df0b9 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
345
8f91314df0b9 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
346 """, buf.getvalue().lower())
8f91314df0b9 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
347 buf = StringIO()
8f91314df0b9 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
348 pofile.write_po(buf, catalog, width=100, omit_header=True)
8f91314df0b9 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
349 self.assertEqual("""\
8f91314df0b9 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
350 #: 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
8f91314df0b9 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
351 #: 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
8f91314df0b9 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
352 #: 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
8f91314df0b9 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
353 #: fake.py:29
8f91314df0b9 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
354 msgid ""
8f91314df0b9 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
355 "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
8f91314df0b9 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
356 " work."
8f91314df0b9 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
357 msgstr ""
8f91314df0b9 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
358
8f91314df0b9 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
359 """, buf.getvalue().lower())
315
5e80cf8e3299 Fix for #79 (location lines wrapping at hyphens).
cmlenz
parents: 291
diff changeset
360
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
361 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
362 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
363 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
364 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
365 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
366 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
367 '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
368 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
369 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
370 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
371 #: 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
372 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
373 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
374
105
f744dd56573d `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
375 # Comment About `bar` with
f744dd56573d `Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents: 104
diff changeset
376 # 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
377 #: 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
378 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
379 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
380
190
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
381 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
382 catalog = Catalog()
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
383 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
384 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
385 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
386 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
387 buf = StringIO()
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
388 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
389 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
390 msgid "foo"
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
391 msgstr "Voh"
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
392
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
393 # User comment
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
394 #~ msgid "bar"
9a1acb41e7dd The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents: 175
diff changeset
395 #~ 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
396
190
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
397 def test_po_with_multiline_obsolete_message(self):
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
398 catalog = Catalog()
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
399 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
400 msgid = r"""Here's a message that covers
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
401 multiple lines, and should still be handled
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
402 correctly.
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
403 """
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
404 msgstr = r"""Here's a message that covers
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
405 multiple lines, and should still be handled
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
406 correctly.
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
407 """
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
408 catalog.obsolete[msgid] = Message(msgid, msgstr,
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
409 locations=[('utils.py', 3)])
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
410 buf = StringIO()
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
411 pofile.write_po(buf, catalog, omit_header=True)
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
412 self.assertEqual(r'''#: main.py:1
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
413 msgid "foo"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
414 msgstr "Voh"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
415
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
416 #~ msgid ""
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
417 #~ "Here's a message that covers\n"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
418 #~ "multiple lines, and should still be handled\n"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
419 #~ "correctly.\n"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
420 #~ msgstr ""
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
421 #~ "Here's a message that covers\n"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
422 #~ "multiple lines, and should still be handled\n"
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
423 #~ "correctly.\n"''', buf.getvalue().strip())
84193e6612f8 Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents: 181
diff changeset
424
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
425 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
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433 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
434 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
435 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
436
203
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
437 def test_po_with_previous_msgid(self):
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
438 catalog = Catalog()
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
439 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)],
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
440 previous_id=u'fo')
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
441 buf = StringIO()
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
442 pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
443 self.assertEqual('''#: main.py:1
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
444 #| msgid "fo"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
445 msgid "foo"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
446 msgstr "Voh"''', buf.getvalue().strip())
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
447
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
448 def test_po_with_previous_msgid_plural(self):
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
449 catalog = Catalog()
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
450 catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
451 locations=[('main.py', 1)], previous_id=(u'fo', u'fos'))
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
452 buf = StringIO()
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
453 pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
454 self.assertEqual('''#: main.py:1
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
455 #| msgid "fo"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
456 #| msgid_plural "fos"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
457 msgid "foo"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
458 msgid_plural "foos"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
459 msgstr[0] "Voh"
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
460 msgstr[1] "Voeh"''', buf.getvalue().strip())
e50aaaabb3d3 Minor changes to how previous msgids are processed.
cmlenz
parents: 199
diff changeset
461
249
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
462 def test_sorted_po(self):
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
463 catalog = Catalog()
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
464 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
465 user_comments=['Comment About `bar` with',
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
466 'multiple lines.'])
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
467 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
468 locations=[('main.py', 1)])
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
469 buf = StringIO()
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
470 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
471 value = buf.getvalue().strip()
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
472 assert '''\
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
473 # Comment About `bar` with
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
474 # multiple lines.
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
475 #: utils.py:3
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
476 msgid "bar"
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
477 msgstr ""
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
478
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
479 #: main.py:1
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
480 msgid "foo"
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
481 msgid_plural "foos"
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
482 msgstr[0] "Voh"
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
483 msgstr[1] "Voeh"''' in value
00960ab0a631 added test cases for correct po/mofile sorting, following up r264
pjenvey
parents: 228
diff changeset
484 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
485
356
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
486 def test_silent_location_fallback(self):
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
487 buf = StringIO('''\
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
488 #: broken_file.py
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
489 msgid "missing line number"
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
490 msgstr ""
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
491
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
492 #: broken_file.py:broken_line_number
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
493 msgid "broken line number"
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
494 msgstr ""''')
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
495 catalog = pofile.read_po(buf)
377
6611cc6363b6 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
496 self.assertEqual(catalog['missing line number'].locations, [])
6611cc6363b6 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
497 self.assertEqual(catalog['broken line number'].locations, [])
356
1d75228aaa33 Fixed #59 by falling back silently on invalid location comments.
aronacher
parents: 350
diff changeset
498
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
499 def suite():
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
500 suite = unittest.TestSuite()
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
501 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
502 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
503 suite.addTest(unittest.makeSuite(WritePoTestCase))
1
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
504 return suite
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
505
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
506 if __name__ == '__main__':
f71ca60f2a4a Import of initial code base.
cmlenz
parents:
diff changeset
507 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software