Changeset 137 for pyyaml/trunk/tests
- Timestamp:
- 04/16/06 19:45:21 (6 years ago)
- Location:
- pyyaml/trunk/tests
- Files:
-
- 2 added
- 8 modified
- 1 moved
-
data/documents.events (modified) (1 diff)
-
data/mappings.events (modified) (1 diff)
-
data/resolver.data (added)
-
data/resolver.path (added)
-
data/scalars.events (modified) (1 diff)
-
data/sequences.events (modified) (6 diffs)
-
data/sloppy-indentation.canonical (modified) (1 diff)
-
test_appliance.py (modified) (3 diffs)
-
test_emitter.py (modified) (2 diffs)
-
test_resolver.py (moved) (moved from pyyaml/trunk/tests/test_detector.py) (2 diffs)
-
test_yaml.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
pyyaml/trunk/tests/data/documents.events
r132 r137 1 1 - !StreamStart 2 2 - !DocumentStart { explicit: false } 3 - !Scalar { implicit: true, value: 'data' }3 - !Scalar { implicit: [true,false], value: 'data' } 4 4 - !DocumentEnd 5 5 - !DocumentStart 6 - !Scalar { implicit: true}6 - !Scalar { implicit: [true,false] } 7 7 - !DocumentEnd 8 8 - !DocumentStart { version: [1,1], tags: { '!': '!foo', '!yaml!': 'tag:yaml.org,2002:', '!ugly!': '!!!!!!!' } } 9 - !Scalar { implicit: true}9 - !Scalar { implicit: [true,false] } 10 10 - !DocumentEnd 11 11 - !StreamEnd -
pyyaml/trunk/tests/data/mappings.events
r132 r137 3 3 - !DocumentStart 4 4 - !MappingStart 5 - !Scalar { implicit: true, value: 'key' }6 - !Scalar { implicit: true, value: 'value' }7 - !Scalar { implicit: true, value: 'empty mapping' }5 - !Scalar { implicit: [true,true], value: 'key' } 6 - !Scalar { implicit: [true,true], value: 'value' } 7 - !Scalar { implicit: [true,true], value: 'empty mapping' } 8 8 - !MappingStart 9 9 - !MappingEnd 10 - !Scalar { implicit: true, value: 'empty mapping with tag' }11 - !MappingStart { tag: '!mytag' }10 - !Scalar { implicit: [true,true], value: 'empty mapping with tag' } 11 - !MappingStart { tag: '!mytag', implicit: false } 12 12 - !MappingEnd 13 - !Scalar { implicit: true, value: 'block mapping' }13 - !Scalar { implicit: [true,true], value: 'block mapping' } 14 14 - !MappingStart 15 15 - !MappingStart 16 - !Scalar { implicit: true, value: 'complex' }17 - !Scalar { implicit: true, value: 'key' }18 - !Scalar { implicit: true, value: 'complex' }19 - !Scalar { implicit: true, value: 'key' }16 - !Scalar { implicit: [true,true], value: 'complex' } 17 - !Scalar { implicit: [true,true], value: 'key' } 18 - !Scalar { implicit: [true,true], value: 'complex' } 19 - !Scalar { implicit: [true,true], value: 'key' } 20 20 - !MappingEnd 21 21 - !MappingStart 22 - !Scalar { implicit: true, value: 'complex' }23 - !Scalar { implicit: true, value: 'key' }22 - !Scalar { implicit: [true,true], value: 'complex' } 23 - !Scalar { implicit: [true,true], value: 'key' } 24 24 - !MappingEnd 25 25 - !MappingEnd 26 - !Scalar { implicit: true, value: 'flow mapping' }26 - !Scalar { implicit: [true,true], value: 'flow mapping' } 27 27 - !MappingStart { flow_style: true } 28 - !Scalar { implicit: true, value: 'key' }29 - !Scalar { implicit: true, value: 'value' }28 - !Scalar { implicit: [true,true], value: 'key' } 29 - !Scalar { implicit: [true,true], value: 'value' } 30 30 - !MappingStart 31 - !Scalar { implicit: true, value: 'complex' }32 - !Scalar { implicit: true, value: 'key' }33 - !Scalar { implicit: true, value: 'complex' }34 - !Scalar { implicit: true, value: 'key' }31 - !Scalar { implicit: [true,true], value: 'complex' } 32 - !Scalar { implicit: [true,true], value: 'key' } 33 - !Scalar { implicit: [true,true], value: 'complex' } 34 - !Scalar { implicit: [true,true], value: 'key' } 35 35 - !MappingEnd 36 36 - !MappingStart 37 - !Scalar { implicit: true, value: 'complex' }38 - !Scalar { implicit: true, value: 'key' }37 - !Scalar { implicit: [true,true], value: 'complex' } 38 - !Scalar { implicit: [true,true], value: 'key' } 39 39 - !MappingEnd 40 40 - !MappingEnd -
pyyaml/trunk/tests/data/scalars.events
r133 r137 3 3 - !DocumentStart 4 4 - !MappingStart 5 - !Scalar { implicit: true, value: 'empty scalar' }6 - !Scalar { implicit: true, value: '' }7 - !Scalar { implicit: true, value: 'implicit scalar' }8 - !Scalar { implicit: true, value: 'data' }9 - !Scalar { implicit: true, value: 'quoted scalar' }5 - !Scalar { implicit: [true,true], value: 'empty scalar' } 6 - !Scalar { implicit: [true,false], value: '' } 7 - !Scalar { implicit: [true,true], value: 'implicit scalar' } 8 - !Scalar { implicit: [true,true], value: 'data' } 9 - !Scalar { implicit: [true,true], value: 'quoted scalar' } 10 10 - !Scalar { value: 'data', style: '"' } 11 - !Scalar { implicit: true, value: 'block scalar' }11 - !Scalar { implicit: [true,true], value: 'block scalar' } 12 12 - !Scalar { value: 'data', style: '|' } 13 - !Scalar { implicit: true, value: 'empty scalar with tag' }14 - !Scalar { implicit: true, tag: '!mytag', value: '' }15 - !Scalar { implicit: true, value: 'implicit scalar with tag' }16 - !Scalar { implicit: true, tag: '!mytag', value: 'data' }17 - !Scalar { implicit: true, value: 'quoted scalar with tag' }18 - !Scalar { value: 'data', style: '"', tag: '!mytag' }19 - !Scalar { implicit: true, value: 'block scalar with tag' }20 - !Scalar { value: 'data', style: '|', tag: '!mytag' }21 - !Scalar { implicit: true, value: 'single character' }22 - !Scalar { value: 'a', implicit: true}23 - !Scalar { implicit: true, value: 'single digit' }24 - !Scalar { value: '1', implicit: true}13 - !Scalar { implicit: [true,true], value: 'empty scalar with tag' } 14 - !Scalar { implicit: [false,false], tag: '!mytag', value: '' } 15 - !Scalar { implicit: [true,true], value: 'implicit scalar with tag' } 16 - !Scalar { implicit: [false,false], tag: '!mytag', value: 'data' } 17 - !Scalar { implicit: [true,true], value: 'quoted scalar with tag' } 18 - !Scalar { value: 'data', style: '"', tag: '!mytag', implicit: [false,false] } 19 - !Scalar { implicit: [true,true], value: 'block scalar with tag' } 20 - !Scalar { value: 'data', style: '|', tag: '!mytag', implicit: [false,false] } 21 - !Scalar { implicit: [true,true], value: 'single character' } 22 - !Scalar { value: 'a', implicit: [true,true] } 23 - !Scalar { implicit: [true,true], value: 'single digit' } 24 - !Scalar { value: '1', implicit: [true,false] } 25 25 - !MappingEnd 26 26 - !DocumentEnd -
pyyaml/trunk/tests/data/sequences.events
r132 r137 7 7 8 8 - !DocumentStart 9 - !SequenceStart { tag: '!mytag' }9 - !SequenceStart { tag: '!mytag', implicit: false } 10 10 - !SequenceEnd 11 11 - !DocumentEnd … … 15 15 - !SequenceStart 16 16 - !SequenceEnd 17 - !SequenceStart { tag: '!mytag' }17 - !SequenceStart { tag: '!mytag', implicit: false } 18 18 - !SequenceEnd 19 19 - !SequenceStart 20 20 - !Scalar 21 21 - !Scalar { value: 'data' } 22 - !Scalar { tag: '!mytag', value: 'data' }22 - !Scalar { tag: '!mytag', implicit: [false,false], value: 'data' } 23 23 - !SequenceEnd 24 24 - !SequenceStart … … 30 30 - !SequenceEnd 31 31 - !SequenceStart 32 - !SequenceStart { tag: '!mytag' }32 - !SequenceStart { tag: '!mytag', implicit: false } 33 33 - !SequenceStart 34 34 - !Scalar { value: 'data' } … … 48 48 - !SequenceEnd 49 49 - !Scalar { value: 'key2' } 50 - !SequenceStart { tag: '!mytag1' }50 - !SequenceStart { tag: '!mytag1', implicit: false } 51 51 - !Scalar { value: 'data3' } 52 52 - !SequenceStart … … 54 54 - !Scalar { value: 'data5' } 55 55 - !SequenceEnd 56 - !SequenceStart { tag: '!mytag2' }56 - !SequenceStart { tag: '!mytag2', implicit: false } 57 57 - !Scalar { value: 'data6' } 58 58 - !Scalar { value: 'data7' } … … 70 70 - !Scalar 71 71 - !Scalar { value: 'data' } 72 - !Scalar { tag: '!mytag', value: 'data' }73 - !SequenceStart { tag: '!mytag' }72 - !Scalar { tag: '!mytag', implicit: [false,false], value: 'data' } 73 - !SequenceStart { tag: '!mytag', implicit: false } 74 74 - !Scalar { value: 'data' } 75 75 - !Scalar { value: 'data' } -
pyyaml/trunk/tests/data/sloppy-indentation.canonical
r117 r137 16 16 "the parser does not require scalars to be indented with at least one space" 17 17 --- !!map 18 { ? !!str "foo": { ? !!str "bar" : "quoted scalars may not adhere indentation" } }18 { ? !!str "foo": { ? !!str "bar" : !!str "quoted scalars may not adhere indentation" } } -
pyyaml/trunk/tests/test_appliance.py
r136 r137 263 263 tag = self.get_token_value() 264 264 if self.check_token(ScalarToken): 265 self.events.append(ScalarEvent(anchor, tag, False, self.get_token_value(), None, None))265 self.events.append(ScalarEvent(anchor, tag, (False, False), self.get_token_value(), None, None)) 266 266 elif self.check_token(FlowSequenceStartToken): 267 267 self.events.append(SequenceStartEvent(anchor, tag, None, None)) … … 322 322 return self.events[0] 323 323 324 class CanonicalLoader(CanonicalScanner, CanonicalParser, Composer, Constructor, Detector):324 class CanonicalLoader(CanonicalScanner, CanonicalParser, Composer, Constructor, Resolver): 325 325 326 326 def __init__(self, stream): … … 331 331 Composer.__init__(self) 332 332 Constructor.__init__(self) 333 Detector.__init__(self)333 Resolver.__init__(self) 334 334 335 335 def canonical_scan(stream): -
pyyaml/trunk/tests/test_emitter.py
r136 r137 31 31 if isinstance(event, ScalarEvent): 32 32 #self.failUnlessEqual(event.implicit, new_event.implicit) 33 if not event.implicit and notnew_event.implicit:33 if True not in event.implicit+new_event.implicit: 34 34 self.failUnlessEqual(event.tag, new_event.tag) 35 35 self.failUnlessEqual(event.value, new_event.value) … … 59 59 if class_name in ['ScalarEvent', 'SequenceStartEvent', 'MappingStartEvent']: 60 60 mapping.setdefault('tag', None) 61 if class_name in ['SequenceStartEvent', 'MappingStartEvent']: 62 mapping.setdefault('implicit', True) 61 63 if class_name == 'ScalarEvent': 62 mapping.setdefault('implicit', False)64 mapping.setdefault('implicit', (False, True)) 63 65 mapping.setdefault('value', '') 64 66 value = getattr(yaml, class_name)(**mapping) -
pyyaml/trunk/tests/test_resolver.py
r136 r137 4 4 from yaml import * 5 5 6 class TestDetector(test_appliance.TestAppliance): 6 class MyLoader(Loader): 7 pass 7 8 8 def _testDetector(self, test_name, data_filename, detect_filename): 9 class MyDumper(Dumper): 10 pass 11 12 add_path_resolver(u'!root', [], 13 Loader=MyLoader, Dumper=MyDumper) 14 15 add_path_resolver(u'!root/scalar', [], str, 16 Loader=MyLoader, Dumper=MyDumper) 17 18 add_path_resolver(u'!root/key11/key12/*', ['key11', 'key12'], 19 Loader=MyLoader, Dumper=MyDumper) 20 21 add_path_resolver(u'!root/key21/1/*', ['key21', 1], 22 Loader=MyLoader, Dumper=MyDumper) 23 24 add_path_resolver(u'!root/key31/*/*/key14/map', ['key31', None, None, 'key14'], map, 25 Loader=MyLoader, Dumper=MyDumper) 26 27 class TestResolver(test_appliance.TestAppliance): 28 29 def _testImplicitResolver(self, test_name, data_filename, detect_filename): 9 30 node = None 10 31 correct_tag = None … … 26 47 raise 27 48 28 TestDetector.add_tests('testDetector', '.data', '.detect') 49 def _testPathResolverLoader(self, test_name, data_filename, path_filename): 50 #print serialize_all(compose_all(file(data_filename, 'rb').read(), Loader=MyLoader)) 51 nodes1 = compose_all(file(data_filename, 'rb').read(), Loader=MyLoader) 52 nodes2 = compose_all(file(path_filename, 'rb').read()) 53 for node1, node2 in zip(nodes1, nodes2): 54 self.failUnlessEqual(self._convert(node1), self._convert(node2)) 29 55 56 def _testPathResolverDumper(self, test_name, data_filename, path_filename): 57 for filename in [data_filename, path_filename]: 58 output = serialize_all(compose_all(file(filename, 'rb').read()), Dumper=MyDumper) 59 #print output 60 nodes1 = compose_all(output) 61 nodes2 = compose_all(file(data_filename, 'rb').read()) 62 for node1, node2 in zip(nodes1, nodes2): 63 self.failUnlessEqual(self._convert(node1), self._convert(node2)) 64 65 def _convert(self, node): 66 if isinstance(node, ScalarNode): 67 return node.tag, node.value 68 elif isinstance(node, SequenceNode): 69 value = [] 70 for item in node.value: 71 value.append(self._convert(item)) 72 return node.tag, value 73 elif isinstance(node, MappingNode): 74 value = [] 75 for key in node.value: 76 item = node.value[key] 77 value.append((self._convert(key), self._convert(item))) 78 value.sort() 79 return node.tag, value 80 81 TestResolver.add_tests('testImplicitResolver', '.data', '.detect') 82 TestResolver.add_tests('testPathResolverLoader', '.data', '.path') 83 TestResolver.add_tests('testPathResolverDumper', '.data', '.path') 84 -
pyyaml/trunk/tests/test_yaml.py
r133 r137 8 8 from test_structure import * 9 9 from test_errors import * 10 from test_ detector import *10 from test_resolver import * 11 11 from test_constructor import * 12 12 from test_emitter import *
