Ejemplo n.º 1
0
def test_template_manager_error():
    """
    Make sure that we error out with a bad template.
    """
    tm = TemplateManager()
    try:
        tm.add_template("foo")
        assert True is False
    except ValueError:
        pass
Ejemplo n.º 2
0
def test_template_manager():
    """
    Make sure the template manager basics work right.
    """
    template_dir = abspath("./tests/resources/templates/")
    templs = {"plain1": "PlainTemplate", "jinja1": "JinjaTemplate", "jinja2": "JinjaTemplate"}
    context = {"foo": "foo"}
    with tmpdir() as tmp:
        tplm = TemplateManager()
        for template in templs:
            kwargs = {}
            klasse = templs[template]
            if klasse == "JinjaTemplate":
                kwargs["context"] = context

            tplm.add_template(klasse, os.path.join(template_dir, template), **kwargs)

        tplm.render(tmp)
Ejemplo n.º 3
0
    def get_template_stack(self):
        """
        Get the template stack in the form of the TemplateManager.
        """
        ctx = self._context
        tm = TemplateManager()
        native = ctx['native']
        pkgname, version = self.get_source_and_version()
        version = version['upstream']

        for template in ctx['templates']:
            if template == "shim:upstream":
                if native:
                    raise InvalidTemplate("shim:upstream")
                tm.add_template("UpstreamShim", pkgname, version)
                tm.add_template("DebianShim")
            else:
                tobj = self._template_search(template)
                tm.add_real_template(tobj)
        return tm