diff options
| author | Ling-Xiao Yang <ling-xiao.yang@savoirfairelinux.com> | 2017-04-07 13:46:45 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-05-22 09:03:53 -0400 |
| commit | 04ab96ec4fa7b8ce9a006cc929c152e137ac3a77 (patch) | |
| tree | 49c7d25313f2e195d534213e178726de2b2df212 /tests | |
| parent | 3e9aa298719f19d5f09dbe0df29b6bb8d2136229 (diff) | |
Fixed #28015 -- Added makemessages --add-location option.
Thanks François Freitag for review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i18n/test_extraction.py | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py index e6945f1014..fc1c68a090 100644 --- a/tests/i18n/test_extraction.py +++ b/tests/i18n/test_extraction.py @@ -4,7 +4,7 @@ import shutil import time import warnings from io import StringIO -from unittest import mock, skipUnless +from unittest import mock, skipIf, skipUnless from admin_scripts.tests import AdminScriptTestCase @@ -23,6 +23,8 @@ from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree LOCALE = 'de' has_xgettext = find_command('xgettext') +gettext_version = MakeMessagesCommand().gettext_version if has_xgettext else None +requires_gettext_019 = skipIf(gettext_version < (0, 19), 'gettext 0.19 required') @skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests') @@ -581,6 +583,41 @@ class LocationCommentsTests(ExtractorTests): self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py') self.assertLocationCommentPresent(self.PO_FILE, 5, 'templates', 'test.html') + @requires_gettext_019 + def test_add_location_full(self): + """makemessages --add-location=full""" + management.call_command('makemessages', locale=[LOCALE], verbosity=0, add_location='full') + self.assertTrue(os.path.exists(self.PO_FILE)) + # Comment with source file relative path and line number is present. + self.assertLocationCommentPresent(self.PO_FILE, 'Translatable literal #6b', 'templates', 'test.html') + + @requires_gettext_019 + def test_add_location_file(self): + """makemessages --add-location=file""" + management.call_command('makemessages', locale=[LOCALE], verbosity=0, add_location='file') + self.assertTrue(os.path.exists(self.PO_FILE)) + # Comment with source file relative path is present. + self.assertLocationCommentPresent(self.PO_FILE, None, 'templates', 'test.html') + # But it should not contain the line number. + self.assertLocationCommentNotPresent(self.PO_FILE, 'Translatable literal #6b', 'templates', 'test.html') + + @requires_gettext_019 + def test_add_location_never(self): + """makemessages --add-location=never""" + management.call_command('makemessages', locale=[LOCALE], verbosity=0, add_location='never') + self.assertTrue(os.path.exists(self.PO_FILE)) + self.assertLocationCommentNotPresent(self.PO_FILE, None, 'test.html') + + @mock.patch('django.core.management.commands.makemessages.Command.gettext_version', new=(0, 18, 99)) + def test_add_location_gettext_version_check(self): + """ + CommandError is raised when using makemessages --add-location with + gettext < 0.19. + """ + msg = "The --add-location option requires gettext 0.19 or later. You have 0.18.99." + with self.assertRaisesMessage(CommandError, msg): + management.call_command('makemessages', locale=[LOCALE], verbosity=0, add_location='full') + class KeepPotFileExtractorTests(ExtractorTests): |
