def render(self, dest):
     """
     `dest' is a path (abs or rel) to the output directory, or where to
     write the model files to.
     """
     dest = abspath(dest)
     rsync(self._template_path, dest)
 def render(self, dest):
     """
     We're actually rendering a tarball out, not files from a model
     directory. We also expect that `dest' is in pkgname-version format,
     ready for taring up.
     """
     dest = abspath("%s/../" % (dest))
     make_orig_tarball(dest, self.pkgname, self.version,
                       compression=self.compression,
                       outputdir=dest)
Beispiel #3
0
 def get_template(self, name):
     """
     Get the template by the name of `name`, and return that, or None.
     """
     path = abspath("%s/%s" % (self._test_path, name))
     ctx = self._context
     if os.path.exists(path):
         return JinjaTemplate(path,
                              context=ctx)
     return None
Beispiel #4
0
 def __init__(self, workspace):
     """
     The only argument `workspace' is given the root of the test directory.
     """
     self._workspace_path = abspath(workspace)
     self._test_dir = "%s/tests" % (workspace)
     context_file = os.path.join(workspace, "context.json")
     self._context = load_config(context_file)
     self._workspace = workspace
     try:
         self.name = self._context['suite-name']
     except KeyError:
         raise InvalidContextFile(context_file, "Missing suite-name")
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)
    def render(self, dest):
        """
        `dest' is a path (abs or rel) to the output directory, or where to
        write the model files to. Be extra-sure to call setContext on this
        particular class, it's important to render out the Jinja context
        correctly.
        """
        dest = abspath(dest)

        if self.context is None:
            raise ValueError("No context set for this JinjaTemplate")

        with tmpdir() as tmp:
            PlainTemplate.render(self, tmp)
            for template in dir_walk(tmp, xtn=".tpl"):
                with open(template, 'r') as fd:
                    tobj = Template(fd.read())
                    with open(template.rsplit(".", 1)[0], 'w') as obj:
                        obj.write(tobj.render(**self.context))
                rm(template)
            rsync(tmp, dest)
def make_and_check_tarball(testname, rundir, upname, upversion, compression,
                           visitor, visit_open=True):
    """Create, check and clean up a tarball (test utility)

    Utility for setting up a dir, compile a tarball from a resource path,
    opening the tarball and passing it to vistor.

    testname is used to create a unique name for the test.  The
    compression is also used for this purpose, so multiple tests can
    share the same "testname" as long as the compression differs.

    rundir, upname, upversion and compression are passed (as is) to
    make_orig_tarball.

    The tarball passed to visitor may not be seekable and should be
    checked inorder.
    """

    testdir = "%s-%s" % (testname, compression)
    xtn = compression
    if xtn == "gzip":
        xtn = "gz"
    elif xtn == "bzip2":
        xtn = "bz2"

    rundir = abspath(rundir)

    with tmpdir() as tmp:
        with cd(tmp):
            mkdir(testdir)

            make_orig_tarball(rundir, upname, upversion,
                              compression=compression, outputdir=testdir)
            tarname = "%s_%s.orig.tar.%s" % (upname, upversion, xtn)
            path = os.path.join(testdir, tarname)
            if visit_open:
                with open_compressed_tarball(path, compression) as tar:
                    visitor(tar)
            else:
                visitor(path)
 def __init__(self, where):
     """
     `where' is a path (abs or rel) to the Template directory, to be
     rendered when one invokes `render()' on this class.
     """
     self._template_path = abspath(where)
# Copyright (c) DPU AUTHORS, under the terms and conditions of the GPL-2+
# license.
"""
This module tests the workspace system
"""

from dpu.suite import TestSuite
from dpu.utils import abspath, tmpdir, mkdir
from dpu.exceptions import InvalidTemplate
import os

workspace = abspath("./tests/resources/workspace")


def test_test_finder():
    """
    Make sure we can resolve test folders correctly.
    """
    tests = os.listdir("%s/tests" % (workspace))
    ws = TestSuite(workspace)
    for test in ws.tests():
        tests.remove(test.test_id)
    assert tests == []


def test_crazy_things():
    """
    Make sure we can resolve test folders correctly.
    """
    ws = TestSuite(workspace)
    test = ws.get_test("cruft-empty-diff")