Mercurial > babel > old > babel-test
annotate babel/messages/tests/pofile.py @ 181:9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
author | cmlenz |
---|---|
date | Thu, 28 Jun 2007 10:28:25 +0000 |
parents | 3c4718fb7435 |
children | 84193e6612f8 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
12
a2c54ef107c2
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
1
diff
changeset
|
3 # Copyright (C) 2007 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 |
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 |
1 | 21 |
17
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
22 |
106
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
23 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
|
24 |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
25 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
|
26 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
|
27 "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
|
28 "includesareallylongwordthatmightbutshouldnt" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
29 " 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
|
30 "loop\n" |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
31 msgstr ""''') |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 "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
|
37 message.id) |
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
|
38 |
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
|
39 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
|
40 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
|
41 # 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
|
42 # 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
|
43 # 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
|
44 # 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
|
45 # 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
|
46 # |
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
|
47 #, 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
|
48 ''') |
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
|
49 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
|
50 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
|
51 self.assertEqual(True, list(catalog)[0].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
|
52 |
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_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
|
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 ''') |
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(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
|
65 |
9b22b36066f6
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
105
diff
changeset
|
66 |
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
|
67 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
|
68 |
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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 |
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
|
79 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
|
80 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
|
81 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
|
82 |
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
|
83 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
|
84 |
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
|
85 """ |
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
|
86 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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 "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
|
93 "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
|
94 " 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
|
95 "\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
|
96 "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
|
97 "\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
|
98 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
|
99 |
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
|
100 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
|
101 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
|
102 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
|
103 """ |
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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 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
|
110 "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
|
111 "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
|
112 " 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
|
113 "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
|
114 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
|
115 |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
116 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
|
117 """ |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
118 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
|
119 """ |
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
|
120 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
|
121 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
|
122 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
|
123 pofile.write_po(buf, catalog) |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
124 self.assertEqual('''\ |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
125 # Translations template for AReallyReallyLongNameForAProject. |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
126 # Copyright (C) 2007 ORGANIZATION |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
127 # 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
|
128 # 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
|
129 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
103
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
130 # |
7cdf89eb9007
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
131 #, 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
|
132 |
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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 '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
|
140 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
|
141 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
|
142 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
|
143 #: 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
|
144 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
|
145 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
|
146 |
105
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
147 # Comment About `bar` with |
f744dd56573d
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
148 # 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
|
149 #: 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
|
150 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
|
151 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
|
152 |
181
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
153 def test_po_with_obsolete_messages(self): |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
154 catalog = Catalog() |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
155 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
|
156 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
|
157 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
|
158 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
|
159 buf = StringIO() |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
160 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
|
161 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
|
162 msgid "foo" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
163 msgstr "Voh" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
164 |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
165 # User comment |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
166 #~ msgid "bar" |
9a1acb41e7dd
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
175
diff
changeset
|
167 #~ 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
|
168 |
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
|
169 |
1 | 170 def suite(): |
171 suite = unittest.TestSuite() | |
172 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
|
173 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
|
174 suite.addTest(unittest.makeSuite(WritePoTestCase)) |
1 | 175 return suite |
176 | |
177 if __name__ == '__main__': | |
178 unittest.main(defaultTest='suite') |