1
0
mirror of https://github.com/django/django.git synced 2024-12-23 17:46:27 +00:00
django/tests/utils_tests/test_simplelazyobject.py
Claude Paroz c716fe8782 Refs #23919 -- Removed six.PY2/PY3 usage
Thanks Tim Graham for the review.
2017-01-18 16:21:28 +01:00

23 lines
658 B
Python

import pickle
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils.functional import SimpleLazyObject
class TestUtilsSimpleLazyObjectDjangoTestCase(TestCase):
def test_pickle_py2_regression(self):
# 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.
pickle.dumps(x)
# Try the variant protocol levels.
pickle.dumps(x, 0)
pickle.dumps(x, 1)
pickle.dumps(x, 2)