def Load(nag_file):
        """Load a single NagFile object where one and only one is expected.

    Args:
      nag_file: A file-like object or string containing the yaml data to parse.

    Returns:
      A NagFile instance.
    """
        return yaml_object.BuildSingleObject(NagFile, nag_file)
Example #2
0
def LoadSingleConf(stream):
    """Load a conf.yaml file or string and return a YAMLConfiguration object.

  Args:
    stream: a file object corresponding to a conf.yaml file, or its contents
      as a string.

  Returns:
    A YAMLConfiguration instance
  """
    return yaml_object.BuildSingleObject(YAMLConfiguration, stream)
Example #3
0
    def _RunTest(self, klass, doc, expected):
        """Run a validation test against a validated class.

    Builds an object of type klass

    Args:
      klass: Validated class with validator attributes being tested.
      doc: YAML document with source representation of object.
      expected: Dictionary represented the expected object state.
    """
        obj = yaml_object.BuildSingleObject(klass, doc)
        for key in klass.ATTRIBUTES.keys():
            value = getattr(obj, key)
            if not value == expected[key]:
                self.fail("Property '%s' did not match: %s != %s" %
                          (key, expected[key], value))
def ParseIndexDefinitions(document):
    """Parse an individual index definitions document from string or stream.

  Args:
    document: Yaml document as a string or file-like stream.

  Raises:
    EmptyConfigurationFile when the configuration file is empty.
    MultipleConfigurationFile when the configuration file contains more than
    one document.

  Returns:
    Single parsed yaml file if one is defined, else None.
  """
    try:
        return yaml_object.BuildSingleObject(IndexDefinitions, document)
    except yaml_errors.EmptyConfigurationFile:
        return None
Example #5
0
 def testLoadDocument(self):
     """Test basic loading of indexes files."""
     pet = yaml_object.BuildSingleObject(Pet, ('name: Jack\n'
                                               'age: 7\n'
                                               'color: black'))
     self.assertEquals(Pet(name='Jack', age=7, color='black'), pet)