1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #25720 -- Made gettext() return bytestring on Python 2 if input is bytestring.

This is consistent with the behavior of Django 1.7.x and earlier.
This commit is contained in:
Marti Raudsepp
2015-11-09 15:58:24 +02:00
committed by Tim Graham
parent 4c593eaa5f
commit d3e3703a15
3 changed files with 16 additions and 0 deletions

View File

@@ -143,6 +143,18 @@ 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