def __str__(self): output = collections.OrderedDict() output[self._message_path] = self._yaml_path output['repeatable'] = self._repeatable submessage_template_str_array = [] if self._submessage_template: for descriptor in self._submessage_template.values(): submessage_template_str_array.append(str(descriptor)) output['submessage_template'] = submessage_template_str_array or None yaml.convert_to_block_text(output) return yaml.dump(output, round_trip=True)
def GenerateMappingFileTemplate(api_name, message_type, skip_fields=None, file_path=None, api_version=None, known_mappings=None): """Create a stub Apitools To KRM mapping file for specified Apitools message. Args: api_name: string, The api containing the message. message_type: string, The message to generate mapping for. skip_fields: [string], A list of field paths to exclude from mapping file. file_path: string, path of destination file. If None, will write result to stdout. api_version: Version of the api to retrieve the message type from. If None will use default API version. known_mappings: {string: object}, Fields to pre-initialize in the mapping. Returns: The path to the created file or file contents if no path specified. Raises: InvalidDataError, if api or message are invalid. """ try: api_obj = registry.GetAPI(api_name, api_version) all_messages = api_obj.GetMessagesModule() message = getattr(all_messages, message_type) mapping_object = _BuildYamlMappingTemplateFromMessage(message) if skip_fields: # Remove Skipped/Unmapped message fields for path in skip_fields: file_parsers.DeleteItemInDict(mapping_object, path) if known_mappings: for path, value in six.iteritems(known_mappings): file_parsers.FindOrSetItemInDict(mapping_object, path, set_value=value) yaml.convert_to_block_text(mapping_object) output = yaml.dump(mapping_object, round_trip=True) if file_path: files.WriteFileAtomically(file_path, output) output = file_path return output except (AttributeError, registry.Error) as ae: raise InvalidDataError('Error retrieving message [{message}] from ' 'API [{api}/{ver}] :: {error}'.format( message=message_type, api=api_name, ver=api_version or 'default', error=ae))
def UpdateSummary(self, scenario_context): """Generates and updates the summary for the entire scenario run.""" steps = [] for a in self.LoadActions(): steps.extend(a.Summary()) yaml.convert_to_block_text(steps) if 'summary' in self._data: del self._data['summary'] # Only add the summary if it's non-empty; otherwise ruamel messes up the # subsequent indentation when inserting a comment after an empty list. if steps: self._data.insert(len(self._data) - 1, 'summary', steps) self._data.yaml_set_comment_before_after_key( 'summary', after='This summary is generated by http://go/gcloud-scenario-tests on update and should ' 'not be edited.', after_indent=0) scenario_context.RewriteScenario()
def Update(self, actual, modes): """Triggers the update hook. Args: actual: The actual value of the assertion. modes: [UpdateMode], The update modes that are currently active. Returns: True if an update was done or False if this assertion should be raised as an error. """ if self._update_mode not in modes: # We are not allowed to update given the current modes. return False if self._custom_update_hook: result = self._custom_update_hook(self, actual) else: result = self.StandardUpdateHook(actual) # This conversion operates on either a dict or a list. We want to change # as little of the formatting as possible, so we convert the immediately # enclosing dict of the field that is being changed. yaml.convert_to_block_text(self._data_dict) return result
def TearDownClass(): # Write the entire scenario file when the entire test class is done. yaml.convert_to_block_text(Interceptor.SCENARIO_DATA) data = yaml.dump(Interceptor.SCENARIO_DATA, round_trip=True) sys.__stderr__.write(data.encode('utf-8') if six.PY2 else data) files.WriteFileContents(Interceptor.PATH, data)
def _StartNewCommandExecution(self): if self.current_action: yaml.convert_to_block_text(self.current_action) Interceptor.SCENARIO_DATA['actions'].append(self.current_action) self.current_action = {'execute_command': comments.CommentedMap( [('command', ''), ('events', [])])}
def __str__(self): yaml.convert_to_block_text(self._content) return yaml.dump(self._content, round_trip=True)