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.
This commit is contained in:
parent
3145ae06be
commit
b951a7fbc1
|
@ -12,7 +12,6 @@ from django.conf import settings
|
||||||
from django.contrib.humanize.templatetags import humanize
|
from django.contrib.humanize.templatetags import humanize
|
||||||
from django.template import Template, Context, defaultfilters
|
from django.template import Template, Context, defaultfilters
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import TransRealMixin
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.timezone import utc, get_fixed_timezone
|
from django.utils.timezone import utc, get_fixed_timezone
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
@ -36,7 +35,7 @@ class MockDateTime(datetime.datetime):
|
||||||
return now.replace(tzinfo=tz) + tz.utcoffset(now)
|
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):
|
def humanize_tester(self, test_list, result_list, method, normalize_result_func=escape):
|
||||||
for test_content, result in zip(test_list, result_list):
|
for test_content, result in zip(test_list, result_list):
|
||||||
|
|
|
@ -17,7 +17,6 @@ from django.template.defaultfilters import (
|
||||||
urlize, urlizetrunc, wordcount, wordwrap, yesno,
|
urlize, urlizetrunc, wordcount, wordwrap, yesno,
|
||||||
)
|
)
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.utils import TransRealMixin
|
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.safestring import SafeData
|
from django.utils.safestring import SafeData
|
||||||
|
@ -683,11 +682,11 @@ class DefaultFiltersTests(TestCase):
|
||||||
self.assertEqual(striptags(123), '123')
|
self.assertEqual(striptags(123), '123')
|
||||||
|
|
||||||
|
|
||||||
class DefaultFiltersI18NTests(TransRealMixin, TestCase):
|
class DefaultFiltersI18NTests(TestCase):
|
||||||
|
|
||||||
def test_localized_filesizeformat(self):
|
def test_localized_filesizeformat(self):
|
||||||
# NOTE: \xa0 avoids wrapping between value and unit
|
# 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(1023), '1023\xa0Bytes')
|
||||||
self.assertEqual(filesizeformat(1024), '1,0\xa0KB')
|
self.assertEqual(filesizeformat(1024), '1,0\xa0KB')
|
||||||
self.assertEqual(filesizeformat(10 * 1024), '10,0\xa0KB')
|
self.assertEqual(filesizeformat(10 * 1024), '10,0\xa0KB')
|
||||||
|
|
|
@ -9,13 +9,13 @@ from django.forms import (
|
||||||
TextInput,
|
TextInput,
|
||||||
)
|
)
|
||||||
from django.test import TestCase
|
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 forms_tests.models import Cheese
|
||||||
from django.test.utils import TransRealMixin
|
|
||||||
|
|
||||||
|
|
||||||
class FormsRegressionsTestCase(TransRealMixin, TestCase):
|
class FormsRegressionsTestCase(TestCase):
|
||||||
def test_class(self):
|
def test_class(self):
|
||||||
# Tests to prevent against recurrences of earlier bugs.
|
# Tests to prevent against recurrences of earlier bugs.
|
||||||
extra_attrs = {'class': 'special'}
|
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>')
|
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)
|
# 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>')
|
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>')
|
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):
|
def test_regression_5216(self):
|
||||||
|
@ -73,13 +73,11 @@ class FormsRegressionsTestCase(TransRealMixin, TestCase):
|
||||||
self.assertEqual(f.clean(b'\xd1\x88\xd1\x82.'), '\u0448\u0442.')
|
self.assertEqual(f.clean(b'\xd1\x88\xd1\x82.'), '\u0448\u0442.')
|
||||||
|
|
||||||
# Translated error messages used to be buggy.
|
# Translated error messages used to be buggy.
|
||||||
with override('ru'):
|
with translation.override('ru'):
|
||||||
f = SomeForm({})
|
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>')
|
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)
|
# Deep copying translated text shouldn't raise an error)
|
||||||
from django.utils.translation import gettext_lazy
|
|
||||||
|
|
||||||
class CopyForm(Form):
|
class CopyForm(Form):
|
||||||
degree = IntegerField(widget=Select(choices=((1, gettext_lazy('test')),)))
|
degree = IntegerField(widget=Select(choices=((1, gettext_lazy('test')),)))
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import os
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import TransRealMixin
|
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
@ -22,7 +21,7 @@ from django.utils import translation
|
||||||
('fr', 'French'),
|
('fr', 'French'),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
class ContentTypeTests(TransRealMixin, TestCase):
|
class ContentTypeTests(TestCase):
|
||||||
def test_verbose_name(self):
|
def test_verbose_name(self):
|
||||||
company_type = ContentType.objects.get(app_label='i18n', model='company')
|
company_type = ContentType.objects.get(app_label='i18n', model='company')
|
||||||
with translation.override('en'):
|
with translation.override('en'):
|
||||||
|
|
|
@ -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.template.loaders import app_directories, filesystem, cached
|
||||||
from django.test import RequestFactory, TestCase
|
from django.test import RequestFactory, TestCase
|
||||||
from django.test.utils import (setup_test_template_loader,
|
from django.test.utils import (setup_test_template_loader,
|
||||||
restore_template_loaders, override_settings, TransRealMixin,
|
restore_template_loaders, override_settings, extend_sys_path)
|
||||||
extend_sys_path)
|
|
||||||
from django.utils.encoding import python_2_unicode_compatible
|
from django.utils.encoding import python_2_unicode_compatible
|
||||||
from django.utils.formats import date_format
|
from django.utils.formats import date_format
|
||||||
from django.utils._os import upath
|
from django.utils._os import upath
|
||||||
from django.utils.translation import activate, deactivate
|
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
from django.utils.six.moves.urllib.parse import urljoin
|
from django.utils.six.moves.urllib.parse import urljoin
|
||||||
|
from django.utils import translation
|
||||||
|
|
||||||
# NumPy installed?
|
# NumPy installed?
|
||||||
try:
|
try:
|
||||||
|
@ -550,7 +549,7 @@ class TemplateRegressionTests(TestCase):
|
||||||
TEMPLATE_DEBUG=False, ALLOWED_INCLUDE_ROOTS=(
|
TEMPLATE_DEBUG=False, ALLOWED_INCLUDE_ROOTS=(
|
||||||
os.path.dirname(os.path.abspath(upath(__file__))),),
|
os.path.dirname(os.path.abspath(upath(__file__))),),
|
||||||
)
|
)
|
||||||
class TemplateTests(TransRealMixin, TestCase):
|
class TemplateTests(TestCase):
|
||||||
urls = 'template_tests.urls'
|
urls = 'template_tests.urls'
|
||||||
|
|
||||||
def test_templates(self):
|
def test_templates(self):
|
||||||
|
@ -600,10 +599,7 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
invalid_string_result = vals[2]
|
invalid_string_result = vals[2]
|
||||||
template_debug_result = vals[2]
|
template_debug_result = vals[2]
|
||||||
|
|
||||||
if 'LANGUAGE_CODE' in vals[1]:
|
with translation.override(vals[1].get('LANGUAGE_CODE', 'en-us')):
|
||||||
activate(vals[1]['LANGUAGE_CODE'])
|
|
||||||
else:
|
|
||||||
activate('en-us')
|
|
||||||
|
|
||||||
for invalid_str, template_debug, result in [
|
for invalid_str, template_debug, result in [
|
||||||
('', False, normal_string_result),
|
('', False, normal_string_result),
|
||||||
|
@ -639,15 +635,11 @@ class TemplateTests(TransRealMixin, TestCase):
|
||||||
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))
|
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()
|
cache_loader.reset()
|
||||||
|
|
||||||
if 'LANGUAGE_CODE' in vals[1]:
|
|
||||||
deactivate()
|
|
||||||
|
|
||||||
if template_base.invalid_var_format_string:
|
if template_base.invalid_var_format_string:
|
||||||
expected_invalid_str = 'INVALID'
|
expected_invalid_str = 'INVALID'
|
||||||
template_base.invalid_var_format_string = False
|
template_base.invalid_var_format_string = False
|
||||||
|
|
||||||
restore_template_loaders()
|
restore_template_loaders()
|
||||||
deactivate()
|
|
||||||
|
|
||||||
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
|
self.assertEqual(failures, [], "Tests failed:\n%s\n%s" %
|
||||||
('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))
|
('-' * 70, ("\n%s\n" % ('-' * 70)).join(failures)))
|
||||||
|
|
Loading…
Reference in New Issue