Fixed serializers tests for PyYAML 5.1+.

This commit is contained in:
Mariusz Felisiak 2019-03-13 20:06:47 +01:00 committed by Tim Graham
parent 782d85b6df
commit a57c783dd4
2 changed files with 9 additions and 7 deletions

View File

@ -115,7 +115,9 @@ class YamlSerializerTestCase(SerializersTestBase, TestCase):
author: %(author_pk)s author: %(author_pk)s
headline: Poker has no place on ESPN headline: Poker has no place on ESPN
pub_date: 2006-06-16 11:00:00 pub_date: 2006-06-16 11:00:00
categories: [%(first_category_pk)s, %(second_category_pk)s] categories:""" + (
' [%(first_category_pk)s, %(second_category_pk)s]' if yaml.__version__ < '5.1'
else '\n - %(first_category_pk)s\n - %(second_category_pk)s') + """
meta_data: [] meta_data: []
""" """

View File

@ -643,7 +643,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30") self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
@ -667,7 +667,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060") self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
@ -691,7 +691,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30.405060+07:00") self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30.405060+07:00")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)
@ -715,7 +715,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 10:20:30+00:00") self.assert_yaml_contains_datetime(data, "2011-09-01 10:20:30+00:00")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)
@ -739,7 +739,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30+03:00") self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30+03:00")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)
@ -763,7 +763,7 @@ class SerializationTests(SimpleTestCase):
self.assertEqual(obj.dt, dt) self.assertEqual(obj.dt, dt)
if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer): if not isinstance(serializers.get_serializer('yaml'), serializers.BadSerializer):
data = serializers.serialize('yaml', [Event(dt=dt)]) data = serializers.serialize('yaml', [Event(dt=dt)], default_flow_style=None)
self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30+07:00") self.assert_yaml_contains_datetime(data, "2011-09-01 17:20:30+07:00")
obj = next(serializers.deserialize('yaml', data)).object obj = next(serializers.deserialize('yaml', data)).object
self.assertEqual(obj.dt.replace(tzinfo=UTC), dt) self.assertEqual(obj.dt.replace(tzinfo=UTC), dt)