mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Refs #27753 -- Deprecated django.utils.encoding.force_text() and smart_text().
This commit is contained in:
parent
3bb6a4390c
commit
d55e882927
5 changed files with 54 additions and 2 deletions
24
tests/utils_tests/test_encoding_deprecations.py
Normal file
24
tests/utils_tests/test_encoding_deprecations.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from django.test import SimpleTestCase, ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
from django.utils.encoding import force_text, smart_text
|
||||
from django.utils.functional import SimpleLazyObject
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango40Warning)
|
||||
class TestDeprecatedEncodingUtils(SimpleTestCase):
|
||||
|
||||
def test_force_text(self):
|
||||
s = SimpleLazyObject(lambda: 'x')
|
||||
self.assertIs(type(force_text(s)), str)
|
||||
|
||||
def test_smart_text(self):
|
||||
class Test:
|
||||
def __str__(self):
|
||||
return 'ŠĐĆŽćžšđ'
|
||||
|
||||
lazy_func = gettext_lazy('x')
|
||||
self.assertIs(smart_text(lazy_func), lazy_func)
|
||||
self.assertEqual(smart_text(Test()), '\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111')
|
||||
self.assertEqual(smart_text(1), '1')
|
||||
self.assertEqual(smart_text('foo'), 'foo')
|
Loading…
Add table
Add a link
Reference in a new issue