Fixed #12910 - Only test extracting translation strings if xgettext can be found on PATH.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12475 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
7f5d9ad661
commit
8e1a4bd677
|
@ -858,6 +858,7 @@ dependencies:
|
||||||
* setuptools_
|
* setuptools_
|
||||||
* memcached_, plus the either the python-memcached_ or cmemcached_
|
* memcached_, plus the either the python-memcached_ or cmemcached_
|
||||||
Python binding
|
Python binding
|
||||||
|
* gettext_ (:ref:`gettext_on_windows`)
|
||||||
|
|
||||||
If you want to test the memcached cache backend, you will also need to define
|
If you want to test the memcached cache backend, you will also need to define
|
||||||
a :setting:`CACHE_BACKEND` setting that points at your memcached instance.
|
a :setting:`CACHE_BACKEND` setting that points at your memcached instance.
|
||||||
|
@ -873,6 +874,7 @@ associated tests will be skipped.
|
||||||
.. _memcached: http://www.danga.com/memcached/
|
.. _memcached: http://www.danga.com/memcached/
|
||||||
.. _python-memcached: http://pypi.python.org/pypi/python-memcached/
|
.. _python-memcached: http://pypi.python.org/pypi/python-memcached/
|
||||||
.. _cmemcached: http://gijsbert.org/cmemcache/index.html
|
.. _cmemcached: http://gijsbert.org/cmemcache/index.html
|
||||||
|
.. _gettext: http://www.gnu.org/software/gettext/manual/gettext.html
|
||||||
|
|
||||||
To run a subset of the unit tests, append the names of the test modules to the
|
To run a subset of the unit tests, append the names of the test modules to the
|
||||||
``runtests.py`` command line. See the list of directories in
|
``runtests.py`` command line. See the list of directories in
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
|
from django.test import TestCase
|
||||||
|
from django.core import management
|
||||||
|
|
||||||
|
LOCALE='de'
|
||||||
|
|
||||||
|
class ExtractorTests(TestCase):
|
||||||
|
|
||||||
|
PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self._cwd = os.getcwd()
|
||||||
|
self.test_dir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
def _rmrf(self, dname):
|
||||||
|
if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
|
||||||
|
return
|
||||||
|
shutil.rmtree(dname)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
try:
|
||||||
|
self._rmrf('locale/%s' % LOCALE)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
os.chdir(self._cwd)
|
||||||
|
|
||||||
|
def assertMsgId(self, msgid, s):
|
||||||
|
return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
|
||||||
|
|
||||||
|
def assertNotMsgId(self, msgid, s):
|
||||||
|
return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
|
||||||
|
|
||||||
|
|
||||||
|
class JavascriptExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
|
||||||
|
|
||||||
|
def test_javascript_literals(self):
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
|
||||||
|
self.assert_(os.path.exists(self.PO_FILE))
|
||||||
|
po_contents = open(self.PO_FILE, 'r').read()
|
||||||
|
self.assertMsgId('This literal should be included.', po_contents)
|
||||||
|
self.assertMsgId('This one as well.', po_contents)
|
||||||
|
|
||||||
|
|
||||||
|
class IgnoredExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
def test_ignore_option(self):
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*'])
|
||||||
|
self.assert_(os.path.exists(self.PO_FILE))
|
||||||
|
po_contents = open(self.PO_FILE, 'r').read()
|
||||||
|
self.assertMsgId('This literal should be included.', po_contents)
|
||||||
|
self.assertNotMsgId('This should be ignored.', po_contents)
|
||||||
|
|
||||||
|
|
||||||
|
class SymlinkExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self._cwd = os.getcwd()
|
||||||
|
self.test_dir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
super(SymlinkExtractorTests, self).tearDown()
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
try:
|
||||||
|
os.remove(self.symlinked_dir)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
os.chdir(self._cwd)
|
||||||
|
|
||||||
|
def test_symlink(self):
|
||||||
|
if hasattr(os, 'symlink'):
|
||||||
|
if os.path.exists(self.symlinked_dir):
|
||||||
|
self.assert_(os.path.islink(self.symlinked_dir))
|
||||||
|
else:
|
||||||
|
os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir)
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
|
||||||
|
self.assert_(os.path.exists(self.PO_FILE))
|
||||||
|
po_contents = open(self.PO_FILE, 'r').read()
|
||||||
|
self.assertMsgId('This literal should be included.', po_contents)
|
||||||
|
self.assert_('templates_symlinked/test.html' in po_contents)
|
||||||
|
|
||||||
|
|
||||||
|
class CopyPluralFormsExtractorTests(ExtractorTests):
|
||||||
|
|
||||||
|
def test_copy_plural_forms(self):
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
management.call_command('makemessages', locale=LOCALE, verbosity=0)
|
||||||
|
self.assert_(os.path.exists(self.PO_FILE))
|
||||||
|
po_contents = open(self.PO_FILE, 'r').read()
|
||||||
|
self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
|
|
@ -1,98 +1,30 @@
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import shutil
|
|
||||||
from django.test import TestCase
|
|
||||||
from django.core import management
|
|
||||||
|
|
||||||
LOCALE='de'
|
def find_command(cmd, path=None, pathext=None):
|
||||||
|
if path is None:
|
||||||
|
path = os.environ.get('PATH', []).split(os.pathsep)
|
||||||
|
if isinstance(path, basestring):
|
||||||
|
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
|
||||||
|
|
||||||
class ExtractorTests(TestCase):
|
# checks if it can find xgettext on the PATH and
|
||||||
|
# imports the extraction tests if yes
|
||||||
PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE
|
if find_command('xgettext'):
|
||||||
|
from extraction import *
|
||||||
def setUp(self):
|
|
||||||
self._cwd = os.getcwd()
|
|
||||||
self.test_dir = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
|
|
||||||
def _rmrf(self, dname):
|
|
||||||
if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
|
|
||||||
return
|
|
||||||
shutil.rmtree(dname)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
try:
|
|
||||||
self._rmrf('locale/%s' % LOCALE)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
os.chdir(self._cwd)
|
|
||||||
|
|
||||||
def assertMsgId(self, msgid, s):
|
|
||||||
return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
|
|
||||||
|
|
||||||
def assertNotMsgId(self, msgid, s):
|
|
||||||
return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE))
|
|
||||||
|
|
||||||
|
|
||||||
class JavascriptExtractorTests(ExtractorTests):
|
|
||||||
|
|
||||||
PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
|
|
||||||
|
|
||||||
def test_javascript_literals(self):
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
|
|
||||||
self.assert_(os.path.exists(self.PO_FILE))
|
|
||||||
po_contents = open(self.PO_FILE, 'r').read()
|
|
||||||
self.assertMsgId('This literal should be included.', po_contents)
|
|
||||||
self.assertMsgId('This one as well.', po_contents)
|
|
||||||
|
|
||||||
|
|
||||||
class IgnoredExtractorTests(ExtractorTests):
|
|
||||||
|
|
||||||
def test_ignore_option(self):
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*'])
|
|
||||||
self.assert_(os.path.exists(self.PO_FILE))
|
|
||||||
po_contents = open(self.PO_FILE, 'r').read()
|
|
||||||
self.assertMsgId('This literal should be included.', po_contents)
|
|
||||||
self.assertNotMsgId('This should be ignored.', po_contents)
|
|
||||||
|
|
||||||
|
|
||||||
class SymlinkExtractorTests(ExtractorTests):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self._cwd = os.getcwd()
|
|
||||||
self.test_dir = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
super(SymlinkExtractorTests, self).tearDown()
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
try:
|
|
||||||
os.remove(self.symlinked_dir)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
os.chdir(self._cwd)
|
|
||||||
|
|
||||||
def test_symlink(self):
|
|
||||||
if hasattr(os, 'symlink'):
|
|
||||||
if os.path.exists(self.symlinked_dir):
|
|
||||||
self.assert_(os.path.islink(self.symlinked_dir))
|
|
||||||
else:
|
|
||||||
os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir)
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
|
|
||||||
self.assert_(os.path.exists(self.PO_FILE))
|
|
||||||
po_contents = open(self.PO_FILE, 'r').read()
|
|
||||||
self.assertMsgId('This literal should be included.', po_contents)
|
|
||||||
self.assert_('templates_symlinked/test.html' in po_contents)
|
|
||||||
|
|
||||||
|
|
||||||
class CopyPluralFormsExtractorTests(ExtractorTests):
|
|
||||||
|
|
||||||
def test_copy_plural_forms(self):
|
|
||||||
os.chdir(self.test_dir)
|
|
||||||
management.call_command('makemessages', locale=LOCALE, verbosity=0)
|
|
||||||
self.assert_(os.path.exists(self.PO_FILE))
|
|
||||||
po_contents = open(self.PO_FILE, 'r').read()
|
|
||||||
self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
|
|
||||||
|
|
Loading…
Reference in New Issue