mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Refs #23919 -- Removed six.PY2/PY3 usage
Thanks Tim Graham for the review.
This commit is contained in:
@@ -12,7 +12,7 @@ from django.core.management.commands.makemessages import \
|
||||
from django.core.management.utils import find_command
|
||||
from django.test import SimpleTestCase, mock, override_settings
|
||||
from django.test.utils import captured_stderr, captured_stdout
|
||||
from django.utils import six, translation
|
||||
from django.utils import translation
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six import StringIO
|
||||
from django.utils.translation import ugettext
|
||||
@@ -144,18 +144,11 @@ class CompilationErrorHandling(MessageCompilationTests):
|
||||
env = os.environ.copy()
|
||||
env.update({str('LANG'): str('C')})
|
||||
with mock.patch('django.core.management.utils.Popen', lambda *args, **kwargs: Popen(*args, env=env, **kwargs)):
|
||||
if six.PY2:
|
||||
# Various assertRaises on PY2 don't support unicode error messages.
|
||||
try:
|
||||
call_command('compilemessages', locale=['ko'], verbosity=0)
|
||||
except CommandError as err:
|
||||
self.assertIn("' cannot start a field name", six.text_type(err))
|
||||
else:
|
||||
cmd = MakeMessagesCommand()
|
||||
if cmd.gettext_version < (0, 18, 3):
|
||||
self.skipTest("python-brace-format is a recent gettext addition.")
|
||||
with self.assertRaisesMessage(CommandError, "' cannot start a field name"):
|
||||
call_command('compilemessages', locale=['ko'], verbosity=0)
|
||||
cmd = MakeMessagesCommand()
|
||||
if cmd.gettext_version < (0, 18, 3):
|
||||
self.skipTest("python-brace-format is a recent gettext addition.")
|
||||
with self.assertRaisesMessage(CommandError, "' cannot start a field name"):
|
||||
call_command('compilemessages', locale=['ko'], verbosity=0)
|
||||
|
||||
|
||||
class ProjectAndAppTests(MessageCompilationTests):
|
||||
|
||||
@@ -6,7 +6,6 @@ import pickle
|
||||
from contextlib import contextmanager
|
||||
from importlib import import_module
|
||||
from threading import local
|
||||
from unittest import skipUnless
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
@@ -23,13 +22,11 @@ from django.utils.formats import (
|
||||
)
|
||||
from django.utils.numberformat import format as nformat
|
||||
from django.utils.safestring import SafeBytes, SafeText
|
||||
from django.utils.six import PY3
|
||||
from django.utils.translation import (
|
||||
LANGUAGE_SESSION_KEY, activate, check_for_language, deactivate,
|
||||
get_language, get_language_from_request, get_language_info, gettext,
|
||||
gettext_lazy, ngettext_lazy, npgettext, npgettext_lazy, pgettext,
|
||||
pgettext_lazy, trans_real, ugettext, ugettext_lazy, ungettext,
|
||||
ungettext_lazy,
|
||||
get_language, get_language_from_request, get_language_info, gettext_lazy,
|
||||
ngettext_lazy, npgettext, npgettext_lazy, pgettext, trans_real, ugettext,
|
||||
ugettext_lazy, ungettext, ungettext_lazy,
|
||||
)
|
||||
|
||||
from .forms import CompanyForm, I18nForm, SelectDateForm
|
||||
@@ -141,33 +138,6 @@ class TranslationTests(SimpleTestCase):
|
||||
s4 = ugettext_lazy('Some other string')
|
||||
self.assertNotEqual(s, s4)
|
||||
|
||||
@skipUnless(six.PY2, "No more bytestring translations on PY3")
|
||||
def test_bytestrings(self):
|
||||
"""gettext() returns a bytestring if input is bytestring."""
|
||||
|
||||
# Using repr() to check translated text and type
|
||||
self.assertEqual(repr(gettext(b"Time")), repr(b"Time"))
|
||||
self.assertEqual(repr(gettext("Time")), repr("Time"))
|
||||
|
||||
with translation.override('de', deactivate=True):
|
||||
self.assertEqual(repr(gettext(b"Time")), repr(b"Zeit"))
|
||||
self.assertEqual(repr(gettext("Time")), repr(b"Zeit"))
|
||||
|
||||
@skipUnless(six.PY2, "No more bytestring translations on PY3")
|
||||
def test_lazy_and_bytestrings(self):
|
||||
# On Python 2, (n)gettext_lazy should not transform a bytestring to unicode
|
||||
self.assertEqual(gettext_lazy(b"test").upper(), b"TEST")
|
||||
self.assertEqual((ngettext_lazy(b"%d test", b"%d tests") % 1).upper(), b"1 TEST")
|
||||
|
||||
# Other versions of lazy functions always return unicode
|
||||
self.assertEqual(ugettext_lazy(b"test").upper(), "TEST")
|
||||
self.assertEqual((ungettext_lazy(b"%d test", b"%d tests") % 1).upper(), "1 TEST")
|
||||
self.assertEqual(pgettext_lazy(b"context", b"test").upper(), "TEST")
|
||||
self.assertEqual(
|
||||
(npgettext_lazy(b"context", b"%d test", b"%d tests") % 1).upper(),
|
||||
"1 TEST"
|
||||
)
|
||||
|
||||
def test_lazy_pickle(self):
|
||||
s1 = ugettext_lazy("test")
|
||||
self.assertEqual(six.text_type(s1), "test")
|
||||
@@ -223,20 +193,6 @@ class TranslationTests(SimpleTestCase):
|
||||
with self.assertRaisesMessage(KeyError, 'Your dictionary lacks key'):
|
||||
complex_context_deferred % {'name': 'Jim'}
|
||||
|
||||
@skipUnless(six.PY2, "PY3 doesn't have distinct int and long types")
|
||||
def test_ungettext_lazy_long(self):
|
||||
"""
|
||||
Regression test for #22820: int and long should be treated alike in ungettext_lazy.
|
||||
"""
|
||||
result = ungettext_lazy('%(name)s has %(num)d good result', '%(name)s has %(num)d good results', 4)
|
||||
self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
|
||||
# Now with a long
|
||||
result = ungettext_lazy(
|
||||
'%(name)s has %(num)d good result', '%(name)s has %(num)d good results',
|
||||
long(4) # NOQA: long undefined on PY3
|
||||
)
|
||||
self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
|
||||
|
||||
def test_ungettext_lazy_bool(self):
|
||||
self.assertTrue(ungettext_lazy('%d good result', '%d good results'))
|
||||
self.assertFalse(ungettext_lazy('', ''))
|
||||
@@ -298,7 +254,7 @@ class FormattingTests(SimpleTestCase):
|
||||
self.d = datetime.date(2009, 12, 31)
|
||||
self.dt = datetime.datetime(2009, 12, 31, 20, 50)
|
||||
self.t = datetime.time(10, 15, 48)
|
||||
self.long = 10000 if PY3 else long(10000) # NOQA: long undefined on PY3
|
||||
self.long = 10000
|
||||
self.ctxt = Context({
|
||||
'n': self.n,
|
||||
't': self.t,
|
||||
|
||||
Reference in New Issue
Block a user