mirror of
https://github.com/django/django.git
synced 2025-09-26 12:09:19 +00:00
[py3] Ported django.utils.functional.
This commit is contained in:
parent
7e01e532c0
commit
fe8484efda
3 changed files with 57 additions and 31 deletions
|
@ -19,17 +19,27 @@ class _ComplexObject(object):
|
|||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
||||
def __str__(self):
|
||||
return "I am _ComplexObject(%r)" % self.name
|
||||
if six.PY3:
|
||||
def __bytes__(self):
|
||||
return ("I am _ComplexObject(%r)" % self.name).encode("utf-8")
|
||||
|
||||
def __unicode__(self):
|
||||
return six.text_type(self.name)
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
else:
|
||||
def __str__(self):
|
||||
return b"I am _ComplexObject(%r)" % str(self.name)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
def __repr__(self):
|
||||
return "_ComplexObject(%r)" % self.name
|
||||
|
||||
|
||||
complex_object = lambda: _ComplexObject("joe")
|
||||
|
||||
|
||||
class TestUtilsSimpleLazyObject(TestCase):
|
||||
"""
|
||||
Tests for SimpleLazyObject
|
||||
|
@ -54,11 +64,11 @@ class TestUtilsSimpleLazyObject(TestCase):
|
|||
# proxy __repr__
|
||||
self.assertTrue("SimpleLazyObject" in repr(SimpleLazyObject(complex_object)))
|
||||
|
||||
def test_str(self):
|
||||
self.assertEqual(str_prefix("I am _ComplexObject(%(_)s'joe')"),
|
||||
str(SimpleLazyObject(complex_object)))
|
||||
def test_bytes(self):
|
||||
self.assertEqual(b"I am _ComplexObject('joe')",
|
||||
bytes(SimpleLazyObject(complex_object)))
|
||||
|
||||
def test_unicode(self):
|
||||
def test_text(self):
|
||||
self.assertEqual("joe", six.text_type(SimpleLazyObject(complex_object)))
|
||||
|
||||
def test_class(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue