Changeset 55 for branches/pyyaml3000/tests/test_structure.py
- Timestamp:
- 02/22/06 19:18:34 (7 years ago)
- File:
-
- 1 edited
-
branches/pyyaml3000/tests/test_structure.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pyyaml3000/tests/test_structure.py
r54 r55 7 7 from yaml.composer import * 8 8 from yaml.resolver import * 9 from yaml.constructor import * 9 10 from yaml.nodes import * 10 11 … … 138 139 elif isinstance(node1, MappingNode): 139 140 self.failUnlessEqual(len(node1.value), len(node2.value)) 140 for (key1, value1), (key2, value2) in zip(node1.value, node2.value): 141 items1 = node1.value.items() 142 items1.sort(lambda (k1,v1), (k2,v2): cmp((k1.tag,k1.value,v1.tag,v1.value), 143 (k2.tag,k2.value,v2.tag,v2.value))) 144 items2 = node2.value.items() 145 items2.sort(lambda (k1,v1), (k2,v2): cmp((k1.tag,k1.value,v1.tag,v1.value), 146 (k2.tag,k2.value,v2.tag,v2.value))) 147 for (key1, value1), (key2, value2) in zip(items1, items2): 141 148 self._compare(key1, key2) 142 149 self._compare(value1, value2) 143 150 144 151 TestResolver.add_tests('testResolver', '.data', '.canonical') 152 153 class MyConstructor(Constructor): 154 155 def construct_sequence(self, node): 156 return tuple(Constructor.construct_sequence(self, node)) 157 158 def construct_mapping(self, node): 159 pairs = self.construct_pairs(node) 160 pairs.sort() 161 return pairs 162 163 class TestConstructor(test_appliance.TestAppliance): 164 165 def _testConstructor(self, test_name, data_filename, canonical_filename): 166 natives1 = None 167 natives2 = None 168 try: 169 constructor1 = MyConstructor(Resolver(Composer(Parser(Scanner(Reader(file(data_filename, 'rb'))))))) 170 natives1 = list(iter(constructor1)) 171 canonical = test_appliance.CanonicalParser(file(canonical_filename, 'rb').read()) 172 canonical.parse() 173 constructor2 = MyConstructor(Resolver(Composer(canonical))) 174 natives2 = list(iter(constructor2)) 175 self.failUnlessEqual(natives1, natives2) 176 except: 177 print 178 print "DATA1:" 179 print file(data_filename, 'rb').read() 180 print "DATA2:" 181 print file(canonical_filename, 'rb').read() 182 print "NATIVES1:", natives1 183 print "NATIVES2:", natives2 184 raise 185 186 TestConstructor.add_tests('testConstructor', '.data', '.canonical') 145 187 146 188 class TestParserOnCanonical(test_appliance.TestAppliance):
Note: See TracChangeset
for help on using the changeset viewer.
