cmlenz@14: # -*- coding: utf-8 -*- cmlenz@14: # cmlenz@14: # Copyright (C) 2007 Edgewall Software cmlenz@14: # All rights reserved. cmlenz@14: # cmlenz@14: # This software is licensed as described in the file COPYING, which cmlenz@14: # you should have received as part of this distribution. The terms cmlenz@14: # are also available at http://babel.edgewall.org/wiki/License. cmlenz@14: # cmlenz@14: # This software consists of voluntary contributions made by many cmlenz@14: # individuals. For the exact contribution history, see the revision cmlenz@14: # history and logs, available at http://babel.edgewall.org/log/. cmlenz@14: cmlenz@136: from datetime import datetime cmlenz@119: from distutils.dist import Distribution cmlenz@119: from distutils.errors import DistutilsOptionError, DistutilsSetupError cmlenz@119: from distutils.log import _global_log cmlenz@14: import doctest cmlenz@119: import os cmlenz@122: import shutil cmlenz@129: from StringIO import StringIO cmlenz@129: import sys cmlenz@119: import time cmlenz@14: import unittest cmlenz@14: palgarvio@116: from babel import __version__ as VERSION cmlenz@136: from babel.dates import format_datetime cmlenz@119: from babel.messages import frontend cmlenz@136: from babel.util import LOCALTZ palgarvio@116: cmlenz@119: cmlenz@162: class CompileCatalogTestCase(unittest.TestCase): cmlenz@162: cmlenz@162: def setUp(self): cmlenz@162: self.olddir = os.getcwd() cmlenz@162: self.datadir = os.path.join(os.path.dirname(__file__), 'data') cmlenz@162: os.chdir(self.datadir) cmlenz@162: _global_log.threshold = 5 # shut up distutils logging cmlenz@162: cmlenz@162: self.dist = Distribution(dict( cmlenz@162: name='TestProject', cmlenz@162: version='0.1', cmlenz@162: packages=['project'] cmlenz@162: )) cmlenz@162: self.cmd = frontend.compile_catalog(self.dist) cmlenz@162: self.cmd.initialize_options() cmlenz@162: cmlenz@162: def tearDown(self): cmlenz@162: os.chdir(self.olddir) cmlenz@162: cmlenz@162: def test_no_directory_or_output_file_specified(self): cmlenz@162: self.cmd.locale = 'en_US' cmlenz@162: self.cmd.input_file = 'dummy' cmlenz@162: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@162: cmlenz@162: def test_no_directory_or_input_file_specified(self): cmlenz@162: self.cmd.locale = 'en_US' cmlenz@162: self.cmd.output_file = 'dummy' cmlenz@162: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@162: cmlenz@162: cmlenz@119: class ExtractMessagesTestCase(unittest.TestCase): cmlenz@119: palgarvio@116: def setUp(self): palgarvio@116: self.olddir = os.getcwd() palgarvio@116: self.datadir = os.path.join(os.path.dirname(__file__), 'data') palgarvio@116: os.chdir(self.datadir) cmlenz@119: _global_log.threshold = 5 # shut up distutils logging cmlenz@119: cmlenz@119: self.dist = Distribution(dict( cmlenz@119: name='TestProject', cmlenz@119: version='0.1', cmlenz@119: packages=['project'] cmlenz@119: )) cmlenz@119: self.cmd = frontend.extract_messages(self.dist) cmlenz@119: self.cmd.initialize_options() cmlenz@119: cmlenz@119: def tearDown(self): cmlenz@122: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@119: if os.path.isfile(pot_file): cmlenz@119: os.unlink(pot_file) cmlenz@119: cmlenz@119: os.chdir(self.olddir) cmlenz@119: cmlenz@119: def test_neither_default_nor_custom_keywords(self): cmlenz@122: self.cmd.output_file = 'dummy' cmlenz@119: self.cmd.no_default_keywords = True cmlenz@119: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@119: cmlenz@119: def test_no_output_file_specified(self): cmlenz@119: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@119: cmlenz@119: def test_both_sort_output_and_sort_by_file(self): cmlenz@122: self.cmd.output_file = 'dummy' cmlenz@119: self.cmd.sort_output = True cmlenz@119: self.cmd.sort_by_file = True cmlenz@119: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@119: cmlenz@119: def test_extraction_with_default_mapping(self): cmlenz@119: self.cmd.copyright_holder = 'FooBar, Inc.' cmlenz@119: self.cmd.msgid_bugs_address = 'bugs.address@email.tld' cmlenz@122: self.cmd.output_file = 'project/i18n/temp.pot' cmlenz@119: self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' cmlenz@119: cmlenz@119: self.cmd.finalize_options() cmlenz@119: self.cmd.run() cmlenz@122: cmlenz@122: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@122: assert os.path.isfile(pot_file) cmlenz@122: cmlenz@122: self.assertEqual( palgarvio@116: r"""# Translations template for TestProject. cmlenz@119: # Copyright (C) %(year)s FooBar, Inc. palgarvio@116: # This file is distributed under the same license as the TestProject palgarvio@116: # project. palgarvio@116: # FIRST AUTHOR , %(year)s. palgarvio@116: # palgarvio@116: #, fuzzy palgarvio@116: msgid "" palgarvio@116: msgstr "" palgarvio@116: "Project-Id-Version: TestProject 0.1\n" palgarvio@116: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" palgarvio@116: "POT-Creation-Date: %(date)s\n" palgarvio@116: "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" palgarvio@116: "Last-Translator: FULL NAME \n" palgarvio@116: "Language-Team: LANGUAGE \n" palgarvio@116: "MIME-Version: 1.0\n" palgarvio@116: "Content-Type: text/plain; charset=utf-8\n" palgarvio@116: "Content-Transfer-Encoding: 8bit\n" palgarvio@116: "Generated-By: Babel %(version)s\n" palgarvio@116: palgarvio@116: #. This will be a translator coment, palgarvio@116: #. that will include several lines palgarvio@116: #: project/file1.py:8 palgarvio@116: msgid "bar" palgarvio@116: msgstr "" palgarvio@116: palgarvio@116: #: project/file2.py:9 palgarvio@116: msgid "foobar" palgarvio@116: msgid_plural "foobars" palgarvio@116: msgstr[0] "" palgarvio@116: msgstr[1] "" palgarvio@116: palgarvio@116: #: project/CVS/this_wont_normally_be_here.py:11 palgarvio@116: msgid "FooBar" palgarvio@116: msgid_plural "FooBars" palgarvio@116: msgstr[0] "" palgarvio@116: msgstr[1] "" palgarvio@116: palgarvio@116: """ % {'version': VERSION, palgarvio@116: 'year': time.strftime('%Y'), cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@136: open(pot_file, 'U').read()) cmlenz@119: cmlenz@119: def test_extraction_with_mapping_file(self): cmlenz@119: self.cmd.copyright_holder = 'FooBar, Inc.' cmlenz@119: self.cmd.msgid_bugs_address = 'bugs.address@email.tld' cmlenz@119: self.cmd.mapping_file = 'mapping.cfg' cmlenz@122: self.cmd.output_file = 'project/i18n/temp.pot' cmlenz@119: self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' cmlenz@119: cmlenz@119: self.cmd.finalize_options() cmlenz@119: self.cmd.run() cmlenz@122: cmlenz@122: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@122: assert os.path.isfile(pot_file) cmlenz@122: cmlenz@122: self.assertEqual( palgarvio@116: r"""# Translations template for TestProject. cmlenz@119: # Copyright (C) %(year)s FooBar, Inc. palgarvio@116: # This file is distributed under the same license as the TestProject palgarvio@116: # project. palgarvio@116: # FIRST AUTHOR , %(year)s. palgarvio@116: # palgarvio@116: #, fuzzy palgarvio@116: msgid "" palgarvio@116: msgstr "" palgarvio@116: "Project-Id-Version: TestProject 0.1\n" palgarvio@116: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" palgarvio@116: "POT-Creation-Date: %(date)s\n" palgarvio@116: "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" palgarvio@116: "Last-Translator: FULL NAME \n" palgarvio@116: "Language-Team: LANGUAGE \n" palgarvio@116: "MIME-Version: 1.0\n" palgarvio@116: "Content-Type: text/plain; charset=utf-8\n" palgarvio@116: "Content-Transfer-Encoding: 8bit\n" palgarvio@116: "Generated-By: Babel %(version)s\n" palgarvio@116: palgarvio@116: #. This will be a translator coment, palgarvio@116: #. that will include several lines palgarvio@116: #: project/file1.py:8 palgarvio@116: msgid "bar" palgarvio@116: msgstr "" palgarvio@116: palgarvio@116: #: project/file2.py:9 palgarvio@116: msgid "foobar" palgarvio@116: msgid_plural "foobars" palgarvio@116: msgstr[0] "" palgarvio@116: msgstr[1] "" palgarvio@116: palgarvio@116: """ % {'version': VERSION, palgarvio@116: 'year': time.strftime('%Y'), cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@136: open(pot_file, 'U').read()) cmlenz@119: cmlenz@119: def test_extraction_with_mapping_dict(self): cmlenz@119: self.dist.message_extractors = { cmlenz@119: 'project': [ cmlenz@119: ('**/CVS/**.*', 'ignore', None), cmlenz@119: ('**.py', 'python', None), cmlenz@119: ] cmlenz@119: } cmlenz@119: self.cmd.copyright_holder = 'FooBar, Inc.' cmlenz@119: self.cmd.msgid_bugs_address = 'bugs.address@email.tld' cmlenz@122: self.cmd.output_file = 'project/i18n/temp.pot' cmlenz@119: self.cmd.add_comments = 'TRANSLATOR:,TRANSLATORS:' cmlenz@119: cmlenz@119: self.cmd.finalize_options() cmlenz@119: self.cmd.run() cmlenz@122: cmlenz@122: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@122: assert os.path.isfile(pot_file) cmlenz@122: cmlenz@122: self.assertEqual( cmlenz@119: r"""# Translations template for TestProject. cmlenz@119: # Copyright (C) %(year)s FooBar, Inc. cmlenz@119: # This file is distributed under the same license as the TestProject cmlenz@119: # project. cmlenz@119: # FIRST AUTHOR , %(year)s. cmlenz@119: # cmlenz@119: #, fuzzy cmlenz@119: msgid "" cmlenz@119: msgstr "" cmlenz@119: "Project-Id-Version: TestProject 0.1\n" cmlenz@119: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" cmlenz@119: "POT-Creation-Date: %(date)s\n" cmlenz@119: "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" cmlenz@119: "Last-Translator: FULL NAME \n" cmlenz@119: "Language-Team: LANGUAGE \n" cmlenz@119: "MIME-Version: 1.0\n" cmlenz@119: "Content-Type: text/plain; charset=utf-8\n" cmlenz@119: "Content-Transfer-Encoding: 8bit\n" cmlenz@119: "Generated-By: Babel %(version)s\n" cmlenz@119: cmlenz@119: #. This will be a translator coment, cmlenz@119: #. that will include several lines cmlenz@119: #: project/file1.py:8 cmlenz@119: msgid "bar" cmlenz@119: msgstr "" cmlenz@119: cmlenz@119: #: project/file2.py:9 cmlenz@119: msgid "foobar" cmlenz@119: msgid_plural "foobars" cmlenz@119: msgstr[0] "" cmlenz@119: msgstr[1] "" cmlenz@119: cmlenz@119: """ % {'version': VERSION, cmlenz@119: 'year': time.strftime('%Y'), cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@136: open(pot_file, 'U').read()) cmlenz@122: cmlenz@122: cmlenz@183: class InitCatalogTestCase(unittest.TestCase): cmlenz@122: cmlenz@122: def setUp(self): cmlenz@122: self.olddir = os.getcwd() cmlenz@122: self.datadir = os.path.join(os.path.dirname(__file__), 'data') cmlenz@122: os.chdir(self.datadir) cmlenz@122: _global_log.threshold = 5 # shut up distutils logging cmlenz@122: cmlenz@122: self.dist = Distribution(dict( cmlenz@122: name='TestProject', cmlenz@122: version='0.1', cmlenz@122: packages=['project'] cmlenz@122: )) cmlenz@183: self.cmd = frontend.init_catalog(self.dist) cmlenz@122: self.cmd.initialize_options() cmlenz@122: cmlenz@122: def tearDown(self): cmlenz@122: locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') cmlenz@122: if os.path.isdir(locale_dir): cmlenz@122: shutil.rmtree(locale_dir) cmlenz@122: cmlenz@122: os.chdir(self.olddir) cmlenz@122: cmlenz@122: def test_no_input_file(self): cmlenz@122: self.cmd.locale = 'en_US' cmlenz@122: self.cmd.output_file = 'dummy' cmlenz@122: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@122: cmlenz@122: def test_no_locale(self): cmlenz@122: self.cmd.input_file = 'dummy' cmlenz@122: self.cmd.output_file = 'dummy' cmlenz@122: self.assertRaises(DistutilsOptionError, self.cmd.finalize_options) cmlenz@122: cmlenz@123: def test_with_output_dir(self): cmlenz@122: self.cmd.input_file = 'project/i18n/messages.pot' cmlenz@122: self.cmd.locale = 'en_US' cmlenz@122: self.cmd.output_dir = 'project/i18n' cmlenz@122: cmlenz@122: self.cmd.finalize_options() cmlenz@122: self.cmd.run() cmlenz@122: cmlenz@122: po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', cmlenz@122: 'LC_MESSAGES', 'messages.po') cmlenz@122: assert os.path.isfile(po_file) cmlenz@122: cmlenz@122: self.assertEqual( cmlenz@122: r"""# English (United States) translations for TestProject. cmlenz@122: # Copyright (C) 2007 FooBar, Inc. cmlenz@122: # This file is distributed under the same license as the TestProject cmlenz@122: # project. cmlenz@122: # FIRST AUTHOR , 2007. cmlenz@122: # cmlenz@122: #, fuzzy cmlenz@122: msgid "" cmlenz@122: msgstr "" cmlenz@122: "Project-Id-Version: TestProject 0.1\n" cmlenz@122: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" cmlenz@122: "POT-Creation-Date: 2007-04-01 15:30+0200\n" cmlenz@122: "PO-Revision-Date: %(date)s\n" cmlenz@122: "Last-Translator: FULL NAME \n" cmlenz@122: "Language-Team: en_US \n" cmlenz@122: "Plural-Forms: nplurals=2; plural=(n != 1)\n" cmlenz@122: "MIME-Version: 1.0\n" cmlenz@122: "Content-Type: text/plain; charset=utf-8\n" cmlenz@122: "Content-Transfer-Encoding: 8bit\n" cmlenz@122: "Generated-By: Babel %(version)s\n" cmlenz@122: cmlenz@122: #. This will be a translator coment, cmlenz@122: #. that will include several lines cmlenz@122: #: project/file1.py:8 cmlenz@122: msgid "bar" cmlenz@122: msgstr "" cmlenz@122: cmlenz@122: #: project/file2.py:9 cmlenz@122: msgid "foobar" cmlenz@122: msgid_plural "foobars" cmlenz@122: msgstr[0] "" cmlenz@122: msgstr[1] "" cmlenz@122: cmlenz@122: """ % {'version': VERSION, cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@122: open(po_file, 'U').read()) cmlenz@14: cmlenz@183: cmlenz@183: class InitCatalogNonFuzzyTestCase(unittest.TestCase): cmlenz@183: # FIXME: what is this test case about? palgarvio@178: palgarvio@178: def setUp(self): palgarvio@178: self.olddir = os.getcwd() palgarvio@178: self.datadir = os.path.join(os.path.dirname(__file__), 'data') palgarvio@178: os.chdir(self.datadir) palgarvio@178: _global_log.threshold = 5 # shut up distutils logging palgarvio@178: palgarvio@178: self.dist = Distribution(dict( palgarvio@178: name='TestProject', palgarvio@178: version='0.1', palgarvio@178: packages=['project'] palgarvio@178: )) cmlenz@183: self.cmd = frontend.init_catalog(self.dist) palgarvio@178: self.cmd.initialize_options() palgarvio@178: palgarvio@178: def tearDown(self): palgarvio@178: locale_dir = os.path.join(self.datadir, 'project', 'i18n', 'en_US') palgarvio@178: if os.path.isdir(locale_dir): palgarvio@178: shutil.rmtree(locale_dir) palgarvio@178: palgarvio@178: os.chdir(self.olddir) palgarvio@178: palgarvio@178: def test_with_output_dir(self): palgarvio@178: self.cmd.input_file = 'project/i18n/messages_non_fuzzy.pot' palgarvio@178: self.cmd.locale = 'en_US' palgarvio@178: self.cmd.output_dir = 'project/i18n' palgarvio@178: palgarvio@178: self.cmd.finalize_options() palgarvio@178: self.cmd.run() palgarvio@178: palgarvio@178: po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', palgarvio@178: 'LC_MESSAGES', 'messages.po') palgarvio@178: assert os.path.isfile(po_file) palgarvio@178: palgarvio@178: self.assertEqual( palgarvio@178: r"""# English (United States) translations for TestProject. palgarvio@178: # Copyright (C) 2007 FooBar, Inc. palgarvio@178: # This file is distributed under the same license as the TestProject palgarvio@178: # project. palgarvio@178: # FIRST AUTHOR , 2007. palgarvio@178: # palgarvio@178: msgid "" palgarvio@178: msgstr "" palgarvio@178: "Project-Id-Version: TestProject 0.1\n" palgarvio@178: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" palgarvio@178: "POT-Creation-Date: 2007-04-01 15:30+0200\n" palgarvio@178: "PO-Revision-Date: %(date)s\n" palgarvio@178: "Last-Translator: FULL NAME \n" palgarvio@178: "Language-Team: en_US \n" palgarvio@178: "Plural-Forms: nplurals=2; plural=(n != 1)\n" palgarvio@178: "MIME-Version: 1.0\n" palgarvio@178: "Content-Type: text/plain; charset=utf-8\n" palgarvio@178: "Content-Transfer-Encoding: 8bit\n" palgarvio@178: "Generated-By: Babel %(version)s\n" palgarvio@178: palgarvio@178: #. This will be a translator coment, palgarvio@178: #. that will include several lines palgarvio@178: #: project/file1.py:8 palgarvio@178: msgid "bar" palgarvio@178: msgstr "" palgarvio@178: palgarvio@178: #: project/file2.py:9 palgarvio@178: msgid "foobar" palgarvio@178: msgid_plural "foobars" palgarvio@178: msgstr[0] "" palgarvio@178: msgstr[1] "" palgarvio@178: palgarvio@178: """ % {'version': VERSION, palgarvio@178: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', palgarvio@178: tzinfo=LOCALTZ, locale='en')}, palgarvio@178: open(po_file, 'U').read()) cmlenz@117: cmlenz@183: cmlenz@129: class CommandLineInterfaceTestCase(unittest.TestCase): cmlenz@129: cmlenz@129: def setUp(self): cmlenz@129: self.datadir = os.path.join(os.path.dirname(__file__), 'data') cmlenz@130: self.orig_argv = sys.argv cmlenz@129: self.orig_stdout = sys.stdout cmlenz@129: self.orig_stderr = sys.stderr cmlenz@234: sys.argv = ['pybabel'] cmlenz@129: sys.stdout = StringIO() cmlenz@129: sys.stderr = StringIO() cmlenz@129: self.cli = frontend.CommandLineInterface() cmlenz@129: cmlenz@129: def tearDown(self): cmlenz@130: sys.argv = self.orig_argv cmlenz@129: sys.stdout = self.orig_stdout cmlenz@129: sys.stderr = self.orig_stderr cmlenz@129: cmlenz@129: def test_usage(self): cmlenz@129: try: cmlenz@130: self.cli.run(sys.argv) cmlenz@129: self.fail('Expected SystemExit') cmlenz@129: except SystemExit, e: cmlenz@129: self.assertEqual(2, e.code) cmlenz@129: self.assertEqual("""\ cmlenz@234: usage: pybabel command [options] [args] cmlenz@129: cmlenz@234: pybabel: error: incorrect number of arguments cmlenz@137: """, sys.stderr.getvalue().lower()) cmlenz@129: cmlenz@129: def test_help(self): cmlenz@129: try: cmlenz@130: self.cli.run(sys.argv + ['--help']) cmlenz@129: self.fail('Expected SystemExit') cmlenz@129: except SystemExit, e: cmlenz@129: self.assertEqual(0, e.code) cmlenz@129: self.assertEqual("""\ cmlenz@234: usage: pybabel command [options] [args] cmlenz@129: cmlenz@129: options: cmlenz@187: --version show program's version number and exit cmlenz@187: -h, --help show this help message and exit cmlenz@187: --list-locales print all known locales and exit cmlenz@234: -v, --verbose print as much as possible cmlenz@234: -q, --quiet print as little as possible cmlenz@129: cmlenz@129: commands: cmlenz@187: compile compile message catalogs to mo files cmlenz@187: extract extract messages from source files and generate a pot file cmlenz@187: init create new message catalogs from a pot file cmlenz@187: update update existing message catalogs from a pot file cmlenz@137: """, sys.stdout.getvalue().lower()) cmlenz@129: cmlenz@129: def test_extract_with_default_mapping(self): cmlenz@129: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@129: try: cmlenz@130: self.cli.run(sys.argv + ['extract', cmlenz@129: '--copyright-holder', 'FooBar, Inc.', cmlenz@129: '--msgid-bugs-address', 'bugs.address@email.tld', cmlenz@129: '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', cmlenz@129: '-o', pot_file, os.path.join(self.datadir, 'project')]) cmlenz@129: except SystemExit, e: cmlenz@129: self.assertEqual(0, e.code) cmlenz@129: assert os.path.isfile(pot_file) cmlenz@129: self.assertEqual( cmlenz@129: r"""# Translations template for TestProject. cmlenz@129: # Copyright (C) %(year)s FooBar, Inc. cmlenz@129: # This file is distributed under the same license as the TestProject cmlenz@129: # project. cmlenz@129: # FIRST AUTHOR , %(year)s. cmlenz@129: # cmlenz@129: #, fuzzy cmlenz@129: msgid "" cmlenz@129: msgstr "" cmlenz@129: "Project-Id-Version: TestProject 0.1\n" cmlenz@129: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" cmlenz@129: "POT-Creation-Date: %(date)s\n" cmlenz@129: "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" cmlenz@129: "Last-Translator: FULL NAME \n" cmlenz@129: "Language-Team: LANGUAGE \n" cmlenz@129: "MIME-Version: 1.0\n" cmlenz@129: "Content-Type: text/plain; charset=utf-8\n" cmlenz@129: "Content-Transfer-Encoding: 8bit\n" cmlenz@129: "Generated-By: Babel %(version)s\n" cmlenz@129: cmlenz@129: #. This will be a translator coment, cmlenz@129: #. that will include several lines cmlenz@129: #: project/file1.py:8 cmlenz@129: msgid "bar" cmlenz@129: msgstr "" cmlenz@129: cmlenz@129: #: project/file2.py:9 cmlenz@129: msgid "foobar" cmlenz@129: msgid_plural "foobars" cmlenz@129: msgstr[0] "" cmlenz@129: msgstr[1] "" cmlenz@129: cmlenz@129: #: project/CVS/this_wont_normally_be_here.py:11 cmlenz@129: msgid "FooBar" cmlenz@129: msgid_plural "FooBars" cmlenz@129: msgstr[0] "" cmlenz@129: msgstr[1] "" cmlenz@129: cmlenz@129: """ % {'version': VERSION, cmlenz@129: 'year': time.strftime('%Y'), cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@136: open(pot_file, 'U').read()) cmlenz@129: cmlenz@129: def test_extract_with_mapping_file(self): cmlenz@129: pot_file = os.path.join(self.datadir, 'project', 'i18n', 'temp.pot') cmlenz@129: try: cmlenz@130: self.cli.run(sys.argv + ['extract', cmlenz@129: '--copyright-holder', 'FooBar, Inc.', cmlenz@129: '--msgid-bugs-address', 'bugs.address@email.tld', cmlenz@129: '--mapping', os.path.join(self.datadir, 'mapping.cfg'), cmlenz@129: '-c', 'TRANSLATOR', '-c', 'TRANSLATORS:', cmlenz@129: '-o', pot_file, os.path.join(self.datadir, 'project')]) cmlenz@129: except SystemExit, e: cmlenz@129: self.assertEqual(0, e.code) cmlenz@129: assert os.path.isfile(pot_file) cmlenz@129: self.assertEqual( cmlenz@129: r"""# Translations template for TestProject. cmlenz@129: # Copyright (C) %(year)s FooBar, Inc. cmlenz@129: # This file is distributed under the same license as the TestProject cmlenz@129: # project. cmlenz@129: # FIRST AUTHOR , %(year)s. cmlenz@129: # cmlenz@129: #, fuzzy cmlenz@129: msgid "" cmlenz@129: msgstr "" cmlenz@129: "Project-Id-Version: TestProject 0.1\n" cmlenz@129: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" cmlenz@129: "POT-Creation-Date: %(date)s\n" cmlenz@129: "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" cmlenz@129: "Last-Translator: FULL NAME \n" cmlenz@129: "Language-Team: LANGUAGE \n" cmlenz@129: "MIME-Version: 1.0\n" cmlenz@129: "Content-Type: text/plain; charset=utf-8\n" cmlenz@129: "Content-Transfer-Encoding: 8bit\n" cmlenz@129: "Generated-By: Babel %(version)s\n" cmlenz@129: cmlenz@129: #. This will be a translator coment, cmlenz@129: #. that will include several lines cmlenz@129: #: project/file1.py:8 cmlenz@129: msgid "bar" cmlenz@129: msgstr "" cmlenz@129: cmlenz@129: #: project/file2.py:9 cmlenz@129: msgid "foobar" cmlenz@129: msgid_plural "foobars" cmlenz@129: msgstr[0] "" cmlenz@129: msgstr[1] "" cmlenz@129: cmlenz@129: """ % {'version': VERSION, cmlenz@129: 'year': time.strftime('%Y'), cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@136: open(pot_file, 'U').read()) cmlenz@129: cmlenz@129: def test_init_with_output_dir(self): cmlenz@129: po_file = os.path.join(self.datadir, 'project', 'i18n', 'en_US', cmlenz@129: 'LC_MESSAGES', 'messages.po') cmlenz@129: try: cmlenz@130: self.cli.run(sys.argv + ['init', cmlenz@129: '--locale', 'en_US', cmlenz@129: '-d', os.path.join(self.datadir, 'project', 'i18n'), cmlenz@129: '-i', os.path.join(self.datadir, 'project', 'i18n', cmlenz@129: 'messages.pot')]) cmlenz@129: except SystemExit, e: cmlenz@129: self.assertEqual(0, e.code) pjenvey@173: assert os.path.isfile(po_file) cmlenz@129: self.assertEqual( cmlenz@129: r"""# English (United States) translations for TestProject. cmlenz@129: # Copyright (C) 2007 FooBar, Inc. cmlenz@129: # This file is distributed under the same license as the TestProject cmlenz@129: # project. cmlenz@129: # FIRST AUTHOR , 2007. cmlenz@129: # cmlenz@129: #, fuzzy cmlenz@129: msgid "" cmlenz@129: msgstr "" cmlenz@129: "Project-Id-Version: TestProject 0.1\n" cmlenz@129: "Report-Msgid-Bugs-To: bugs.address@email.tld\n" cmlenz@129: "POT-Creation-Date: 2007-04-01 15:30+0200\n" cmlenz@129: "PO-Revision-Date: %(date)s\n" cmlenz@129: "Last-Translator: FULL NAME \n" cmlenz@129: "Language-Team: en_US \n" cmlenz@129: "Plural-Forms: nplurals=2; plural=(n != 1)\n" cmlenz@129: "MIME-Version: 1.0\n" cmlenz@129: "Content-Type: text/plain; charset=utf-8\n" cmlenz@129: "Content-Transfer-Encoding: 8bit\n" cmlenz@129: "Generated-By: Babel %(version)s\n" cmlenz@129: cmlenz@129: #. This will be a translator coment, cmlenz@129: #. that will include several lines cmlenz@129: #: project/file1.py:8 cmlenz@129: msgid "bar" cmlenz@129: msgstr "" cmlenz@129: cmlenz@129: #: project/file2.py:9 cmlenz@129: msgid "foobar" cmlenz@129: msgid_plural "foobars" cmlenz@129: msgstr[0] "" cmlenz@129: msgstr[1] "" cmlenz@129: cmlenz@129: """ % {'version': VERSION, cmlenz@136: 'date': format_datetime(datetime.now(LOCALTZ), 'yyyy-MM-dd HH:mmZ', cmlenz@136: tzinfo=LOCALTZ, locale='en')}, cmlenz@129: open(po_file, 'U').read()) cmlenz@179: palgarvio@178: def test_compile_catalog(self): cmlenz@234: po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', palgarvio@178: 'LC_MESSAGES', 'messages.po') cmlenz@234: mo_file = po_file.replace('.po', '.mo') cmlenz@234: self.cli.run(sys.argv + ['compile', cmlenz@234: '--locale', 'de_DE', cmlenz@234: '-d', os.path.join(self.datadir, 'project', 'i18n')]) cmlenz@234: assert not os.path.isfile(mo_file), 'Expected no file at %r' % mo_file cmlenz@234: self.assertEqual("""\ cmlenz@234: catalog %r is marked as fuzzy, skipping cmlenz@234: """ % (po_file), sys.stderr.getvalue()) cmlenz@234: cmlenz@234: def test_compile_fuzzy_catalog(self): cmlenz@234: po_file = os.path.join(self.datadir, 'project', 'i18n', 'de_DE', cmlenz@234: 'LC_MESSAGES', 'messages.po') cmlenz@234: mo_file = po_file.replace('.po', '.mo') palgarvio@178: try: palgarvio@178: self.cli.run(sys.argv + ['compile', cmlenz@234: '--locale', 'de_DE', '--use-fuzzy', palgarvio@178: '-d', os.path.join(self.datadir, 'project', 'i18n')]) cmlenz@234: assert os.path.isfile(mo_file) palgarvio@178: self.assertEqual("""\ cmlenz@179: compiling catalog %r to %r cmlenz@234: """ % (po_file, mo_file), sys.stderr.getvalue()) cmlenz@234: finally: cmlenz@234: if os.path.isfile(mo_file): cmlenz@234: os.unlink(mo_file) cmlenz@129: cmlenz@179: cmlenz@14: def suite(): cmlenz@14: suite = unittest.TestSuite() cmlenz@14: suite.addTest(doctest.DocTestSuite(frontend)) cmlenz@162: suite.addTest(unittest.makeSuite(CompileCatalogTestCase)) cmlenz@119: suite.addTest(unittest.makeSuite(ExtractMessagesTestCase)) cmlenz@183: suite.addTest(unittest.makeSuite(InitCatalogTestCase)) cmlenz@183: suite.addTest(unittest.makeSuite(InitCatalogNonFuzzyTestCase)) cmlenz@129: suite.addTest(unittest.makeSuite(CommandLineInterfaceTestCase)) cmlenz@14: return suite cmlenz@14: cmlenz@14: if __name__ == '__main__': cmlenz@14: unittest.main(defaultTest='suite')