diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-05-02 19:31:22 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-05-02 19:33:22 +0200 |
| commit | 142c27218a0bb07bb197faab7b1d8eb3a084f5b9 (patch) | |
| tree | 7d4994c7f122eecea88efb8914fe56a8b5b0ca13 /tests | |
| parent | d1799233f46c39379fe429a4ece128d96b128006 (diff) | |
Fixed #22565 -- Prevented pgettext_lazy crash with bytestring input
Thanks ygbo for the report.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i18n/tests.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index 13198831a0..8d0fc963af 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -9,6 +9,7 @@ from importlib import import_module import os import pickle from threading import local +from unittest import skipUnless from django.conf import settings from django.template import Template, Context @@ -30,7 +31,7 @@ from django.utils.translation import (activate, deactivate, ugettext, ugettext_lazy, ngettext_lazy, ungettext_lazy, - pgettext, + pgettext, pgettext_lazy, npgettext, npgettext_lazy, check_for_language, string_concat, LANGUAGE_SESSION_KEY) @@ -94,9 +95,20 @@ class TranslationTests(TestCase): s4 = ugettext_lazy('Some other string') self.assertEqual(False, s == s4) - if six.PY2: - # On Python 2, gettext_lazy should not transform a bytestring to unicode - self.assertEqual(gettext_lazy(b"test").upper(), b"TEST") + @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") |
