Changeset 137 for pyyaml/trunk/tests

Show
Ignore:
Timestamp:
04/16/06 19:45:21 (6 years ago)
Author:
xi
Message:

Refactor resolver.

Location:
pyyaml/trunk/tests
Files:
2 added
8 modified
1 moved

Legend:

Unmodified
Added
Removed
  • pyyaml/trunk/tests/data/documents.events

    r132 r137  
    11- !StreamStart 
    22- !DocumentStart { explicit: false } 
    3 - !Scalar { implicit: true, value: 'data' } 
     3- !Scalar { implicit: [true,false], value: 'data' } 
    44- !DocumentEnd 
    55- !DocumentStart 
    6 - !Scalar { implicit: true } 
     6- !Scalar { implicit: [true,false] } 
    77- !DocumentEnd 
    88- !DocumentStart { version: [1,1], tags: { '!': '!foo', '!yaml!': 'tag:yaml.org,2002:', '!ugly!': '!!!!!!!' } } 
    9 - !Scalar { implicit: true } 
     9- !Scalar { implicit: [true,false] } 
    1010- !DocumentEnd 
    1111- !StreamEnd 
  • pyyaml/trunk/tests/data/mappings.events

    r132 r137  
    33- !DocumentStart 
    44- !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' } 
    88- !MappingStart 
    99- !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 } 
    1212- !MappingEnd 
    13 - !Scalar { implicit: true, value: 'block mapping' } 
     13- !Scalar { implicit: [true,true], value: 'block mapping' } 
    1414- !MappingStart 
    1515- !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' } 
    2020- !MappingEnd 
    2121- !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' } 
    2424- !MappingEnd 
    2525- !MappingEnd 
    26 - !Scalar { implicit: true, value: 'flow mapping' } 
     26- !Scalar { implicit: [true,true], value: 'flow mapping' } 
    2727- !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' } 
    3030- !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' } 
    3535- !MappingEnd 
    3636- !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' } 
    3939- !MappingEnd 
    4040- !MappingEnd 
  • pyyaml/trunk/tests/data/scalars.events

    r133 r137  
    33- !DocumentStart 
    44- !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' } 
    1010- !Scalar { value: 'data', style: '"' } 
    11 - !Scalar { implicit: true, value: 'block scalar' } 
     11- !Scalar { implicit: [true,true], value: 'block scalar' } 
    1212- !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] } 
    2525- !MappingEnd 
    2626- !DocumentEnd 
  • pyyaml/trunk/tests/data/sequences.events

    r132 r137  
    77 
    88- !DocumentStart 
    9 - !SequenceStart { tag: '!mytag' } 
     9- !SequenceStart { tag: '!mytag', implicit: false } 
    1010- !SequenceEnd 
    1111- !DocumentEnd 
     
    1515- !SequenceStart 
    1616- !SequenceEnd 
    17 - !SequenceStart { tag: '!mytag' } 
     17- !SequenceStart { tag: '!mytag', implicit: false } 
    1818- !SequenceEnd 
    1919- !SequenceStart 
    2020- !Scalar 
    2121- !Scalar { value: 'data' } 
    22 - !Scalar { tag: '!mytag', value: 'data' } 
     22- !Scalar { tag: '!mytag', implicit: [false,false], value: 'data' } 
    2323- !SequenceEnd 
    2424- !SequenceStart 
     
    3030- !SequenceEnd 
    3131- !SequenceStart 
    32 - !SequenceStart { tag: '!mytag' } 
     32- !SequenceStart { tag: '!mytag', implicit: false } 
    3333- !SequenceStart 
    3434- !Scalar { value: 'data' } 
     
    4848- !SequenceEnd 
    4949- !Scalar { value: 'key2' } 
    50 - !SequenceStart { tag: '!mytag1' } 
     50- !SequenceStart { tag: '!mytag1', implicit: false } 
    5151- !Scalar { value: 'data3' } 
    5252- !SequenceStart 
     
    5454- !Scalar { value: 'data5' } 
    5555- !SequenceEnd 
    56 - !SequenceStart { tag: '!mytag2' } 
     56- !SequenceStart { tag: '!mytag2', implicit: false } 
    5757- !Scalar { value: 'data6' } 
    5858- !Scalar { value: 'data7' } 
     
    7070- !Scalar 
    7171- !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 } 
    7474- !Scalar { value: 'data' } 
    7575- !Scalar { value: 'data' } 
  • pyyaml/trunk/tests/data/sloppy-indentation.canonical

    r117 r137  
    1616"the parser does not require scalars to be indented with at least one space" 
    1717--- !!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  
    263263                tag = self.get_token_value() 
    264264            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)) 
    266266            elif self.check_token(FlowSequenceStartToken): 
    267267                self.events.append(SequenceStartEvent(anchor, tag, None, None)) 
     
    322322        return self.events[0] 
    323323 
    324 class CanonicalLoader(CanonicalScanner, CanonicalParser, Composer, Constructor, Detector): 
     324class CanonicalLoader(CanonicalScanner, CanonicalParser, Composer, Constructor, Resolver): 
    325325 
    326326    def __init__(self, stream): 
     
    331331        Composer.__init__(self) 
    332332        Constructor.__init__(self) 
    333         Detector.__init__(self) 
     333        Resolver.__init__(self) 
    334334 
    335335def canonical_scan(stream): 
  • pyyaml/trunk/tests/test_emitter.py

    r136 r137  
    3131            if isinstance(event, ScalarEvent): 
    3232                #self.failUnlessEqual(event.implicit, new_event.implicit) 
    33                 if not event.implicit and not new_event.implicit: 
     33                if True not in event.implicit+new_event.implicit: 
    3434                    self.failUnlessEqual(event.tag, new_event.tag) 
    3535                self.failUnlessEqual(event.value, new_event.value) 
     
    5959        if class_name in ['ScalarEvent', 'SequenceStartEvent', 'MappingStartEvent']: 
    6060            mapping.setdefault('tag', None) 
     61        if class_name in ['SequenceStartEvent', 'MappingStartEvent']: 
     62            mapping.setdefault('implicit', True) 
    6163        if class_name == 'ScalarEvent': 
    62             mapping.setdefault('implicit', False) 
     64            mapping.setdefault('implicit', (False, True)) 
    6365            mapping.setdefault('value', '') 
    6466        value = getattr(yaml, class_name)(**mapping) 
  • pyyaml/trunk/tests/test_resolver.py

    r136 r137  
    44from yaml import * 
    55 
    6 class TestDetector(test_appliance.TestAppliance): 
     6class MyLoader(Loader): 
     7    pass 
    78 
    8     def _testDetector(self, test_name, data_filename, detect_filename): 
     9class MyDumper(Dumper): 
     10    pass 
     11 
     12add_path_resolver(u'!root', [], 
     13        Loader=MyLoader, Dumper=MyDumper) 
     14 
     15add_path_resolver(u'!root/scalar', [], str, 
     16        Loader=MyLoader, Dumper=MyDumper) 
     17 
     18add_path_resolver(u'!root/key11/key12/*', ['key11', 'key12'], 
     19        Loader=MyLoader, Dumper=MyDumper) 
     20 
     21add_path_resolver(u'!root/key21/1/*', ['key21', 1], 
     22        Loader=MyLoader, Dumper=MyDumper) 
     23 
     24add_path_resolver(u'!root/key31/*/*/key14/map', ['key31', None, None, 'key14'], map, 
     25        Loader=MyLoader, Dumper=MyDumper) 
     26 
     27class TestResolver(test_appliance.TestAppliance): 
     28 
     29    def _testImplicitResolver(self, test_name, data_filename, detect_filename): 
    930        node = None 
    1031        correct_tag = None 
     
    2647            raise 
    2748 
    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)) 
    2955 
     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 
     81TestResolver.add_tests('testImplicitResolver', '.data', '.detect') 
     82TestResolver.add_tests('testPathResolverLoader', '.data', '.path') 
     83TestResolver.add_tests('testPathResolverDumper', '.data', '.path') 
     84 
  • pyyaml/trunk/tests/test_yaml.py

    r133 r137  
    88from test_structure import * 
    99from test_errors import * 
    10 from test_detector import * 
     10from test_resolver import * 
    1111from test_constructor import * 
    1212from test_emitter import *