3 from test_constructor
import *
7 class TestRepresenterTypes(test_appliance
.TestAppliance
):
9 def _testTypesUnicode(self
, test_name
, data_filename
, code_filename
):
10 return self
._testTypes
(test_name
, data_filename
, code_filename
, allow_unicode
=True)
12 def _testTypes(self
, test_name
, data_filename
, code_filename
, allow_unicode
=False):
13 data1
= eval(file(code_filename
, 'rb').read())
17 output
= dump(data1
, Dumper
=MyDumper
, allow_unicode
=allow_unicode
)
18 data2
= load(output
, Loader
=MyLoader
)
19 self
.failUnlessEqual(type(data1
), type(data2
))
21 self
.failUnlessEqual(data1
, data2
)
22 except (AssertionError, TypeError):
23 if isinstance(data1
, dict):
24 data1
= [(repr(key
), value
) for key
, value
in data1
.items()]
27 data2
= [(repr(key
), value
) for key
, value
in data2
.items()]
32 elif isinstance(data1
, list):
33 self
.failUnlessEqual(type(data1
), type(data2
))
34 self
.failUnlessEqual(len(data1
), len(data2
))
35 for item1
, item2
in zip(data1
, data2
):
36 if (item1
!= item1
or (item1
== 0.0 and item1
== 1.0)) and \
37 (item2
!= item2
or (item2
== 0.0 and item2
== 1.0)):
39 if isinstance(item1
, datetime
.datetime
) \
40 and isinstance(item2
, datetime
.datetime
):
41 self
.failUnlessEqual(item1
.microsecond
,
43 if isinstance(item1
, datetime
.datetime
):
44 item1
= item1
.utctimetuple()
45 if isinstance(item2
, datetime
.datetime
):
46 item2
= item2
.utctimetuple()
47 self
.failUnlessEqual(item1
, item2
)
54 print "NATIVES1:", data1
55 print "NATIVES2:", data2
58 TestRepresenterTypes
.add_tests('testTypes', '.data', '.code')
59 TestRepresenterTypes
.add_tests('testTypesUnicode', '.data', '.code')