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:38:46 +0200 |
| commit | 034866204b39f797c73997b03cd90443aa03aa91 (patch) | |
| tree | 7ce82f5f79308861e1c7be0003350996ea8be0a0 /tests | |
| parent | b97b24882c7c3363d6972fe1f3a5573738cf9d5a (diff) | |
[1.6.x] Fixed #22565 -- Prevented pgettext_lazy crash with bytestring input
Thanks ygbo for the report.
Backport of 142c27218 from master.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/i18n/tests.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py index a0bbd4f7d7..9533baac17 100644 --- a/tests/i18n/tests.py +++ b/tests/i18n/tests.py @@ -33,6 +33,7 @@ from django.utils.translation import (activate, deactivate, pgettext, pgettext_lazy, npgettext, npgettext_lazy, check_for_language) +from django.utils.unittest import skipUnless if find_command('xgettext'): from .commands.extraction import (ExtractorTests, BasicExtractorTests, @@ -88,9 +89,20 @@ class TranslationTests(TransRealMixin, 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") |
