mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #26677 -- Converted some i18n tests to use disposable FS tree.
This allows makemessages/compilemessages tests in `test_extraction.py` and `test_compilation.py` to actually run isolated from each other (unaffected by stray FS objects left by cleanup actions failures, debug sessions, etc.) and to take advantage of the parallel tests execution feature like most of the Django test suite. `test_percents.py` gets slightly refactored to not inherit from the new machinery which sets up every test case to copy and run under a temporary tree.
This commit is contained in:
@@ -5,6 +5,7 @@ import gettext as gettext_module
|
||||
import os
|
||||
import shutil
|
||||
import stat
|
||||
import tempfile
|
||||
import unittest
|
||||
from subprocess import Popen
|
||||
|
||||
@@ -23,15 +24,25 @@ from django.utils.six import StringIO
|
||||
from django.utils.translation import ugettext
|
||||
|
||||
has_msgfmt = find_command('msgfmt')
|
||||
source_code_dir = os.path.dirname(upath(__file__))
|
||||
|
||||
|
||||
@unittest.skipUnless(has_msgfmt, 'msgfmt is mandatory for compilation tests')
|
||||
class MessageCompilationTests(SimpleTestCase):
|
||||
|
||||
test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'commands'))
|
||||
work_subdir = 'commands'
|
||||
|
||||
def setUp(self):
|
||||
self._cwd = os.getcwd()
|
||||
self.work_dir = tempfile.mkdtemp(prefix='i18n_')
|
||||
self.test_dir = os.path.abspath(os.path.join(self.work_dir, self.work_subdir))
|
||||
shutil.copytree(os.path.join(source_code_dir, self.work_subdir), self.test_dir)
|
||||
# Make sure we step out of the temporary working tree before we
|
||||
# remove it as we might be pulling the rug from under our own feet
|
||||
# othewise. Rhis is especially true on Windows.
|
||||
# Remember cleanup actions registered with addCleanup() are called in
|
||||
# reverse so this ordering is important:
|
||||
self.addCleanup(self._rmrf, self.test_dir)
|
||||
self.addCleanup(os.chdir, self._cwd)
|
||||
os.chdir(self.test_dir)
|
||||
|
||||
@@ -114,13 +125,12 @@ class MultipleLocaleCompilationTests(MessageCompilationTests):
|
||||
|
||||
class ExcludedLocaleCompilationTests(MessageCompilationTests):
|
||||
|
||||
test_dir = os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), 'exclude'))
|
||||
work_subdir = 'exclude'
|
||||
|
||||
MO_FILE = 'locale/%s/LC_MESSAGES/django.mo'
|
||||
|
||||
def setUp(self):
|
||||
super(ExcludedLocaleCompilationTests, self).setUp()
|
||||
|
||||
shutil.copytree('canned_locale', 'locale')
|
||||
self.addCleanup(self._rmrf, os.path.join(self.test_dir, 'locale'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user