summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-01-26 14:29:04 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-01-27 22:01:22 +0100
commitb951a7fbc12045eff104940dafaec308a543ead2 (patch)
tree1dbf9095629c68f19110eaabe1824dc8e1c49593
parent3145ae06beed2f8c679db5d7a06907dd2a03d138 (diff)
Removed superfluous uses of TransRealMixin.
The translation.override context manager cleans up after itself. As a consequence this mixin isn't needed any more in many cases.
-rw-r--r--django/contrib/humanize/tests.py3
-rw-r--r--tests/defaultfilters/tests.py5
-rw-r--r--tests/forms_tests/tests/test_regressions.py14
-rw-r--r--tests/i18n/contenttypes/tests.py3
-rw-r--r--tests/template_tests/tests.py84
5 files changed, 48 insertions, 61 deletions
diff --git a/django/contrib/humanize/tests.py b/django/contrib/humanize/tests.py
index ab4d53c760..4a58a64889 100644
--- a/django/contrib/humanize/tests.py
+++ b/django/contrib/humanize/tests.py
@@ -12,7 +12,6 @@ from django.conf import settings
from django.contrib.humanize.templatetags import humanize
from django.template import Template, Context, defaultfilters
from django.test import TestCase, override_settings
-from django.test.utils import TransRealMixin
from django.utils.html import escape
from django.utils.timezone import utc, get_fixed_timezone
from django.utils import translation
@@ -36,7 +35,7 @@ class MockDateTime(datetime.datetime):
return now.replace(tzinfo=tz) + tz.utcoffset(now)
-class HumanizeTests(TransRealMixin, TestCase):
+class HumanizeTests(TestCase):
def humanize_tester(self, test_list, result_list, method, normalize_result_func=escape):
for test_content, result in zip(test_list, result_list):
diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py
index 2dc6d9cf0c..6e309dc97a 100644
--- a/tests/defaultfilters/tests.py
+++ b/tests/defaultfilters/tests.py
@@ -17,7 +17,6 @@ from django.template.defaultfilters import (
urlize, urlizetrunc, wordcount, wordwrap, yesno,
)
from django.test import TestCase
-from django.test.utils import TransRealMixin
from django.utils import six
from django.utils import translation
from django.utils.safestring import SafeData
@@ -683,11 +682,11 @@ class DefaultFiltersTests(TestCase):
self.assertEqual(striptags(123), '123')
-class DefaultFiltersI18NTests(TransRealMixin, TestCase):
+class DefaultFiltersI18NTests(TestCase):
def test_localized_filesizeformat(self):
# NOTE: \xa0 avoids wrapping between value and unit
- with self.settings(USE_L10N=True), translation.override('de', deactivate=True):
+ with self.settings(USE_L10N=True), translation.override('de'):
self.assertEqual(filesizeformat(1023), '1023\xa0Bytes')
self.assertEqual(filesizeformat(1024), '1,0\xa0KB')
self.assertEqual(filesizeformat(10 * 1024), '10,0\xa0KB')
diff --git a/tests/forms_tests/tests/test_regressions.py b/tests/forms_tests/tests/test_regressions.py
index 39459aa472..b009e800e1 100644
--- a/tests/forms_tests/tests/test_regressions.py
+++ b/tests/forms_tests/tests/test_regressions.py
@@ -9,13 +9,13 @@ from django.forms import (
TextInput,
)
from django.test import TestCase
-from django.utils.translation import ugettext_lazy, override
+from django.utils import translation
+from django.utils.translation import gettext_lazy, ugettext_lazy
from forms_tests.models import Cheese
-from django.test.utils import TransRealMixin
-class FormsRegressionsTestCase(TransRealMixin, TestCase):
+class FormsRegressionsTestCase(TestCase):
def test_class(self):
# Tests to prevent against recurrences of earlier bugs.
extra_attrs = {'class': 'special'}
@@ -37,9 +37,9 @@ class FormsRegressionsTestCase(TransRealMixin, TestCase):
self.assertHTMLEqual(f.as_p(), '<p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>')
# Translations are done at rendering time, so multi-lingual apps can define forms)
- with override('de'):
+ with translation.override('de'):
self.assertHTMLEqual(f.as_p(), '<p><label for="id_username">Benutzername:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>')
- with override('pl', deactivate=True):
+ with translation.override('pl'):
self.assertHTMLEqual(f.as_p(), '<p><label for="id_username">Nazwa u\u017cytkownika:</label> <input id="id_username" type="text" name="username" maxlength="10" /></p>')
def test_regression_5216(self):
@@ -73,13 +73,11 @@ class FormsRegressionsTestCase(TransRealMixin, TestCase):
self.assertEqual(f.clean(b'\xd1\x88\xd1\x82.'), '\u0448\u0442.')
# Translated error messages used to be buggy.
- with override('ru'):
+ with translation.override('ru'):
f = SomeForm({})
self.assertHTMLEqual(f.as_p(), '<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul id="id_somechoice">\n<li><label for="id_somechoice_0"><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label for="id_somechoice_1"><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label for="id_somechoice_2"><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>')
# Deep copying translated text shouldn't raise an error)
- from django.utils.translation import gettext_lazy
-
class CopyForm(Form):
degree = IntegerField(widget=Select(choices=((1, gettext_lazy('test')),)))
diff --git a/tests/i18n/contenttypes/tests.py b/tests/i18n/contenttypes/tests.py
index 894ae0a3c7..3e25867616 100644
--- a/tests/i18n/contenttypes/tests.py
+++ b/tests/i18n/contenttypes/tests.py
@@ -5,7 +5,6 @@ import os
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase, override_settings
-from django.test.utils import TransRealMixin
from django.utils._os import upath
from django.utils import six
from django.utils import translation
@@ -22,7 +21,7 @@ from django.utils import translation
('fr', 'French'),
),
)
-class ContentTypeTests(TransRealMixin, TestCase):
+class ContentTypeTests(TestCase):
def test_verbose_name(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
with translation.override('en'):
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py
index b5b9bdf5b1..4dcf0281a4 100644
--- a/tests/template_tests/tests.py
+++ b/tests/template_tests/tests.py
@@ -22,15 +22,14 @@ from django.template import (base as template_base, loader, Context,
from django.template.loaders import app_directories, filesystem, cached
from django.test import RequestFactory, TestCase
from django.test.utils import (setup_test_template_loader,
- restore_template_loaders, override_settings, TransRealMixin,
- extend_sys_path)
+ restore_template_loaders, override_settings, extend_sys_path)
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import date_format
from django.utils._os import upath
-from django.utils.translation import activate, deactivate
from django.utils.safestring import mark_safe
from django.utils import six
from django.utils.six.moves.urllib.parse import urljoin
+from django.utils import translation
# NumPy installed?
try:
@@ -550,7 +549,7 @@ class TemplateRegressionTests(TestCase):
TEMPLATE_DEBUG=False, ALLOWED_INCLUDE_ROOTS=(
os.path.dirname(os.path.abspath(upath(__file__))),),
)
-class TemplateTests(TransRealMixin, TestCase):
+class TemplateTests(TestCase):
urls = 'template_tests.urls'
def test_templates(self):
@@ -600,54 +599,47 @@ class TemplateTests(TransRealMixin, TestCase):
invalid_string_result = vals[2]
template_debug_result = vals[2]
- if 'LANGUAGE_CODE' in vals[1]:
- activate(vals[1]['LANGUAGE_CODE'])
- else:
- activate('en-us')
-
- for invalid_str, template_debug, result in [
- ('', False, normal_string_result),
- (expected_invalid_str, False, invalid_string_result),
- ('', True, template_debug_result)
- ]:
- with override_settings(TEMPLATE_STRING_IF_INVALID=invalid_str,
- TEMPLATE_DEBUG=template_debug):
- for is_cached in (False, True):
- try:
- try:
- with warnings.catch_warnings():
- # Ignore pending deprecations of the old syntax of the 'cycle' and 'firstof' tags.
- warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.base')
- test_template = loader.get_template(name)
- except ShouldNotExecuteException:
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
+ with translation.override(vals[1].get('LANGUAGE_CODE', 'en-us')):
+ for invalid_str, template_debug, result in [
+ ('', False, normal_string_result),
+ (expected_invalid_str, False, invalid_string_result),
+ ('', True, template_debug_result)
+ ]:
+ with override_settings(TEMPLATE_STRING_IF_INVALID=invalid_str,
+ TEMPLATE_DEBUG=template_debug):
+ for is_cached in (False, True):
try:
- output = self.render(test_template, vals)
- except ShouldNotExecuteException:
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
- except ContextStackException:
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
- continue
- except Exception:
- exc_type, exc_value, exc_tb = sys.exc_info()
- if exc_type != result:
- tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
- continue
- if output != result:
- failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
- cache_loader.reset()
+ try:
+ with warnings.catch_warnings():
+ # Ignore pending deprecations of the old syntax of the 'cycle' and 'firstof' tags.
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.base')
+ test_template = loader.get_template(name)
+ except ShouldNotExecuteException:
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
- if 'LANGUAGE_CODE' in vals[1]:
- deactivate()
+ try:
+ output = self.render(test_template, vals)
+ except ShouldNotExecuteException:
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
+ except ContextStackException:
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Context stack was left imbalanced" % (is_cached, invalid_str, template_debug, name))
+ continue
+ except Exception:
+ exc_type, exc_value, exc_tb = sys.exc_info()
+ if exc_type != result:
+ tb = '\n'.join(traceback.format_exception(exc_type, exc_value, exc_tb))
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Got %s, exception: %s\n%s" % (is_cached, invalid_str, template_debug, name, exc_type, exc_value, tb))
+ continue
+ if output != result:
+ failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Expected %r, got %r" % (is_cached, invalid_str, template_debug, name, result, output))
+ cache_loader.reset()
- if template_base.invalid_var_format_string:
- expected_invalid_str = 'INVALID'
- template_base.invalid_var_format_string = False
+ if template_base.invalid_var_format_string:
+ expected_invalid_str = 'INVALID'
+ template_base.invalid_var_format_string = False
restore_template_loaders()
- deactivate()
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))