|
Revision 6845, 1.5 kB
(checked in by mtredinnick, 9 months ago)
|
Fixed #6071 -- Fixed another infinite recursion problem in SafeString? and
SafeUnicode?. Thanks, Trey Long.
|
- Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 |
# coding: utf-8 |
|---|
| 2 |
import misc |
|---|
| 3 |
|
|---|
| 4 |
regressions = ur""" |
|---|
| 5 |
Format string interpolation should work with *_lazy objects. |
|---|
| 6 |
|
|---|
| 7 |
>>> from django.utils.translation import ugettext, ugettext_lazy, activate, deactivate, gettext_lazy |
|---|
| 8 |
>>> s = ugettext_lazy('Add %(name)s') |
|---|
| 9 |
>>> d = {'name': 'Ringo'} |
|---|
| 10 |
>>> s % d |
|---|
| 11 |
u'Add Ringo' |
|---|
| 12 |
>>> activate('de') |
|---|
| 13 |
>>> s % d |
|---|
| 14 |
u'Ringo hinzuf\xfcgen' |
|---|
| 15 |
>>> activate('pl') |
|---|
| 16 |
>>> s % d |
|---|
| 17 |
u'Dodaj Ringo' |
|---|
| 18 |
>>> deactivate() |
|---|
| 19 |
|
|---|
| 20 |
It should be possible to compare *_lazy objects. |
|---|
| 21 |
|
|---|
| 22 |
>>> s1 = ugettext_lazy('Add %(name)s') |
|---|
| 23 |
>>> s == s1 |
|---|
| 24 |
True |
|---|
| 25 |
>>> s2 = gettext_lazy('Add %(name)s') |
|---|
| 26 |
>>> s3 = gettext_lazy('Add %(name)s') |
|---|
| 27 |
>>> s2 == s3 |
|---|
| 28 |
True |
|---|
| 29 |
>>> s == s2 |
|---|
| 30 |
True |
|---|
| 31 |
>>> s4 = ugettext_lazy('Some other string') |
|---|
| 32 |
>>> s == s4 |
|---|
| 33 |
False |
|---|
| 34 |
|
|---|
| 35 |
unicode(string_concat(...)) should not raise a TypeError - #4796 |
|---|
| 36 |
|
|---|
| 37 |
>>> import django.utils.translation |
|---|
| 38 |
>>> reload(django.utils.translation) |
|---|
| 39 |
<module 'django.utils.translation' from ...> |
|---|
| 40 |
>>> unicode(django.utils.translation.string_concat("dja", "ngo")) |
|---|
| 41 |
u'django' |
|---|
| 42 |
|
|---|
| 43 |
Translating a string requiring no auto-escaping shouldn't change the "safe" |
|---|
| 44 |
status. |
|---|
| 45 |
|
|---|
| 46 |
>>> from django.utils.safestring import mark_safe, SafeString |
|---|
| 47 |
>>> s = mark_safe('Password') |
|---|
| 48 |
>>> type(s) |
|---|
| 49 |
<class 'django.utils.safestring.SafeString'> |
|---|
| 50 |
>>> activate('de') |
|---|
| 51 |
>>> type(ugettext(s)) |
|---|
| 52 |
<class 'django.utils.safestring.SafeUnicode'> |
|---|
| 53 |
>>> deactivate() |
|---|
| 54 |
|
|---|
| 55 |
>>> SafeString('a') + s |
|---|
| 56 |
'aPassword' |
|---|
| 57 |
>>> s + SafeString('a') |
|---|
| 58 |
'Passworda' |
|---|
| 59 |
>>> s + mark_safe('a') |
|---|
| 60 |
'Passworda' |
|---|
| 61 |
>>> mark_safe('a') + s |
|---|
| 62 |
'aPassword' |
|---|
| 63 |
>>> mark_safe('a') + mark_safe('s') |
|---|
| 64 |
'as' |
|---|
| 65 |
>>> print s |
|---|
| 66 |
Password |
|---|
| 67 |
""" |
|---|
| 68 |
|
|---|
| 69 |
__test__ = { |
|---|
| 70 |
'regressions': regressions, |
|---|
| 71 |
'misc': misc.tests, |
|---|
| 72 |
} |
|---|