Esempio n. 1
0
    def _fresh_content_events(self, content_iterable):
        # Header events
        yield yaml.StreamStartEvent()
        yield yaml.DocumentStartEvent()
        yield yaml.MappingStartEvent(None, None, True, flow_style=False)

        # Content events
        for key, value in content_iterable:
            yield yaml.ScalarEvent(None, None, (True, False), key)
            if isinstance(value, dict):
                yield from _yaml_content_events(
                    dict((k, v) for k, v in value.items()
                         if k not in self.CASE_PRIMARY_KEYS))
            elif callable(getattr(value, 'case_data_events')):
                yield yaml.MappingStartEvent(None,
                                             None,
                                             True,
                                             flow_style=False)
                yield from value.case_data_events()
                yield yaml.MappingEndEvent()
            else:
                yield yaml.MappingStartEvent(None,
                                             None,
                                             True,
                                             flow_style=False)
                yield from value
                yield yaml.MappingEndEvent()

        # Tail events
        yield yaml.MappingEndEvent()
        yield yaml.DocumentEndEvent()
        yield yaml.StreamEndEvent()
Esempio n. 2
0
    def _GetYAMLEvents(self):
        events = []
        events.append(yaml.MappingStartEvent(anchor = None, tag = None, implicit = True, flow_style = False))

        # Serialize all properties to yaml pairs
        sorted_keys = sorted(self._ALL_PROPERTIES.keys())
        for k in sorted_keys:
            if k == 'children' and self.HasChildren():
                events.append(yaml.ScalarEvent(anchor = None, tag = None, implicit = (True, True), value = 'children'))
                events.append(yaml.SequenceStartEvent(anchor = None, tag = None, implicit = (True, True)))
                for child in self.GetChildren():
                    events.extend(child._GetYAMLEvents())

                events.append(yaml.SequenceEndEvent())
            else:
                val = str(self._properties[k])
                # Escape input. This must be symmetric with __init__ when loading initial properties
                val = val.replace('"', '\\"').replace('\n', '\\n').replace('\r', '\\r')
                # val = val.replace("'","\\'")

                events.extend([yaml.ScalarEvent(anchor = None, tag = None, implicit = (True, True), value = str(k)),
                               yaml.ScalarEvent(anchor = None, tag = None, implicit = (True, True), value = val),
                               ])

        events.append(yaml.MappingEndEvent())
        return events
Esempio n. 3
0
 def parse_mapping(self):
     self.get_token(yaml.FlowMappingStartToken)
     if not self.check_token(yaml.FlowMappingEndToken):
         self.parse_map_entry()
         while not self.check_token(yaml.FlowMappingEndToken):
             self.get_token(yaml.FlowEntryToken)
             if not self.check_token(yaml.FlowMappingEndToken):
                 self.parse_map_entry()
     self.get_token(yaml.FlowMappingEndToken)
     self.events.append(yaml.MappingEndEvent(None, None))
Esempio n. 4
0
 def augmented_test_case_events(self, case_key, case_id_events):
     """Generate YAML events for a test case
     
     :param str case_key:
         The case key for augmentation
     :param case_id_events:
         An iterable of YAML events representing the key/value pairs of the
         test case identity
     
     This is used internally when extending an updates file with the existing
     data from a case, given the ID of the case as YAML.
     """
     case_augmenter = self._case_augmenters.get(case_key)
     yield yaml.MappingStartEvent(None, None, True, flow_style=False)
     yield from case_id_events
     if case_augmenter is not None:
         yield from case_augmenter.case_data_events()
     yield yaml.MappingEndEvent()
Esempio n. 5
0
 def _full_yaml_mapping_events_from_update_augmentation(cls, augmenter):
     yield yaml.MappingStartEvent(None, None, True, flow_style=False)
     yield from augmenter.case_data_events()
     yield yaml.MappingEndEvent()