Fixed #15 (pyyaml discards '-' sign on negative floats).
[pyyaml/python3.git] / tests / test_representer.py
blobe0fa894b358694edba01d1c28234796f1d45d85c
2 import test_appliance
3 from test_constructor import *
5 from yaml 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())
14 data2 = None
15 output = None
16 try:
17 output = dump(data1, Dumper=MyDumper, allow_unicode=allow_unicode)
18 data2 = load(output, Loader=MyLoader)
19 self.failUnlessEqual(type(data1), type(data2))
20 try:
21 self.failUnlessEqual(data1, data2)
22 except AssertionError:
23 if isinstance(data1, dict):
24 data1 = [(repr(key), value) for key, value in data1.items()]
25 data1.sort()
26 data1 = repr(data1)
27 data2 = [(repr(key), value) for key, value in data2.items()]
28 data2.sort()
29 data2 = repr(data2)
30 if data1 != data2:
31 raise
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 self.failUnlessEqual(item1, item2)
37 else:
38 raise
39 except:
40 print
41 print "OUTPUT:"
42 print output
43 print "NATIVES1:", data1
44 print "NATIVES2:", data2
45 raise
47 TestRepresenterTypes.add_tests('testTypes', '.data', '.code')
48 TestRepresenterTypes.add_tests('testTypesUnicode', '.data', '.code')