From b4a1d545db19bb427af4043ce2c689dad856514f Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 25 Nov 2015 12:31:23 -0500 Subject: [1.9.x] Fixed #25807 -- Instructed the migration writer about lazy objects. Thanks to Trac alias mrgaolei for the report, Baptiste for the confirmation and Tim for the review. Backport of cc2ca9c550fbf8fca8684b373a3c8e3618eea08e from master --- tests/migrations/test_writer.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'tests') diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 12df772df5..b3c41565e3 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -23,6 +23,7 @@ from django.test import SimpleTestCase, ignore_warnings, mock from django.utils import datetime_safe, six from django.utils._os import upath from django.utils.deconstruct import deconstructible +from django.utils.functional import SimpleLazyObject from django.utils.timezone import FixedOffset, get_default_timezone, utc from django.utils.translation import ugettext_lazy as _ @@ -229,6 +230,11 @@ class WriterTests(SimpleTestCase): ("[list, tuple, dict, set, frozenset]", set()) ) + def test_serialize_lazy_objects(self): + pattern = re.compile(r'^foo$', re.UNICODE) + lazy_pattern = SimpleLazyObject(lambda: pattern) + self.assertEqual(self.serialize_round_trip(lazy_pattern), pattern) + def test_serialize_functions(self): with six.assertRaisesRegex(self, ValueError, 'Cannot serialize function: lambda'): self.assertSerializedEqual(lambda x: 42) -- cgit v1.3