Changeset 136 for pyyaml/trunk/tests/test_representer.py
- Timestamp:
- 04/15/06 19:54:52 (7 years ago)
- File:
-
- 1 edited
-
pyyaml/trunk/tests/test_representer.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/tests/test_representer.py
r133 r136 13 13 from yaml import * 14 14 15 class My Constructor(Constructor):15 class MyLoader(Loader): 16 16 pass 17 class My Representer(Representer):17 class MyDumper(Dumper): 18 18 pass 19 19 … … 39 39 class MyTestClass2(MyTestClass1, YAMLObject): 40 40 41 yaml_constructor = MyConstructor 41 yaml_loader = MyLoader 42 yaml_dumper = MyDumper 42 43 yaml_tag = "!tag2" 43 44 … … 68 69 to_yaml = classmethod(to_yaml) 69 70 70 MyConstructor.add_constructor("!tag1", construct1) 71 MyRepresenter.add_representer(MyTestClass1, represent1) 71 MyLoader.add_constructor("!tag1", construct1) 72 MyDumper.add_representer(MyTestClass1, represent1) 73 74 class YAMLObject1(YAMLObject): 75 yaml_loader = MyLoader 76 yaml_dumper = MyDumper 77 yaml_tag = '!foo' 78 yaml_flow_style = True 79 80 def __init__(self, my_parameter=None, my_another_parameter=None): 81 self.my_parameter = my_parameter 82 self.my_another_parameter = my_another_parameter 83 84 def __eq__(self, other): 85 if isinstance(other, YAMLObject1): 86 return self.__class__, self.__dict__ == other.__class__, other.__dict__ 87 else: 88 return False 72 89 73 90 class TestTypeRepresenter(test_appliance.TestAppliance): 74 91 75 92 def _testTypes(self, test_name, data_filename, code_filename): 76 natives1 = eval(file(code_filename, 'rb').read())77 natives2 = None93 data1 = eval(file(code_filename, 'rb').read()) 94 data2 = None 78 95 output = None 79 96 try: 80 output = dump( natives1, Representer=MyRepresenter)81 natives2 = load(output, Constructor=MyConstructor)97 output = dump(data1, Dumper=MyDumper) 98 data2 = load(output, Loader=MyLoader) 82 99 try: 83 self.failUnlessEqual( natives1, natives2)100 self.failUnlessEqual(data1, data2) 84 101 except AssertionError: 85 if isinstance( natives1, dict):86 natives1 = natives1.items()87 natives1.sort()88 natives1 = repr(natives1)89 natives2 = natives2.items()90 natives2.sort()91 natives2 = repr(natives2)92 if natives1 != natives2:102 if isinstance(data1, dict): 103 data1 = data1.items() 104 data1.sort() 105 data1 = repr(data1) 106 data2 = data2.items() 107 data2.sort() 108 data2 = repr(data2) 109 if data1 != data2: 93 110 raise 94 111 except: … … 96 113 print "OUTPUT:" 97 114 print output 98 print "NATIVES1:", natives199 print "NATIVES2:", natives2115 print "NATIVES1:", data1 116 print "NATIVES2:", data2 100 117 raise 101 118
Note: See TracChangeset
for help on using the changeset viewer.
