Mercurial > babel > mirror
diff babel/catalog/tests/pofile.py @ 24:b09e90803d1b trunk
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).
author | cmlenz |
---|---|
date | Fri, 01 Jun 2007 15:36:00 +0000 |
parents | 55e22bc56f0c |
children | d484eb9a70d5 |
line wrap: on
line diff
--- a/babel/catalog/tests/pofile.py +++ b/babel/catalog/tests/pofile.py @@ -12,12 +12,13 @@ # history and logs, available at http://babel.edgewall.org/log/. import doctest +from StringIO import StringIO import unittest from babel.catalog import pofile -class PythonFormatFlagUnitTest(unittest.TestCase): +class PythonFormatFlagTestCase(unittest.TestCase): def test_without_name(self): assert pofile.PYTHON_FORMAT('foo %d bar') @@ -25,10 +26,59 @@ assert pofile.PYTHON_FORMAT('foo %r bar') +class WritePoTestCase(unittest.TestCase): + + def test_join_locations(self): + buf = StringIO() + pofile.write_po(buf, [ + ('main.py', 1, None, u'foo', None), + ('utils.py', 3, None, u'foo', None), + ], omit_header=True) + self.assertEqual('''#: main.py:1 utils.py:3 +msgid "foo" +msgstr ""''', buf.getvalue().strip()) + + def test_wrap_long_lines(self): + text = """Here's some text where +white space and line breaks matter, and should + +not be removed + +""" + buf = StringIO() + pofile.write_po(buf, [ + ('main.py', 1, None, text, None), + ], no_location=True, omit_header=True, width=42) + self.assertEqual(r'''msgid "" +"Here's some text where \n" +"white space and line breaks matter, and" +" should\n" +"\n" +"not be removed\n" +"\n" +msgstr ""''', buf.getvalue().strip()) + + def test_wrap_long_lines_with_long_word(self): + text = """Here's some text that +includesareallylongwordthatmightbutshouldnt throw us into an infinite loop +""" + buf = StringIO() + pofile.write_po(buf, [ + ('main.py', 1, None, text, None), + ], no_location=True, omit_header=True, width=32) + self.assertEqual(r'''msgid "" +"Here's some text that\n" +"includesareallylongwordthatmightbutshouldnt" +" throw us into an infinite " +"loop\n" +msgstr ""''', buf.getvalue().strip()) + + def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(pofile)) - suite.addTest(unittest.makeSuite(PythonFormatFlagUnitTest)) + suite.addTest(unittest.makeSuite(PythonFormatFlagTestCase)) + suite.addTest(unittest.makeSuite(WritePoTestCase)) return suite if __name__ == '__main__':