Made (make|compile)messages check for availability of gettext commands.

Refs #19584.
This commit is contained in:
Ramiro Morales 2013-02-12 16:50:47 -03:00
parent 3f43f5f3b0
commit 7fca4416c7
6 changed files with 137 additions and 70 deletions

View file

@ -131,8 +131,13 @@ class BasicExtractorTests(ExtractorTests):
os.chdir(self.test_dir)
shutil.copyfile('./code.sample', './code_sample.py')
stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, stdout=stdout)
os.remove('./code_sample.py')
try:
management.call_command('makemessages', locale=LOCALE, stdout=stdout)
finally:
try:
os.remove('./code_sample.py')
except OSError:
pass
self.assertIn("code_sample.py:4", force_text(stdout.getvalue()))
def test_template_message_context_extractor(self):

View file

@ -2,35 +2,11 @@ import os
import re
from subprocess import Popen, PIPE
from django.utils import six
from django.core.management.utils import find_command
can_run_extraction_tests = False
can_run_compilation_tests = False
def find_command(cmd, path=None, pathext=None):
if path is None:
path = os.environ.get('PATH', []).split(os.pathsep)
if isinstance(path, six.string_types):
path = [path]
# check if there are funny path extensions for executables, e.g. Windows
if pathext is None:
pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
# don't use extensions if the command ends with one of them
for ext in pathext:
if cmd.endswith(ext):
pathext = ['']
break
# check if we find the command on PATH
for p in path:
f = os.path.join(p, cmd)
if os.path.isfile(f):
return f
for ext in pathext:
fext = f + ext
if os.path.isfile(fext):
return fext
return None
# checks if it can find xgettext on the PATH and
# imports the extraction tests if yes
xgettext_cmd = find_command('xgettext')

View file

@ -1,13 +1,14 @@
import sys
from django.core import management
from django.core.management.base import CommandError
from django.test import TestCase
from django.core.management import CommandError
from django.core.management.utils import popen_wrapper
from django.test import SimpleTestCase
from django.utils import translation
from django.utils.six import StringIO
class CommandTests(TestCase):
class CommandTests(SimpleTestCase):
def test_command(self):
out = StringIO()
management.call_command('dance', stdout=out)
@ -58,3 +59,9 @@ class CommandTests(TestCase):
with translation.override('pl'):
management.call_command('leave_locale_alone_true', stdout=out)
self.assertEqual(out.getvalue(), "pl\n")
class UtilsTests(SimpleTestCase):
def test_no_existent_external_program(self):
self.assertRaises(CommandError, popen_wrapper, ['a_42_command_that_doesnt_exist_42'])