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@56: from babel.messages.catalog import Catalog cmlenz@54: from babel.messages import pofile cmlenz@1: cmlenz@17: palgarvio@51: class WritePotTestCase(unittest.TestCase): cmlenz@24: cmlenz@24: def test_join_locations(self): cmlenz@56: catalog = Catalog() cmlenz@56: catalog.add(u'foo', locations=[('main.py', 1)]) cmlenz@56: catalog.add(u'foo', locations=[('utils.py', 3)]) cmlenz@24: buf = StringIO() cmlenz@56: pofile.write_pot(buf, catalog, 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@56: catalog = Catalog() cmlenz@56: catalog.add(text, locations=[('main.py', 1)]) cmlenz@24: buf = StringIO() cmlenz@56: pofile.write_pot(buf, catalog, no_location=True, omit_header=True, cmlenz@56: 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@56: catalog = Catalog() cmlenz@56: catalog.add(text, locations=[('main.py', 1)]) cmlenz@24: buf = StringIO() cmlenz@56: pofile.write_pot(buf, catalog, no_location=True, omit_header=True, cmlenz@56: 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()) palgarvio@80: cmlenz@103: def test_wrap_long_lines_in_header(self): cmlenz@103: """ cmlenz@103: Verify that long lines in the header comment are wrapped correctly. cmlenz@103: """ cmlenz@103: catalog = Catalog(project='AReallyReallyLongNameForAProject') cmlenz@103: buf = StringIO() cmlenz@103: pofile.write_pot(buf, catalog) cmlenz@103: self.assertEqual('''\ cmlenz@103: # Translations template for AReallyReallyLongNameForAProject. cmlenz@103: # Copyright (C) 2007 ORGANIZATION cmlenz@103: # This file is distributed under the same license as the cmlenz@103: # AReallyReallyLongNameForAProject project. cmlenz@103: # FIRST AUTHOR , YEAR. cmlenz@103: # cmlenz@103: #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) cmlenz@103: palgarvio@80: def test_pot_with_translator_comments(self): palgarvio@80: catalog = Catalog() palgarvio@80: catalog.add(u'foo', locations=[('main.py', 1)], palgarvio@80: comments=['Comment About `foo`']) palgarvio@80: catalog.add(u'bar', locations=[('utils.py', 3)], palgarvio@80: comments=['Comment About `bar` with', palgarvio@80: 'multiple lines.']) palgarvio@80: buf = StringIO() palgarvio@80: pofile.write_pot(buf, catalog, omit_header=True) palgarvio@80: self.assertEqual('''#. Comment About `foo` palgarvio@80: #: main.py:1 palgarvio@80: msgid "foo" palgarvio@80: msgstr "" palgarvio@80: palgarvio@80: #. Comment About `bar` with palgarvio@80: #. multiple lines. palgarvio@80: #: utils.py:3 palgarvio@80: msgid "bar" palgarvio@80: msgstr ""''', buf.getvalue().strip()) cmlenz@24: cmlenz@24: cmlenz@1: def suite(): cmlenz@1: suite = unittest.TestSuite() cmlenz@1: suite.addTest(doctest.DocTestSuite(pofile)) palgarvio@51: suite.addTest(unittest.makeSuite(WritePotTestCase)) cmlenz@1: return suite cmlenz@1: cmlenz@1: if __name__ == '__main__': cmlenz@1: unittest.main(defaultTest='suite')