diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py
index a65fcac..8bc3f51 100644
|
a
|
b
|
import gettext as gettext_module
|
| 5 | 5 | import os |
| 6 | 6 | import shutil |
| 7 | 7 | import stat |
| | 8 | import tempfile |
| 8 | 9 | import unittest |
| 9 | 10 | from subprocess import Popen |
| 10 | 11 | |
| … |
… |
class MessageCompilationTests(SimpleTestCase):
|
| 31 | 32 | test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'commands')) |
| 32 | 33 | |
| 33 | 34 | def setUp(self): |
| | 35 | # Update test_dir to point to a temporary directory and work from there |
| | 36 | self._test_dir = self.test_dir |
| 34 | 37 | self._cwd = os.getcwd() |
| 35 | | self.addCleanup(os.chdir, self._cwd) |
| | 38 | self._tempdir = tempfile.mkdtemp() |
| | 39 | self.test_dir = os.path.join(self._tempdir, |
| | 40 | os.path.basename(self._test_dir)) |
| | 41 | shutil.copytree(self._test_dir, self.test_dir) |
| 36 | 42 | os.chdir(self.test_dir) |
| 37 | 43 | |
| 38 | | def _rmrf(self, dname): |
| 39 | | if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir: |
| 40 | | return |
| 41 | | shutil.rmtree(dname) |
| 42 | | |
| 43 | | def rmfile(self, filepath): |
| 44 | | if os.path.exists(filepath): |
| 45 | | os.remove(filepath) |
| | 44 | def tearDown(self): |
| | 45 | shutil.rmtree(self._tempdir) |
| | 46 | self.test_dir = self._test_dir |
| | 47 | os.chdir(self._cwd) |
| 46 | 48 | |
| 47 | 49 | |
| 48 | 50 | class PoFileTests(MessageCompilationTests): |
| … |
… |
class PoFileContentsTests(MessageCompilationTests):
|
| 76 | 78 | LOCALE = 'fr' |
| 77 | 79 | MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE |
| 78 | 80 | |
| 79 | | def setUp(self): |
| 80 | | super(PoFileContentsTests, self).setUp() |
| 81 | | self.addCleanup(os.unlink, os.path.join(self.test_dir, self.MO_FILE)) |
| 82 | | |
| 83 | 81 | def test_percent_symbol_in_po_file(self): |
| 84 | 82 | call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO()) |
| 85 | 83 | self.assertTrue(os.path.exists(self.MO_FILE)) |
| … |
… |
class MultipleLocaleCompilationTests(MessageCompilationTests):
|
| 95 | 93 | localedir = os.path.join(self.test_dir, 'locale') |
| 96 | 94 | self.MO_FILE_HR = os.path.join(localedir, 'hr/LC_MESSAGES/django.mo') |
| 97 | 95 | self.MO_FILE_FR = os.path.join(localedir, 'fr/LC_MESSAGES/django.mo') |
| 98 | | self.addCleanup(self.rmfile, os.path.join(localedir, self.MO_FILE_HR)) |
| 99 | | self.addCleanup(self.rmfile, os.path.join(localedir, self.MO_FILE_FR)) |
| 100 | 96 | |
| 101 | 97 | def test_one_locale(self): |
| 102 | 98 | with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]): |
| … |
… |
class ExcludedLocaleCompilationTests(MessageCompilationTests):
|
| 122 | 118 | super(ExcludedLocaleCompilationTests, self).setUp() |
| 123 | 119 | |
| 124 | 120 | shutil.copytree('canned_locale', 'locale') |
| 125 | | self.addCleanup(self._rmrf, os.path.join(self.test_dir, 'locale')) |
| 126 | 121 | |
| 127 | 122 | def test_command_help(self): |
| 128 | 123 | with captured_stdout(), captured_stderr(): |
| … |
… |
class CompilationErrorHandling(MessageCompilationTests):
|
| 161 | 156 | def test_error_reported_by_msgfmt(self): |
| 162 | 157 | # po file contains wrong po formatting. |
| 163 | 158 | mo_file = 'locale/ja/LC_MESSAGES/django.mo' |
| 164 | | self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file)) |
| 165 | 159 | with self.assertRaises(CommandError): |
| 166 | 160 | call_command('compilemessages', locale=['ja'], verbosity=0) |
| 167 | 161 | |
| 168 | 162 | def test_msgfmt_error_including_non_ascii(self): |
| 169 | 163 | # po file contains invalid msgstr content (triggers non-ascii error content). |
| 170 | 164 | mo_file = 'locale/ko/LC_MESSAGES/django.mo' |
| 171 | | self.addCleanup(self.rmfile, os.path.join(self.test_dir, mo_file)) |
| 172 | 165 | # Make sure the output of msgfmt is unaffected by the current locale. |
| 173 | 166 | env = os.environ.copy() |
| 174 | 167 | env.update({str('LANG'): str('C')}) |
| … |
… |
class ProjectAndAppTests(MessageCompilationTests):
|
| 192 | 185 | PROJECT_MO_FILE = 'locale/%s/LC_MESSAGES/django.mo' % LOCALE |
| 193 | 186 | APP_MO_FILE = 'app_with_locale/locale/%s/LC_MESSAGES/django.mo' % LOCALE |
| 194 | 187 | |
| 195 | | def setUp(self): |
| 196 | | super(ProjectAndAppTests, self).setUp() |
| 197 | | self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.PROJECT_MO_FILE)) |
| 198 | | self.addCleanup(self.rmfile, os.path.join(self.test_dir, self.APP_MO_FILE)) |
| 199 | | |
| 200 | 188 | |
| 201 | 189 | class FuzzyTranslationTest(ProjectAndAppTests): |
| 202 | 190 | |