Serialized some tests that interact with the filesystem.

Considering the APIs exercised by these test cases, it's hard to make
them independent.
This commit is contained in:
Aymeric Augustin 2015-02-05 22:33:13 +01:00
parent ba81386487
commit b799a50c8e
2 changed files with 14 additions and 7 deletions

View File

@ -17,6 +17,7 @@ from django.core.management.commands.makemessages import \
Command as MakeMessagesCommand Command as MakeMessagesCommand
from django.core.management.utils import find_command from django.core.management.utils import find_command
from django.test import SimpleTestCase, mock, override_settings from django.test import SimpleTestCase, mock, override_settings
from django.test.testcases import SerializeMixin
from django.test.utils import captured_stderr, captured_stdout from django.test.utils import captured_stderr, captured_stdout
from django.utils import six from django.utils import six
from django.utils._os import upath from django.utils._os import upath
@ -30,7 +31,13 @@ this_directory = os.path.dirname(upath(__file__))
@skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests') @skipUnless(has_xgettext, 'xgettext is mandatory for extraction tests')
class ExtractorTests(SimpleTestCase): class ExtractorTests(SerializeMixin, SimpleTestCase):
# makemessages scans the current working directory and writes in the
# locale subdirectory. There aren't any options to control this. As a
# consequence tests can't run in parallel. Since i18n tests run in less
# than 4 seconds, serializing them with SerializeMixin is acceptable.
lockfile = __file__
test_dir = os.path.abspath(os.path.join(this_directory, 'commands')) test_dir = os.path.abspath(os.path.join(this_directory, 'commands'))
@ -610,9 +617,6 @@ class KeepPotFileExtractorTests(ExtractorTests):
POT_FILE = 'locale/django.pot' POT_FILE = 'locale/django.pot'
def setUp(self):
super(KeepPotFileExtractorTests, self).setUp()
def tearDown(self): def tearDown(self):
super(KeepPotFileExtractorTests, self).tearDown() super(KeepPotFileExtractorTests, self).tearDown()
os.chdir(self.test_dir) os.chdir(self.test_dir)
@ -646,6 +650,7 @@ class MultipleLocaleExtractionTests(ExtractorTests):
LOCALES = ['pt', 'de', 'ch'] LOCALES = ['pt', 'de', 'ch']
def tearDown(self): def tearDown(self):
super(MultipleLocaleExtractionTests, self).tearDown()
os.chdir(self.test_dir) os.chdir(self.test_dir)
for locale in self.LOCALES: for locale in self.LOCALES:
try: try:
@ -677,7 +682,6 @@ class ExcludedLocaleExtractionTests(ExtractorTests):
def setUp(self): def setUp(self):
super(ExcludedLocaleExtractionTests, self).setUp() super(ExcludedLocaleExtractionTests, self).setUp()
os.chdir(self.test_dir) # ExtractorTests.tearDown() takes care of restoring. os.chdir(self.test_dir) # ExtractorTests.tearDown() takes care of restoring.
shutil.copytree('canned_locale', 'locale') shutil.copytree('canned_locale', 'locale')
self._set_times_for_all_po_files() self._set_times_for_all_po_files()
@ -719,7 +723,7 @@ class ExcludedLocaleExtractionTests(ExtractorTests):
class CustomLayoutExtractionTests(ExtractorTests): class CustomLayoutExtractionTests(ExtractorTests):
def setUp(self): def setUp(self):
self._cwd = os.getcwd() super(CustomLayoutExtractionTests, self).setUp()
self.test_dir = os.path.join(this_directory, 'project_dir') self.test_dir = os.path.join(this_directory, 'project_dir')
def test_no_locale_raises(self): def test_no_locale_raises(self):

View File

@ -8,6 +8,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.files import File from django.core.files import File
from django.core.files.images import ImageFile from django.core.files.images import ImageFile
from django.test import TestCase from django.test import TestCase
from django.test.testcases import SerializeMixin
from django.utils._os import upath from django.utils._os import upath
try: try:
@ -27,11 +28,13 @@ else:
PersonTwoImages = Person PersonTwoImages = Person
class ImageFieldTestMixin(object): class ImageFieldTestMixin(SerializeMixin):
""" """
Mixin class to provide common functionality to ImageField test classes. Mixin class to provide common functionality to ImageField test classes.
""" """
lockfile = __file__
# Person model to use for tests. # Person model to use for tests.
PersonModel = PersonWithHeightAndWidth PersonModel = PersonWithHeightAndWidth
# File class to use for file instances. # File class to use for file instances.