2012-06-07 16:08:47 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2011-12-15 02:33:14 +00:00
|
|
|
import pickle
|
2010-09-27 15:15:04 +00:00
|
|
|
|
2013-09-18 13:35:51 +00:00
|
|
|
from django.contrib.auth.models import User
|
2014-01-29 04:53:30 +00:00
|
|
|
from django.test import TestCase
|
2012-07-20 12:48:51 +00:00
|
|
|
from django.utils import six
|
2014-01-29 04:53:30 +00:00
|
|
|
from django.utils.functional import SimpleLazyObject
|
2011-06-01 15:30:06 +00:00
|
|
|
|
2010-09-27 15:15:04 +00:00
|
|
|
|
2014-01-29 04:53:30 +00:00
|
|
|
class TestUtilsSimpleLazyObjectDjangoTestCase(TestCase):
|
2013-05-21 05:17:56 +00:00
|
|
|
|
2013-09-18 13:35:51 +00:00
|
|
|
def test_pickle_py2_regression(self):
|
2013-05-21 05:17:56 +00:00
|
|
|
# See ticket #20212
|
|
|
|
user = User.objects.create_user('johndoe', 'john@example.com', 'pass')
|
|
|
|
x = SimpleLazyObject(lambda: user)
|
|
|
|
|
|
|
|
# This would fail with "TypeError: can't pickle instancemethod objects",
|
|
|
|
# only on Python 2.X.
|
2013-10-19 12:31:38 +00:00
|
|
|
pickle.dumps(x)
|
2013-05-21 05:17:56 +00:00
|
|
|
|
|
|
|
# Try the variant protocol levels.
|
2013-10-19 12:31:38 +00:00
|
|
|
pickle.dumps(x, 0)
|
|
|
|
pickle.dumps(x, 1)
|
|
|
|
pickle.dumps(x, 2)
|
2013-05-21 05:17:56 +00:00
|
|
|
|
2013-09-02 10:06:32 +00:00
|
|
|
if six.PY2:
|
2013-05-21 05:17:56 +00:00
|
|
|
import cPickle
|
|
|
|
|
|
|
|
# This would fail with "TypeError: expected string or Unicode object, NoneType found".
|
2013-10-19 12:31:38 +00:00
|
|
|
cPickle.dumps(x)
|