From 9587d4eea09bc8d8a852dfb24c2a9227c74fd8ad Mon Sep 17 00:00:00 2001 From: Roberto Aguilar Date: Fri, 6 Sep 2013 22:22:04 +0000 Subject: [PATCH] Fixed existing tests to handle BadSerializer. When a BadSerializer instance is stubbed in for the yaml serializer, make sure tests do not fail. --- tests/serializers_regress/tests.py | 2 +- tests/timezones/tests.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/serializers_regress/tests.py b/tests/serializers_regress/tests.py index 3173f73985..0a8267a33b 100644 --- a/tests/serializers_regress/tests.py +++ b/tests/serializers_regress/tests.py @@ -523,7 +523,7 @@ def streamTest(format, self): else: self.assertEqual(string_data, stream.content.decode('utf-8')) -for format in serializers.get_serializer_formats(): +for format in filter(lambda x: not isinstance(serializers.get_serializer(x), serializers.BadSerializer), serializers.get_serializer_formats()): setattr(SerializerTests, 'test_' + format + '_serializer', curry(serializerTest, format)) setattr(SerializerTests, 'test_' + format + '_natural_key_serializer', curry(naturalKeySerializerTest, format)) setattr(SerializerTests, 'test_' + format + '_serializer_fields', curry(fieldsTest, format)) diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index 49169f90f2..9390eb93df 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -599,7 +599,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30") obj = next(serializers.deserialize('yaml', data)).object @@ -623,7 +623,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060") obj = next(serializers.deserialize('yaml', data)).object @@ -647,7 +647,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30.405060+07:00") obj = next(serializers.deserialize('yaml', data)).object @@ -671,7 +671,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 10:20:30+00:00") obj = next(serializers.deserialize('yaml', data)).object @@ -695,7 +695,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30+03:00") obj = next(serializers.deserialize('yaml', data)).object @@ -719,7 +719,7 @@ class SerializationTests(TestCase): obj = next(serializers.deserialize('xml', data)).object self.assertEqual(obj.dt, dt) - if 'yaml' in serializers.get_serializer_formats(): + if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): data = serializers.serialize('yaml', [Event(dt=dt)]) self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30+07:00") obj = next(serializers.deserialize('yaml', data)).object