Ticket #12910: 12910.1.diff
File 12910.1.diff, 9.3 KB (added by , 15 years ago) |
---|
-
docs/internals/contributing.txt
diff --git a/docs/internals/contributing.txt b/docs/internals/contributing.txt index a257e67..8258c5e 100644
a b dependencies: 858 858 * setuptools_ 859 859 * memcached_, plus the either the python-memcached_ or cmemcached_ 860 860 Python binding 861 * gettext_ (:ref:`gettext_on_windows`) 861 862 862 863 If you want to test the memcached cache backend, you will also need to define 863 864 a :setting:`CACHE_BACKEND` setting that points at your memcached instance. … … associated tests will be skipped. 873 874 .. _memcached: http://www.danga.com/memcached/ 874 875 .. _python-memcached: http://pypi.python.org/pypi/python-memcached/ 875 876 .. _cmemcached: http://gijsbert.org/cmemcache/index.html 877 .. _gettext: http://www.gnu.org/software/gettext/manual/gettext.html 876 878 877 879 To run a subset of the unit tests, append the names of the test modules to the 878 880 ``runtests.py`` command line. See the list of directories in -
new file tests/regressiontests/makemessages/extraction.py
diff --git a/tests/regressiontests/makemessages/extraction.py b/tests/regressiontests/makemessages/extraction.py new file mode 100644 index 0000000..4b4fa1b
- + 1 import os 2 import re 3 import shutil 4 from django.test import TestCase 5 from django.core import management 6 7 LOCALE='de' 8 9 class ExtractorTests(TestCase): 10 11 PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE 12 13 def setUp(self): 14 self._cwd = os.getcwd() 15 self.test_dir = os.path.abspath(os.path.dirname(__file__)) 16 17 def _rmrf(self, dname): 18 if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir: 19 return 20 shutil.rmtree(dname) 21 22 def tearDown(self): 23 os.chdir(self.test_dir) 24 try: 25 self._rmrf('locale/%s' % LOCALE) 26 except OSError: 27 pass 28 os.chdir(self._cwd) 29 30 def assertMsgId(self, msgid, s): 31 return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE)) 32 33 def assertNotMsgId(self, msgid, s): 34 return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE)) 35 36 37 class JavascriptExtractorTests(ExtractorTests): 38 39 PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE 40 41 def test_javascript_literals(self): 42 os.chdir(self.test_dir) 43 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 44 self.assert_(os.path.exists(self.PO_FILE)) 45 po_contents = open(self.PO_FILE, 'r').read() 46 self.assertMsgId('This literal should be included.', po_contents) 47 self.assertMsgId('This one as well.', po_contents) 48 49 50 class IgnoredExtractorTests(ExtractorTests): 51 52 def test_ignore_option(self): 53 os.chdir(self.test_dir) 54 management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*']) 55 self.assert_(os.path.exists(self.PO_FILE)) 56 po_contents = open(self.PO_FILE, 'r').read() 57 self.assertMsgId('This literal should be included.', po_contents) 58 self.assertNotMsgId('This should be ignored.', po_contents) 59 60 61 class SymlinkExtractorTests(ExtractorTests): 62 63 def setUp(self): 64 self._cwd = os.getcwd() 65 self.test_dir = os.path.abspath(os.path.dirname(__file__)) 66 self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked') 67 68 def tearDown(self): 69 super(SymlinkExtractorTests, self).tearDown() 70 os.chdir(self.test_dir) 71 try: 72 os.remove(self.symlinked_dir) 73 except OSError: 74 pass 75 os.chdir(self._cwd) 76 77 def test_symlink(self): 78 if hasattr(os, 'symlink'): 79 if os.path.exists(self.symlinked_dir): 80 self.assert_(os.path.islink(self.symlinked_dir)) 81 else: 82 os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir) 83 os.chdir(self.test_dir) 84 management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True) 85 self.assert_(os.path.exists(self.PO_FILE)) 86 po_contents = open(self.PO_FILE, 'r').read() 87 self.assertMsgId('This literal should be included.', po_contents) 88 self.assert_('templates_symlinked/test.html' in po_contents) 89 90 91 class CopyPluralFormsExtractorTests(ExtractorTests): 92 93 def test_copy_plural_forms(self): 94 os.chdir(self.test_dir) 95 management.call_command('makemessages', locale=LOCALE, verbosity=0) 96 self.assert_(os.path.exists(self.PO_FILE)) 97 po_contents = open(self.PO_FILE, 'r').read() 98 self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents) -
tests/regressiontests/makemessages/tests.py
diff --git a/tests/regressiontests/makemessages/tests.py b/tests/regressiontests/makemessages/tests.py index 4b4fa1b..e2b6122 100644
a b 1 1 import os 2 import re3 import shutil4 from django.test import TestCase5 from django.core import management6 2 7 LOCALE='de' 8 9 class ExtractorTests(TestCase): 10 11 PO_FILE='locale/%s/LC_MESSAGES/django.po' % LOCALE 12 13 def setUp(self): 14 self._cwd = os.getcwd() 15 self.test_dir = os.path.abspath(os.path.dirname(__file__)) 16 17 def _rmrf(self, dname): 18 if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir: 19 return 20 shutil.rmtree(dname) 21 22 def tearDown(self): 23 os.chdir(self.test_dir) 24 try: 25 self._rmrf('locale/%s' % LOCALE) 26 except OSError: 27 pass 28 os.chdir(self._cwd) 29 30 def assertMsgId(self, msgid, s): 31 return self.assert_(re.search('^msgid "%s"' % msgid, s, re.MULTILINE)) 32 33 def assertNotMsgId(self, msgid, s): 34 return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE)) 35 36 37 class JavascriptExtractorTests(ExtractorTests): 38 39 PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE 40 41 def test_javascript_literals(self): 42 os.chdir(self.test_dir) 43 management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0) 44 self.assert_(os.path.exists(self.PO_FILE)) 45 po_contents = open(self.PO_FILE, 'r').read() 46 self.assertMsgId('This literal should be included.', po_contents) 47 self.assertMsgId('This one as well.', po_contents) 48 49 50 class IgnoredExtractorTests(ExtractorTests): 51 52 def test_ignore_option(self): 53 os.chdir(self.test_dir) 54 management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=['ignore_dir/*']) 55 self.assert_(os.path.exists(self.PO_FILE)) 56 po_contents = open(self.PO_FILE, 'r').read() 57 self.assertMsgId('This literal should be included.', po_contents) 58 self.assertNotMsgId('This should be ignored.', po_contents) 59 60 61 class SymlinkExtractorTests(ExtractorTests): 62 63 def setUp(self): 64 self._cwd = os.getcwd() 65 self.test_dir = os.path.abspath(os.path.dirname(__file__)) 66 self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked') 67 68 def tearDown(self): 69 super(SymlinkExtractorTests, self).tearDown() 70 os.chdir(self.test_dir) 71 try: 72 os.remove(self.symlinked_dir) 73 except OSError: 74 pass 75 os.chdir(self._cwd) 76 77 def test_symlink(self): 78 if hasattr(os, 'symlink'): 79 if os.path.exists(self.symlinked_dir): 80 self.assert_(os.path.islink(self.symlinked_dir)) 81 else: 82 os.symlink(os.path.join(self.test_dir, 'templates'), self.symlinked_dir) 83 os.chdir(self.test_dir) 84 management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True) 85 self.assert_(os.path.exists(self.PO_FILE)) 86 po_contents = open(self.PO_FILE, 'r').read() 87 self.assertMsgId('This literal should be included.', po_contents) 88 self.assert_('templates_symlinked/test.html' in po_contents) 89 90 91 class CopyPluralFormsExtractorTests(ExtractorTests): 92 93 def test_copy_plural_forms(self): 94 os.chdir(self.test_dir) 95 management.call_command('makemessages', locale=LOCALE, verbosity=0) 96 self.assert_(os.path.exists(self.PO_FILE)) 97 po_contents = open(self.PO_FILE, 'r').read() 98 self.assert_('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents) 3 def find_command(cmd, path=None, pathext=None): 4 if path is None: 5 path = os.environ.get('PATH', []).split(os.pathsep) 6 if isinstance(path, basestring): 7 path = [path] 8 # check if there are funny path extensions for executables, e.g. Windows 9 if pathext is None: 10 pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep) 11 # don't use extensions if the command ends with one of them 12 for ext in pathext: 13 if cmd.endswith(ext): 14 pathext = [''] 15 break 16 # check if we find the command on PATH 17 for p in path: 18 f = os.path.join(p, cmd) 19 if os.path.isfile(f): 20 return f 21 for ext in pathext: 22 fext = f + ext 23 if os.path.isfile(fext): 24 return fext 25 return None 26 27 # checks if it can find xgettext on the PATH and 28 # imports the extraction tests if yes 29 if find_command('xgettext'): 30 from extraction import *