示例#1
0
def parse_template(template):
    """ parse instantiates a Template object with the provided string contents
    of the template and returns a dict of all the resources defined within it.
    """
    temp = Template(template)
    temp.reduce_functions()
    return temp.parse_resources()
示例#2
0
def parse_template(template):
    """ parse instantiates a Template object with the provided string contents
    of the template and returns a dict of all the resources defined within it.
    """
    temp = Template(template)
    temp.reduce_functions()
    return temp.parse_resources()
示例#3
0
    def test_functions_get_applied(self):
        """ test_functions_get_applied tests that running the function
        application on a Template's data reduces all available functions.
        """
        LOG.debug("testing function application correctness on '%s'.", self._function_application_test_data)
        temp = Template(self._function_application_test_data)
        temp.reduce_functions()

        # for each registered templating function (which are considered to
        # behave correctly, as they have their separate tests), ensure that
        # there is no unapplied instance of it in the resulting template:
        for func_name in temp._functions:
            LOG.debug("checking for unapplied function '%s' in '%s'.", func_name, temp._template_data)
            self.assertFalse(recursive_dict_search(temp._template_data, func_name))
示例#4
0
    def test_functions_get_applied(self):
        """ test_functions_get_applied tests that running the function
        application on a Template's data reduces all available functions.
        """
        LOG.debug("testing function application correctness on '%s'.",
                  self._function_application_test_data)
        temp = Template(self._function_application_test_data)
        temp.reduce_functions()

        # for each registered templating function (which are considered to
        # behave correctly, as they have their separate tests), ensure that
        # there is no unapplied instance of it in the resulting template:
        for func_name in temp._functions:
            LOG.debug("checking for unapplied function '%s' in '%s'.",
                      func_name, temp._template_data)
            self.assertFalse(
                recursive_dict_search(temp._template_data, func_name))
示例#5
0
    def test_parse_resources(self):
        """ test_parse_resources tests that running the resource extraction
        procedure will yield the appropriate set of resources:
        """
        LOG.debug("testing resource parsing on '%s'", self._resource_parsing_test_data)

        temp = Template(self._resource_parsing_test_data)
        parsed_resources = temp.parse_resources()

        input_resources = yaml.load(self._resource_parsing_test_data)[self._field_names["resources"]]

        # ensure all the resources defined in the input template have a
        # corresponding Resource instance created for them:
        for res_name, res_data in input_resources.items():
            self.assertTrue(res_name in parsed_resources)
            self.assertDictEqual(
                parsed_resources[res_name].properties, res_data.get(self._field_names["properties"], {})
            )
示例#6
0
    def test_parse_resources(self):
        """ test_parse_resources tests that running the resource extraction
        procedure will yield the appropriate set of resources:
        """
        LOG.debug("testing resource parsing on '%s'",
                  self._resource_parsing_test_data)

        temp = Template(self._resource_parsing_test_data)
        parsed_resources = temp.parse_resources()

        input_resources = yaml.load(
            self._resource_parsing_test_data)[self._field_names["resources"]]

        # ensure all the resources defined in the input template have a
        # corresponding Resource instance created for them:
        for res_name, res_data in input_resources.items():
            self.assertTrue(res_name in parsed_resources)
            self.assertDictEqual(
                parsed_resources[res_name].properties,
                res_data.get(self._field_names["properties"], {}))
示例#7
0
    def test_invalid_data(self):
        """ test_invalid_data tests the behavior of the Template parsing logic
        agains flawed or incomplete templates.
        """
        for test_input in self._template_parsing_test_data:
            LOG.debug(
                "testing Template parsing reaction to invalid data '%s': %s.",
                test_input.template_data, test_input.description)

            with self.assertRaises(test_input.expected_exception):
                Template(test_input.template_data)
示例#8
0
 def setUp(self):
     self._function = self._function_class(Template(self._template_data))