Mercurial > babel > mirror
comparison babel/messages/tests/pofile.py @ 54:7dbcbc3f07e0 trunk
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@d484eb9a70d5 |
children | f40fc143439c |
comparison
equal
deleted
inserted
replaced
53:e4711b804df7 | 54:7dbcbc3f07e0 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 # | |
3 # Copyright (C) 2007 Edgewall Software | |
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 | |
15 from StringIO import StringIO | |
16 import unittest | |
17 | |
18 from babel.messages import pofile | |
19 | |
20 | |
21 class PythonFormatFlagTestCase(unittest.TestCase): | |
22 | |
23 def test_without_name(self): | |
24 assert pofile.PYTHON_FORMAT('foo %d bar') | |
25 assert pofile.PYTHON_FORMAT('foo %s bar') | |
26 assert pofile.PYTHON_FORMAT('foo %r bar') | |
27 | |
28 | |
29 class WritePotTestCase(unittest.TestCase): | |
30 | |
31 def test_join_locations(self): | |
32 buf = StringIO() | |
33 pofile.write_pot(buf, [ | |
34 ('main.py', 1, None, u'foo', None), | |
35 ('utils.py', 3, None, u'foo', None), | |
36 ], omit_header=True) | |
37 self.assertEqual('''#: main.py:1 utils.py:3 | |
38 msgid "foo" | |
39 msgstr ""''', buf.getvalue().strip()) | |
40 | |
41 def test_wrap_long_lines(self): | |
42 text = """Here's some text where | |
43 white space and line breaks matter, and should | |
44 | |
45 not be removed | |
46 | |
47 """ | |
48 buf = StringIO() | |
49 pofile.write_pot(buf, [ | |
50 ('main.py', 1, None, text, None), | |
51 ], no_location=True, omit_header=True, width=42) | |
52 self.assertEqual(r'''msgid "" | |
53 "Here's some text where \n" | |
54 "white space and line breaks matter, and" | |
55 " should\n" | |
56 "\n" | |
57 "not be removed\n" | |
58 "\n" | |
59 msgstr ""''', buf.getvalue().strip()) | |
60 | |
61 def test_wrap_long_lines_with_long_word(self): | |
62 text = """Here's some text that | |
63 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop | |
64 """ | |
65 buf = StringIO() | |
66 pofile.write_pot(buf, [ | |
67 ('main.py', 1, None, text, None), | |
68 ], no_location=True, omit_header=True, width=32) | |
69 self.assertEqual(r'''msgid "" | |
70 "Here's some text that\n" | |
71 "includesareallylongwordthatmightbutshouldnt" | |
72 " throw us into an infinite " | |
73 "loop\n" | |
74 msgstr ""''', buf.getvalue().strip()) | |
75 | |
76 | |
77 def suite(): | |
78 suite = unittest.TestSuite() | |
79 suite.addTest(doctest.DocTestSuite(pofile)) | |
80 suite.addTest(unittest.makeSuite(PythonFormatFlagTestCase)) | |
81 suite.addTest(unittest.makeSuite(WritePotTestCase)) | |
82 return suite | |
83 | |
84 if __name__ == '__main__': | |
85 unittest.main(defaultTest='suite') |