Mercurial > babel > mirror
annotate babel/messages/tests/pofile.py @ 105:c62b68a0b65e trunk
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
The `Generated-By` header value needed a missing `\n`.
The frontends now pass the value of `--copyright-holder` to the Catalog, and removed the `copyright_holder` arg for `write_po` left behind on [105].
Tests changed accordingly.
author | palgarvio |
---|---|
date | Thu, 14 Jun 2007 06:24:28 +0000 |
parents | 395704fda00b |
children | 2cd83f77cc98 |
rev | line source |
---|---|
1 | 1 # -*- coding: utf-8 -*- |
2 # | |
12
e6ba3e878b10
* 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
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
14 from datetime import datetime |
1 | 15 import doctest |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
16 from StringIO import StringIO |
1 | 17 import unittest |
18 | |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
19 from babel.messages.catalog import Catalog |
54
7dbcbc3f07e0
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
51
diff
changeset
|
20 from babel.messages import pofile |
1 | 21 |
17
55e22bc56f0c
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
22 |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
23 class WritePoTestCase(unittest.TestCase): |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
24 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
25 def test_join_locations(self): |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
26 catalog = Catalog() |
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
27 catalog.add(u'foo', locations=[('main.py', 1)]) |
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
28 catalog.add(u'foo', locations=[('utils.py', 3)]) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
29 buf = StringIO() |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
30 pofile.write_po(buf, catalog, omit_header=True) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
31 self.assertEqual('''#: main.py:1 utils.py:3 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
32 msgid "foo" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
33 msgstr ""''', buf.getvalue().strip()) |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
34 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
35 def test_wrap_long_lines(self): |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
36 text = """Here's some text where |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
37 white space and line breaks matter, and should |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
38 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
39 not be removed |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
40 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
41 """ |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
42 catalog = Catalog() |
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
43 catalog.add(text, locations=[('main.py', 1)]) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
44 buf = StringIO() |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
45 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
46 width=42) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
47 self.assertEqual(r'''msgid "" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
48 "Here's some text where \n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
49 "white space and line breaks matter, and" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
50 " should\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
51 "\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
52 "not be removed\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
53 "\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
54 msgstr ""''', buf.getvalue().strip()) |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
55 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
56 def test_wrap_long_lines_with_long_word(self): |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
57 text = """Here's some text that |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
58 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
59 """ |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
60 catalog = Catalog() |
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
61 catalog.add(text, locations=[('main.py', 1)]) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
62 buf = StringIO() |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
63 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
56
f40fc143439c
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
54
diff
changeset
|
64 width=32) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
65 self.assertEqual(r'''msgid "" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
66 "Here's some text that\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
67 "includesareallylongwordthatmightbutshouldnt" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
68 " throw us into an infinite " |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
69 "loop\n" |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
70 msgstr ""''', buf.getvalue().strip()) |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
71 |
103
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
72 def test_wrap_long_lines_in_header(self): |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
73 """ |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
74 Verify that long lines in the header comment are wrapped correctly. |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
75 """ |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
76 catalog = Catalog(project='AReallyReallyLongNameForAProject', |
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
77 revision_date=datetime(2007, 4, 1)) |
103
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
78 buf = StringIO() |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
79 pofile.write_po(buf, catalog) |
103
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
80 self.assertEqual('''\ |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
81 # Translations template for AReallyReallyLongNameForAProject. |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
82 # Copyright (C) 2007 ORGANIZATION |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
83 # This file is distributed under the same license as the |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
84 # AReallyReallyLongNameForAProject project. |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
85 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
103
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
86 # |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
87 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) |
dacfbaf0d1e0
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
80
diff
changeset
|
88 |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
89 def test_pot_with_translator_comments(self): |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
90 catalog = Catalog() |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
91 catalog.add(u'foo', locations=[('main.py', 1)], |
105
c62b68a0b65e
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
92 auto_comments=['Comment About `foo`']) |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
93 catalog.add(u'bar', locations=[('utils.py', 3)], |
105
c62b68a0b65e
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
94 user_comments=['Comment About `bar` with', |
c62b68a0b65e
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
95 'multiple lines.']) |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
96 buf = StringIO() |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
97 pofile.write_po(buf, catalog, omit_header=True) |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
98 self.assertEqual('''#. Comment About `foo` |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
99 #: main.py:1 |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
100 msgid "foo" |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
101 msgstr "" |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
102 |
105
c62b68a0b65e
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
103 # Comment About `bar` with |
c62b68a0b65e
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
104
diff
changeset
|
104 # multiple lines. |
80
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
105 #: utils.py:3 |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
106 msgid "bar" |
116e34b8cefa
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
56
diff
changeset
|
107 msgstr ""''', buf.getvalue().strip()) |
24
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
108 |
b09e90803d1b
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
17
diff
changeset
|
109 |
1 | 110 def suite(): |
111 suite = unittest.TestSuite() | |
112 suite.addTest(doctest.DocTestSuite(pofile)) | |
104
395704fda00b
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
103
diff
changeset
|
113 suite.addTest(unittest.makeSuite(WritePoTestCase)) |
1 | 114 return suite |
115 | |
116 if __name__ == '__main__': | |
117 unittest.main(defaultTest='suite') |