11# SPDX-License-Identifier: Apache-2.0
22# Copyright Contributors to the OpenTimelineIO project
33
4- import unittest
4+ import json
55import sys
6+ import unittest
67
7- import opentimelineio as otio
88import opentimelineio .test_utils as otio_test_utils
99
10+ import opentimelineio as otio
11+
1012
1113class V2dTests (unittest .TestCase , otio_test_utils .OTIOAssertions ):
1214 def test_cons (self ):
@@ -21,15 +23,9 @@ def test_cons(self):
2123 def test_str (self ):
2224 v = otio .schema .V2d (1.0 , 2.0 )
2325
24- self .assertMultiLineEqual (
25- str (v ),
26- 'V2d(1.0, 2.0)'
27- )
26+ self .assertMultiLineEqual (str (v ), "V2d(1.0, 2.0)" )
2827
29- self .assertMultiLineEqual (
30- repr (v ),
31- 'otio.schema.V2d(x=1.0, y=2.0)'
32- )
28+ self .assertMultiLineEqual (repr (v ), "otio.schema.V2d(x=1.0, y=2.0)" )
3329
3430 def test_equality (self ):
3531 v1 = otio .schema .V2d (1.0 , 2.0 )
@@ -104,6 +100,17 @@ def test_limits(self):
104100 self .assertEqual (otio .schema .V2d .baseTypeSmallest (), sys .float_info .min )
105101 self .assertEqual (otio .schema .V2d .baseTypeEpsilon (), sys .float_info .epsilon )
106102
103+ def test_json_serialization (self ):
104+ serialized = otio .adapters .otio_json .write_to_string (otio .schema .V2d ())
105+ json_v2d = json .loads (serialized )
106+ self .assertEqual (json_v2d ["OTIO_SCHEMA" ], "V2d.1" )
107+
108+ def test_serialization_round_trip (self ):
109+ v2d = otio .schema .V2d ()
110+ serialized = otio .adapters .otio_json .write_to_string (v2d )
111+ deserialized = otio .adapters .otio_json .read_from_string (serialized )
112+ self .assertEqual (v2d , deserialized )
113+
107114
108- if __name__ == ' __main__' :
115+ if __name__ == " __main__" :
109116 unittest .main ()
0 commit comments