Mercurial > babel > old > babel-test
annotate babel/messages/tests/pofile.py @ 54:b3395b285104
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
author | cmlenz |
---|---|
date | Fri, 08 Jun 2007 09:16:32 +0000 |
parents | babel/catalog/tests/pofile.py@7f61453c1bea |
children | 27fba894d3ca |
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 | |
14 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
|
15 from StringIO import StringIO |
1 | 16 import unittest |
17 | |
54
b3395b285104
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
51
diff
changeset
|
18 from babel.messages import pofile |
1 | 19 |
17
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
20 |
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
|
21 class PythonFormatFlagTestCase(unittest.TestCase): |
17
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
22 |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
23 def test_without_name(self): |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
24 assert pofile.PYTHON_FORMAT('foo %d bar') |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
25 assert pofile.PYTHON_FORMAT('foo %s bar') |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
26 assert pofile.PYTHON_FORMAT('foo %r bar') |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
27 |
6aa4c4df8871
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
12
diff
changeset
|
28 |
51
7f61453c1bea
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
24
diff
changeset
|
29 class WritePotTestCase(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
|
30 |
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
|
31 def test_join_locations(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
|
32 buf = StringIO() |
51
7f61453c1bea
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
24
diff
changeset
|
33 pofile.write_pot(buf, [ |
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
|
34 ('main.py', 1, None, u'foo', None), |
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
|
35 ('utils.py', 3, None, u'foo', None), |
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
|
36 ], omit_header=True) |
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
|
37 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
|
38 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
|
39 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
|
40 |
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
|
41 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
|
42 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
|
43 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
|
44 |
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
|
45 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
|
46 |
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
|
47 """ |
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
|
48 buf = StringIO() |
51
7f61453c1bea
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
24
diff
changeset
|
49 pofile.write_pot(buf, [ |
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
|
50 ('main.py', 1, None, text, None), |
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
|
51 ], no_location=True, omit_header=True, width=42) |
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
|
52 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
|
53 "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
|
54 "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
|
55 " 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
|
56 "\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
|
57 "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
|
58 "\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
|
59 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
|
60 |
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
|
61 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
|
62 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
|
63 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
|
64 """ |
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
|
65 buf = StringIO() |
51
7f61453c1bea
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
24
diff
changeset
|
66 pofile.write_pot(buf, [ |
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
|
67 ('main.py', 1, None, text, None), |
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 ], no_location=True, omit_header=True, width=32) |
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 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
|
70 "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
|
71 "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
|
72 " 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
|
73 "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
|
74 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
|
75 |
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 |
1 | 77 def suite(): |
78 suite = unittest.TestSuite() | |
79 suite.addTest(doctest.DocTestSuite(pofile)) | |
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
|
80 suite.addTest(unittest.makeSuite(PythonFormatFlagTestCase)) |
51
7f61453c1bea
Fixed a bug regarding plural msgid's handling when writing the `.pot` file.
palgarvio
parents:
24
diff
changeset
|
81 suite.addTest(unittest.makeSuite(WritePotTestCase)) |
1 | 82 return suite |
83 | |
84 if __name__ == '__main__': | |
85 unittest.main(defaultTest='suite') |