| 1 | |
|---|
| 2 | import test_appliance |
|---|
| 3 | from test_constructor import * |
|---|
| 4 | |
|---|
| 5 | from yaml import * |
|---|
| 6 | |
|---|
| 7 | class TestRepresenterTypes(test_appliance.TestAppliance): |
|---|
| 8 | |
|---|
| 9 | def _testTypes(self, test_name, data_filename, code_filename): |
|---|
| 10 | data1 = eval(file(code_filename, 'rb').read()) |
|---|
| 11 | data2 = None |
|---|
| 12 | output = None |
|---|
| 13 | try: |
|---|
| 14 | output = dump(data1, Dumper=MyDumper) |
|---|
| 15 | data2 = load(output, Loader=MyLoader) |
|---|
| 16 | self.failUnlessEqual(type(data1), type(data2)) |
|---|
| 17 | try: |
|---|
| 18 | self.failUnlessEqual(data1, data2) |
|---|
| 19 | except AssertionError: |
|---|
| 20 | if isinstance(data1, dict): |
|---|
| 21 | data1 = [(repr(key), value) for key, value in data1.items()] |
|---|
| 22 | data1.sort() |
|---|
| 23 | data1 = repr(data1) |
|---|
| 24 | data2 = [(repr(key), value) for key, value in data2.items()] |
|---|
| 25 | data2.sort() |
|---|
| 26 | data2 = repr(data2) |
|---|
| 27 | if data1 != data2: |
|---|
| 28 | raise |
|---|
| 29 | elif isinstance(data1, list): |
|---|
| 30 | self.failUnlessEqual(type(data1), type(data2)) |
|---|
| 31 | self.failUnlessEqual(len(data1), len(data2)) |
|---|
| 32 | for item1, item2 in zip(data1, data2): |
|---|
| 33 | self.failUnlessEqual(item1, item2) |
|---|
| 34 | else: |
|---|
| 35 | raise |
|---|
| 36 | except: |
|---|
| 37 | print |
|---|
| 38 | print "OUTPUT:" |
|---|
| 39 | print output |
|---|
| 40 | print "NATIVES1:", data1 |
|---|
| 41 | print "NATIVES2:", data2 |
|---|
| 42 | raise |
|---|
| 43 | |
|---|
| 44 | TestRepresenterTypes.add_tests('testTypes', '.data', '.code') |
|---|
| 45 | |
|---|