annotate babel/messages/tests/pofile.py @ 103:dacfbaf0d1e0 trunk

Implement wrapping of header comments in PO(T) output. Related to #14.
author cmlenz
date Wed, 13 Jun 2007 21:46:41 +0000
parents 116e34b8cefa
children 395704fda00b
rev   line source
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
1 # -*- coding: utf-8 -*-
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
2 #
12
e6ba3e878b10 * Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents: 1
diff changeset
3 # Copyright (C) 2007 Edgewall Software
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
4 # All rights reserved.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
5 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
6 # This software is licensed as described in the file COPYING, which
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
7 # you should have received as part of this distribution. The terms
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
8 # are also available at http://babel.edgewall.org/wiki/License.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
9 #
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
12 # history and logs, available at http://babel.edgewall.org/log/.
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
13
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
14 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
15 from StringIO import StringIO
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
16 import unittest
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
17
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
18 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
19 from babel.messages import pofile
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
20
17
55e22bc56f0c Recognize python-format messages also for unnamed parameters.
cmlenz
parents: 12
diff changeset
21
51
d484eb9a70d5 Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents: 24
diff changeset
22 class WritePotTestCase(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
23
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 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
25 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
26 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
27 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
28 buf = StringIO()
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
29 pofile.write_pot(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
30 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
31 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
32 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
33
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 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
35 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
36 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
37
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 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
39
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 """
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
41 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
42 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
43 buf = StringIO()
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
44 pofile.write_pot(buf, catalog, no_location=True, omit_header=True,
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
45 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
46 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
47 "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
48 "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
49 " 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
50 "\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 "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
52 "\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 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
54
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 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
56 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
57 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
58 """
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
59 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
60 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
61 buf = StringIO()
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
62 pofile.write_pot(buf, catalog, no_location=True, omit_header=True,
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
63 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
64 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
65 "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
66 "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
67 " 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
68 "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
69 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
70
103
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
71 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
72 """
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
73 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
74 """
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
75 catalog = Catalog(project='AReallyReallyLongNameForAProject')
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
76 buf = StringIO()
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
77 pofile.write_pot(buf, catalog)
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
78 self.assertEqual('''\
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
79 # Translations template for AReallyReallyLongNameForAProject.
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
80 # Copyright (C) 2007 ORGANIZATION
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
81 # 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
82 # AReallyReallyLongNameForAProject project.
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
83 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
84 #
dacfbaf0d1e0 Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents: 80
diff changeset
85 #, 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
86
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
87 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
88 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
89 catalog.add(u'foo', locations=[('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
90 comments=['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
91 catalog.add(u'bar', locations=[('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
92 comments=['Comment About `bar` with',
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 'multiple lines.'])
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
94 buf = StringIO()
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
95 pofile.write_pot(buf, catalog, omit_header=True)
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 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
97 #: 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
98 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
99 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
100
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 #. Comment About `bar` with
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 #. multiple lines.
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
103 #: 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
104 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
105 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
106
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
107
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
108 def suite():
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
109 suite = unittest.TestSuite()
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
110 suite.addTest(doctest.DocTestSuite(pofile))
51
d484eb9a70d5 Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents: 24
diff changeset
111 suite.addTest(unittest.makeSuite(WritePotTestCase))
1
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
112 return suite
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
113
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
114 if __name__ == '__main__':
7870274479f5 Import of initial code base.
cmlenz
parents:
diff changeset
115 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software