|
@@ -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):
|
|
|
|