summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-12-18 14:38:46 +0100
committerClaude Paroz <claude@2xlibre.net>2014-12-18 16:06:33 +0100
commit9bcd4d812ca698fd3a2de8c52cae8e63c261e628 (patch)
treedad9b6fc0086158b7d74922d5ec683c0be0533de
parent4a2a433e7daca1e1797b7b34d30d49ad4e09791c (diff)
Fixed #23788 (2) -- Improved gettext version checker
Thanks Tim Graham for the report and initial patch.
-rw-r--r--django/core/management/commands/makemessages.py4
-rw-r--r--tests/i18n/test_extraction.py37
2 files changed, 33 insertions, 8 deletions
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index ba8de527bf..932bc0897e 100644
--- a/django/core/management/commands/makemessages.py
+++ b/django/core/management/commands/makemessages.py
@@ -310,9 +310,9 @@ class Command(BaseCommand):
@cached_property
def gettext_version(self):
out, err, status = popen_wrapper(['xgettext', '--version'])
- m = re.search(r'(\d)\.(\d+)\.(\d+)', out)
+ m = re.search(r'(\d)\.(\d+)\.?(\d+)?', out)
if m:
- return tuple(int(d) for d in m.groups())
+ return tuple(int(d) for d in m.groups() if d is not None)
else:
raise CommandError("Unable to get gettext version. Is it installed?")
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index 705eca431e..6f8fea1bfe 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -12,9 +12,10 @@ import warnings
from django.conf import settings
from django.core import management
from django.core.management import execute_from_command_line
+from django.core.management.base import CommandError
+from django.core.management.commands.makemessages import Command as MakeMessagesCommand
from django.core.management.utils import find_command
-from django.test import SimpleTestCase
-from django.test import override_settings
+from django.test import mock, override_settings, SimpleTestCase
from django.test.utils import captured_stderr, captured_stdout
from django.utils.encoding import force_text
from django.utils._os import upath
@@ -205,8 +206,7 @@ class BasicExtractorTests(ExtractorTests):
def test_force_en_us_locale(self):
"""Value of locale-munging option used by the command is the right one"""
- from django.core.management.commands.makemessages import Command
- self.assertTrue(Command.leave_locale_alone)
+ self.assertTrue(MakeMessagesCommand.leave_locale_alone)
def test_extraction_error(self):
os.chdir(self.test_dir)
@@ -347,8 +347,7 @@ class BasicExtractorTests(ExtractorTests):
"""
Test that find_files only discover files having the proper extensions.
"""
- from django.core.management.commands.makemessages import Command
- cmd = Command()
+ cmd = MakeMessagesCommand()
cmd.ignore_patterns = ['CVS', '.*', '*~', '*.pyc']
cmd.symlinks = False
cmd.domain = 'django'
@@ -366,6 +365,32 @@ class BasicExtractorTests(ExtractorTests):
found_exts = set([os.path.splitext(tfile.file)[1] for tfile in found_files])
self.assertEqual(found_exts.difference({'.js'}), set())
+ @mock.patch('django.core.management.commands.makemessages.popen_wrapper')
+ def test_makemessages_gettext_version(self, mocked_popen_wrapper):
+ # "Normal" output:
+ mocked_popen_wrapper.return_value = (
+ "xgettext (GNU gettext-tools) 0.18.1\n"
+ "Copyright (C) 1995-1998, 2000-2010 Free Software Foundation, Inc.\n"
+ "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n"
+ "This is free software: you are free to change and redistribute it.\n"
+ "There is NO WARRANTY, to the extent permitted by law.\n"
+ "Written by Ulrich Drepper.\n", '', 0)
+ cmd = MakeMessagesCommand()
+ self.assertEqual(cmd.gettext_version, (0, 18, 1))
+
+ # Version number with only 2 parts (#23788)
+ mocked_popen_wrapper.return_value = (
+ "xgettext (GNU gettext-tools) 0.17\n", '', 0)
+ cmd = MakeMessagesCommand()
+ self.assertEqual(cmd.gettext_version, (0, 17))
+
+ # Bad version output
+ mocked_popen_wrapper.return_value = (
+ "any other return value\n", '', 0)
+ cmd = MakeMessagesCommand()
+ with six.assertRaisesRegex(self, CommandError, "Unable to get gettext version. Is it installed?"):
+ cmd.gettext_version
+
class JavascriptExtractorTests(ExtractorTests):