Skip to content

Commit 49de4f1

Browse files
claudeptimgraham
authored andcommitted
[1.11.x] Refs #24423 -- Readded inadvertently deleted i18n tests.
Mistake in 97c1931. Backport of 357a6428980961b2c5311eb75d16229c7fc0d982 from master
1 parent f20168e commit 49de4f1

File tree

1 file changed

+59
-6
lines changed

1 file changed

+59
-6
lines changed

tests/i18n/tests.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616
from django.conf.urls.i18n import i18n_patterns
1717
from django.template import Context, Template
1818
from django.test import (
19-
RequestFactory, SimpleTestCase, TestCase, override_settings,
19+
RequestFactory, SimpleTestCase, TestCase, ignore_warnings,
20+
override_settings,
2021
)
2122
from django.utils import six, translation
2223
from django.utils._os import upath
24+
from django.utils.deprecation import RemovedInDjango21Warning
2325
from django.utils.formats import (
2426
date_format, get_format, get_format_modules, iter_format_modules, localize,
2527
localize_input, reset_format_cache, sanitize_separators, time_format,
2628
)
2729
from django.utils.numberformat import format as nformat
28-
from django.utils.safestring import SafeBytes, SafeText
30+
from django.utils.safestring import SafeBytes, SafeString, SafeText, mark_safe
2931
from django.utils.six import PY3
3032
from django.utils.translation import (
3133
LANGUAGE_SESSION_KEY, activate, check_for_language, deactivate,
32-
get_language, get_language_from_request, get_language_info, gettext,
33-
gettext_lazy, ngettext_lazy, npgettext, npgettext_lazy, pgettext,
34-
pgettext_lazy, trans_real, ugettext, ugettext_lazy, ungettext,
35-
ungettext_lazy,
34+
get_language, get_language_bidi, get_language_from_request,
35+
get_language_info, gettext, gettext_lazy, ngettext_lazy, npgettext,
36+
npgettext_lazy, pgettext, pgettext_lazy, string_concat, to_locale,
37+
trans_real, ugettext, ugettext_lazy, ungettext, ungettext_lazy,
3638
)
3739

3840
from .forms import CompanyForm, I18nForm, SelectDateForm
@@ -262,6 +264,57 @@ def test_pgettext(self):
262264
self.assertEqual(pgettext("verb", "May"), "Kann")
263265
self.assertEqual(npgettext("search", "%d result", "%d results", 4) % 4, "4 Resultate")
264266

267+
@ignore_warnings(category=RemovedInDjango21Warning)
268+
def test_string_concat(self):
269+
self.assertEqual(str(string_concat('dja', 'ngo')), 'django')
270+
271+
def test_empty_value(self):
272+
"""Empty value must stay empty after being translated (#23196)."""
273+
with translation.override('de'):
274+
self.assertEqual('', gettext(''))
275+
s = mark_safe('')
276+
self.assertEqual(s, gettext(s))
277+
278+
def test_safe_status(self):
279+
"""
280+
Translating a string requiring no auto-escaping shouldn't change the
281+
"safe" status.
282+
"""
283+
s = mark_safe(str('Password'))
284+
self.assertIs(type(s), SafeString)
285+
with translation.override('de', deactivate=True):
286+
self.assertIs(type(ugettext(s)), SafeText)
287+
self.assertEqual('aPassword', SafeText('a') + s)
288+
self.assertEqual('Passworda', s + SafeText('a'))
289+
self.assertEqual('Passworda', s + mark_safe('a'))
290+
self.assertEqual('aPassword', mark_safe('a') + s)
291+
self.assertEqual('as', mark_safe('a') + mark_safe('s'))
292+
293+
def test_maclines(self):
294+
"""
295+
Translations on files with Mac or DOS end of lines will be converted
296+
to unix EOF in .po catalogs.
297+
"""
298+
ca_translation = trans_real.translation('ca')
299+
ca_translation._catalog['Mac\nEOF\n'] = 'Catalan Mac\nEOF\n'
300+
ca_translation._catalog['Win\nEOF\n'] = 'Catalan Win\nEOF\n'
301+
with translation.override('ca', deactivate=True):
302+
self.assertEqual('Catalan Mac\nEOF\n', gettext('Mac\rEOF\r'))
303+
self.assertEqual('Catalan Win\nEOF\n', gettext('Win\r\nEOF\r\n'))
304+
305+
def test_to_locale(self):
306+
self.assertEqual(to_locale('en-us'), 'en_US')
307+
self.assertEqual(to_locale('sr-lat'), 'sr_Lat')
308+
309+
def test_to_language(self):
310+
self.assertEqual(trans_real.to_language('en_US'), 'en-us')
311+
self.assertEqual(trans_real.to_language('sr_Lat'), 'sr-lat')
312+
313+
def test_language_bidi(self):
314+
self.assertIs(get_language_bidi(), False)
315+
with translation.override(None):
316+
self.assertIs(get_language_bidi(), False)
317+
265318

266319
class TranslationThreadSafetyTests(SimpleTestCase):
267320

0 commit comments

Comments
 (0)