Mercurial > babel > mirror
comparison babel/messages/tests/pofile.py @ 104:395704fda00b trunk
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.
author | cmlenz |
---|---|
date | Wed, 13 Jun 2007 23:02:24 +0000 |
parents | dacfbaf0d1e0 |
children | c62b68a0b65e |
comparison
equal
deleted
inserted
replaced
103:dacfbaf0d1e0 | 104:395704fda00b |
---|---|
9 # | 9 # |
10 # This software consists of voluntary contributions made by many | 10 # This software consists of voluntary contributions made by many |
11 # individuals. For the exact contribution history, see the revision | 11 # individuals. For the exact contribution history, see the revision |
12 # history and logs, available at http://babel.edgewall.org/log/. | 12 # history and logs, available at http://babel.edgewall.org/log/. |
13 | 13 |
14 from datetime import datetime | |
14 import doctest | 15 import doctest |
15 from StringIO import StringIO | 16 from StringIO import StringIO |
16 import unittest | 17 import unittest |
17 | 18 |
18 from babel.messages.catalog import Catalog | 19 from babel.messages.catalog import Catalog |
19 from babel.messages import pofile | 20 from babel.messages import pofile |
20 | 21 |
21 | 22 |
22 class WritePotTestCase(unittest.TestCase): | 23 class WritePoTestCase(unittest.TestCase): |
23 | 24 |
24 def test_join_locations(self): | 25 def test_join_locations(self): |
25 catalog = Catalog() | 26 catalog = Catalog() |
26 catalog.add(u'foo', locations=[('main.py', 1)]) | 27 catalog.add(u'foo', locations=[('main.py', 1)]) |
27 catalog.add(u'foo', locations=[('utils.py', 3)]) | 28 catalog.add(u'foo', locations=[('utils.py', 3)]) |
28 buf = StringIO() | 29 buf = StringIO() |
29 pofile.write_pot(buf, catalog, omit_header=True) | 30 pofile.write_po(buf, catalog, omit_header=True) |
30 self.assertEqual('''#: main.py:1 utils.py:3 | 31 self.assertEqual('''#: main.py:1 utils.py:3 |
31 msgid "foo" | 32 msgid "foo" |
32 msgstr ""''', buf.getvalue().strip()) | 33 msgstr ""''', buf.getvalue().strip()) |
33 | 34 |
34 def test_wrap_long_lines(self): | 35 def test_wrap_long_lines(self): |
39 | 40 |
40 """ | 41 """ |
41 catalog = Catalog() | 42 catalog = Catalog() |
42 catalog.add(text, locations=[('main.py', 1)]) | 43 catalog.add(text, locations=[('main.py', 1)]) |
43 buf = StringIO() | 44 buf = StringIO() |
44 pofile.write_pot(buf, catalog, no_location=True, omit_header=True, | 45 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
45 width=42) | 46 width=42) |
46 self.assertEqual(r'''msgid "" | 47 self.assertEqual(r'''msgid "" |
47 "Here's some text where \n" | 48 "Here's some text where \n" |
48 "white space and line breaks matter, and" | 49 "white space and line breaks matter, and" |
49 " should\n" | 50 " should\n" |
57 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop | 58 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop |
58 """ | 59 """ |
59 catalog = Catalog() | 60 catalog = Catalog() |
60 catalog.add(text, locations=[('main.py', 1)]) | 61 catalog.add(text, locations=[('main.py', 1)]) |
61 buf = StringIO() | 62 buf = StringIO() |
62 pofile.write_pot(buf, catalog, no_location=True, omit_header=True, | 63 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
63 width=32) | 64 width=32) |
64 self.assertEqual(r'''msgid "" | 65 self.assertEqual(r'''msgid "" |
65 "Here's some text that\n" | 66 "Here's some text that\n" |
66 "includesareallylongwordthatmightbutshouldnt" | 67 "includesareallylongwordthatmightbutshouldnt" |
67 " throw us into an infinite " | 68 " throw us into an infinite " |
70 | 71 |
71 def test_wrap_long_lines_in_header(self): | 72 def test_wrap_long_lines_in_header(self): |
72 """ | 73 """ |
73 Verify that long lines in the header comment are wrapped correctly. | 74 Verify that long lines in the header comment are wrapped correctly. |
74 """ | 75 """ |
75 catalog = Catalog(project='AReallyReallyLongNameForAProject') | 76 catalog = Catalog(project='AReallyReallyLongNameForAProject', |
77 revision_date=datetime(2007, 4, 1)) | |
76 buf = StringIO() | 78 buf = StringIO() |
77 pofile.write_pot(buf, catalog) | 79 pofile.write_po(buf, catalog) |
78 self.assertEqual('''\ | 80 self.assertEqual('''\ |
79 # Translations template for AReallyReallyLongNameForAProject. | 81 # Translations template for AReallyReallyLongNameForAProject. |
80 # Copyright (C) 2007 ORGANIZATION | 82 # Copyright (C) 2007 ORGANIZATION |
81 # This file is distributed under the same license as the | 83 # This file is distributed under the same license as the |
82 # AReallyReallyLongNameForAProject project. | 84 # AReallyReallyLongNameForAProject project. |
83 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. | 85 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
84 # | 86 # |
85 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) | 87 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) |
86 | 88 |
87 def test_pot_with_translator_comments(self): | 89 def test_pot_with_translator_comments(self): |
88 catalog = Catalog() | 90 catalog = Catalog() |
90 comments=['Comment About `foo`']) | 92 comments=['Comment About `foo`']) |
91 catalog.add(u'bar', locations=[('utils.py', 3)], | 93 catalog.add(u'bar', locations=[('utils.py', 3)], |
92 comments=['Comment About `bar` with', | 94 comments=['Comment About `bar` with', |
93 'multiple lines.']) | 95 'multiple lines.']) |
94 buf = StringIO() | 96 buf = StringIO() |
95 pofile.write_pot(buf, catalog, omit_header=True) | 97 pofile.write_po(buf, catalog, omit_header=True) |
96 self.assertEqual('''#. Comment About `foo` | 98 self.assertEqual('''#. Comment About `foo` |
97 #: main.py:1 | 99 #: main.py:1 |
98 msgid "foo" | 100 msgid "foo" |
99 msgstr "" | 101 msgstr "" |
100 | 102 |
106 | 108 |
107 | 109 |
108 def suite(): | 110 def suite(): |
109 suite = unittest.TestSuite() | 111 suite = unittest.TestSuite() |
110 suite.addTest(doctest.DocTestSuite(pofile)) | 112 suite.addTest(doctest.DocTestSuite(pofile)) |
111 suite.addTest(unittest.makeSuite(WritePotTestCase)) | 113 suite.addTest(unittest.makeSuite(WritePoTestCase)) |
112 return suite | 114 return suite |
113 | 115 |
114 if __name__ == '__main__': | 116 if __name__ == '__main__': |
115 unittest.main(defaultTest='suite') | 117 unittest.main(defaultTest='suite') |