Esempio n. 1
0
 def __init__(self, path, test_id, workspace):
     """
     We require three arguments - a path to the test, a unique id, and the
     workspace object we fall back on.
     """
     self._test_path = path
     self._context = load_config("%s/test.json" % (path))
     self._workspace = workspace
     self._update_context()
     self.test_id = test_id
Esempio n. 2
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")
Esempio n. 3
0
    def run(self, verbose=False):
        templates = self._context['templates'][:]
        templates.reverse()

        for template in templates:
            template = "%s.json" % (template)

            try:
                context = self._workspace._look_up('contexts', template)
                context = load_config(context)
                self.set_global_context(context)
            except NoSuchCallableError as e:
                pass

        self._run_hook("init")

        if "todo" in self._context:
            return {}

        source, version = self.get_source_and_version()
        version = version['upstream']
        tm = self.get_template_stack()
        with tmpdir() as tmp:
            self.path = "%s/%s-%s" % (tmp, source, version)
            path = self.path
            mkdir(path)
            self._run_hook("tmpdir", path=tmp)
            tm.render(path)

            self._run_hook("pre-build", path=path)
            self._run_builds()
            self._run_hook("post-build", path=path)

            self._run_hook("pre-check", path=path)
            self._run_checks()
            self._run_hook("post-check", path=path)

            results = {}
            for checker in self._context['checkers']:
                pristine = "%s/%s" % (self._test_path, checker)
                output = "%s/%s" % (tmp, checker)
                if os.path.exists(pristine):
                    # OK, let's verify
                    if os.path.exists(output):
                        with open("/dev/null", "w") as null:
                            if diff(pristine, output,
                                    output_fd=null):
                                results[checker] = "passed"
                            else:
                                results[checker] = "failed"
                                if verbose:
                                    print "================================"
                                    print "Checker match failure:"
                                    print "  -> %s" % (self.name)
                                    print "  -> %s" % (checker)
                                    print "--------------------------------"
                                    diff(pristine, output)
                                    print "================================"
                    else:
                        results[checker] = "no-output"
                else:
                    results[checker] = "no-pristine"
            self._run_hook("finally", path=path)
        return results