cmlenz@1: # -*- coding: utf-8 -*- cmlenz@1: # cmlenz@12: # Copyright (C) 2007 Edgewall Software cmlenz@1: # All rights reserved. cmlenz@1: # cmlenz@1: # This software is licensed as described in the file COPYING, which cmlenz@1: # you should have received as part of this distribution. The terms cmlenz@1: # are also available at http://babel.edgewall.org/wiki/License. cmlenz@1: # cmlenz@1: # This software consists of voluntary contributions made by many cmlenz@1: # individuals. For the exact contribution history, see the revision cmlenz@1: # history and logs, available at http://babel.edgewall.org/log/. cmlenz@1: cmlenz@1: import doctest cmlenz@24: from StringIO import StringIO cmlenz@1: import unittest cmlenz@1: cmlenz@1: from babel.catalog import pofile cmlenz@1: cmlenz@17: cmlenz@24: class PythonFormatFlagTestCase(unittest.TestCase): cmlenz@17: cmlenz@17: def test_without_name(self): cmlenz@17: assert pofile.PYTHON_FORMAT('foo %d bar') cmlenz@17: assert pofile.PYTHON_FORMAT('foo %s bar') cmlenz@17: assert pofile.PYTHON_FORMAT('foo %r bar') cmlenz@17: cmlenz@17: cmlenz@24: class WritePoTestCase(unittest.TestCase): cmlenz@24: cmlenz@24: def test_join_locations(self): cmlenz@24: buf = StringIO() cmlenz@24: pofile.write_po(buf, [ cmlenz@24: ('main.py', 1, None, u'foo', None), cmlenz@24: ('utils.py', 3, None, u'foo', None), cmlenz@24: ], omit_header=True) cmlenz@24: self.assertEqual('''#: main.py:1 utils.py:3 cmlenz@24: msgid "foo" cmlenz@24: msgstr ""''', buf.getvalue().strip()) cmlenz@24: cmlenz@24: def test_wrap_long_lines(self): cmlenz@24: text = """Here's some text where cmlenz@24: white space and line breaks matter, and should cmlenz@24: cmlenz@24: not be removed cmlenz@24: cmlenz@24: """ cmlenz@24: buf = StringIO() cmlenz@24: pofile.write_po(buf, [ cmlenz@24: ('main.py', 1, None, text, None), cmlenz@24: ], no_location=True, omit_header=True, width=42) cmlenz@24: self.assertEqual(r'''msgid "" cmlenz@24: "Here's some text where \n" cmlenz@24: "white space and line breaks matter, and" cmlenz@24: " should\n" cmlenz@24: "\n" cmlenz@24: "not be removed\n" cmlenz@24: "\n" cmlenz@24: msgstr ""''', buf.getvalue().strip()) cmlenz@24: cmlenz@24: def test_wrap_long_lines_with_long_word(self): cmlenz@24: text = """Here's some text that cmlenz@24: includesareallylongwordthatmightbutshouldnt throw us into an infinite loop cmlenz@24: """ cmlenz@24: buf = StringIO() cmlenz@24: pofile.write_po(buf, [ cmlenz@24: ('main.py', 1, None, text, None), cmlenz@24: ], no_location=True, omit_header=True, width=32) cmlenz@24: self.assertEqual(r'''msgid "" cmlenz@24: "Here's some text that\n" cmlenz@24: "includesareallylongwordthatmightbutshouldnt" cmlenz@24: " throw us into an infinite " cmlenz@24: "loop\n" cmlenz@24: msgstr ""''', buf.getvalue().strip()) cmlenz@24: cmlenz@24: cmlenz@1: def suite(): cmlenz@1: suite = unittest.TestSuite() cmlenz@1: suite.addTest(doctest.DocTestSuite(pofile)) cmlenz@24: suite.addTest(unittest.makeSuite(PythonFormatFlagTestCase)) cmlenz@24: suite.addTest(unittest.makeSuite(WritePoTestCase)) cmlenz@1: return suite cmlenz@1: cmlenz@1: if __name__ == '__main__': cmlenz@1: unittest.main(defaultTest='suite')