comparison babel/messages/tests/pofile.py @ 56:f40fc143439c trunk

Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
author cmlenz
date Fri, 08 Jun 2007 11:08:03 +0000
parents 7dbcbc3f07e0
children 116e34b8cefa
comparison
equal deleted inserted replaced
55:a258e4015eb6 56:f40fc143439c
13 13
14 import doctest 14 import doctest
15 from StringIO import StringIO 15 from StringIO import StringIO
16 import unittest 16 import unittest
17 17
18 from babel.messages.catalog import Catalog
18 from babel.messages import pofile 19 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 20
28 21
29 class WritePotTestCase(unittest.TestCase): 22 class WritePotTestCase(unittest.TestCase):
30 23
31 def test_join_locations(self): 24 def test_join_locations(self):
25 catalog = Catalog()
26 catalog.add(u'foo', locations=[('main.py', 1)])
27 catalog.add(u'foo', locations=[('utils.py', 3)])
32 buf = StringIO() 28 buf = StringIO()
33 pofile.write_pot(buf, [ 29 pofile.write_pot(buf, catalog, omit_header=True)
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 30 self.assertEqual('''#: main.py:1 utils.py:3
38 msgid "foo" 31 msgid "foo"
39 msgstr ""''', buf.getvalue().strip()) 32 msgstr ""''', buf.getvalue().strip())
40 33
41 def test_wrap_long_lines(self): 34 def test_wrap_long_lines(self):
43 white space and line breaks matter, and should 36 white space and line breaks matter, and should
44 37
45 not be removed 38 not be removed
46 39
47 """ 40 """
41 catalog = Catalog()
42 catalog.add(text, locations=[('main.py', 1)])
48 buf = StringIO() 43 buf = StringIO()
49 pofile.write_pot(buf, [ 44 pofile.write_pot(buf, catalog, no_location=True, omit_header=True,
50 ('main.py', 1, None, text, None), 45 width=42)
51 ], no_location=True, omit_header=True, width=42)
52 self.assertEqual(r'''msgid "" 46 self.assertEqual(r'''msgid ""
53 "Here's some text where \n" 47 "Here's some text where \n"
54 "white space and line breaks matter, and" 48 "white space and line breaks matter, and"
55 " should\n" 49 " should\n"
56 "\n" 50 "\n"
60 54
61 def test_wrap_long_lines_with_long_word(self): 55 def test_wrap_long_lines_with_long_word(self):
62 text = """Here's some text that 56 text = """Here's some text that
63 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop 57 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop
64 """ 58 """
59 catalog = Catalog()
60 catalog.add(text, locations=[('main.py', 1)])
65 buf = StringIO() 61 buf = StringIO()
66 pofile.write_pot(buf, [ 62 pofile.write_pot(buf, catalog, no_location=True, omit_header=True,
67 ('main.py', 1, None, text, None), 63 width=32)
68 ], no_location=True, omit_header=True, width=32)
69 self.assertEqual(r'''msgid "" 64 self.assertEqual(r'''msgid ""
70 "Here's some text that\n" 65 "Here's some text that\n"
71 "includesareallylongwordthatmightbutshouldnt" 66 "includesareallylongwordthatmightbutshouldnt"
72 " throw us into an infinite " 67 " throw us into an infinite "
73 "loop\n" 68 "loop\n"
75 70
76 71
77 def suite(): 72 def suite():
78 suite = unittest.TestSuite() 73 suite = unittest.TestSuite()
79 suite.addTest(doctest.DocTestSuite(pofile)) 74 suite.addTest(doctest.DocTestSuite(pofile))
80 suite.addTest(unittest.makeSuite(PythonFormatFlagTestCase))
81 suite.addTest(unittest.makeSuite(WritePotTestCase)) 75 suite.addTest(unittest.makeSuite(WritePotTestCase))
82 return suite 76 return suite
83 77
84 if __name__ == '__main__': 78 if __name__ == '__main__':
85 unittest.main(defaultTest='suite') 79 unittest.main(defaultTest='suite')
Copyright (C) 2012-2017 Edgewall Software