Esempio n. 1
0
def insert_one_result(leader, uuid):
    logger.info("Inserting result %s ", uuid)
    stuff = None
    info = uuid_to_dict(leader, uuid)
    try:
        resultobj = db.obj.insert(info)
    except:
        logger.error("Already have %s", uuid)
        return
    try:
        if leader == 'er':
            with open(os.path.join(PATH_RESULT,leader,uuid,'pipeline.exception')) as f:
                doc = {'exception': f.read()}
            stuff = doc_to_dict(doc,leader,uuid)
            db.data.insert(stuff)
    except:
        logger.info("Could not insert exception for %s/%s", leader, uuid)
    try:
        with open(os.path.join(PATH_RESULT,leader,uuid,'results.edn')) as f:
            edn_docs = util.loadedn(f)
            edn_docs = edn_docs if isinstance(edn_docs, list) else [edn_docs]
            for doc in edn_docs:
                stuff = doc_to_dict(doc,leader,uuid)
                db.data.insert(stuff)
        set_latest_version_test_result(info['test-result-id'])
    except:
        logger.info("Could not read document for %s/%s", leader, uuid)
Esempio n. 2
0
    def kimspec(self):
        specfile = os.path.join(self.path,cf.CONFIG_FILE)
        if not os.path.exists(specfile):
            return None

        spec = {}
        with open(specfile) as f:
            spec = util.loadedn(f)
        return spec
Esempio n. 3
0
    def runtime_dependencies(self, subject=None):
        """ go ahead and append the subject to single test items """
        if self.depfile:
            raw, out = util.loadedn(self.depfile), []
            for dep in raw:
                newdep = dep

                if subject and isinstance(dep, basestring):
                    tt = kim_obj(dep)
                    if isinstance(tt, Test):
                        newdep = [str(tt), str(subject)]

                out.append(newdep)
            return out
        return []
Esempio n. 4
0
def insert_one_reference_data(leader, kimcode):
    logger.info("Inserting reference data %s ", kimcode)
    info = kimcode_to_dict(kimcode)
    try:
        resultobj = db.obj.insert(info)
    except:
        logger.error("Already have %s", kimcode)
        return
    try:
        with open(os.path.join(PATH_APPROVED,leader,kimcode,'data.edn')) as f:
            edn_docs = util.loadedn(f)
            edn_docs = edn_docs if isinstance(edn_docs, list) else [edn_docs]
            for doc in edn_docs:
                stuff = doc_to_dict(doc,leader,kimcode)
                stuff = kimunits.add_si_units(stuff)
                db.data.insert(stuff)
    except:
        logger.info("Could not read document for %s/%s", leader, kimcode)
Esempio n. 5
0
    def process_output(self):
        """
        In the current directory, make sure that the results are ready to
        go by checking that ``RESULT_FILE`` exists and conforms to the
        property definitions that it promises.  Also append SI units
        """
        # Short-circuit if we already have a results.edn
        with self.runner_temp.in_dir():
            if not os.path.isfile(cf.RESULT_FILE):
                raise cf.KIMRuntimeError(
                    "The test did not produce a %s output file." % cf.RESULT_FILE
                )

        # now, let's check whether that was actual a valid test result
        logger.debug("Checking the output EDN for validity")
        with self.runner_temp.in_dir(), open(cf.RESULT_FILE, 'r') as f:
            try:
                doc = util.loadedn(f)
                doc = kimunits.add_si_units(doc)
            except Exception as e:
                raise cf.PipelineRuntimeError(
                    "Test did not produce valid EDN %s" % cf.RESULT_FILE, str(e)
                )

            if self.verify:
                valid, reply = test_result_valid(cf.RESULT_FILE)
                if not valid:
                    raise cf.KIMRuntimeError(
                        "Test result did not conform to property definition\n%r" % reply
                    )

        logger.debug("Adding units to result file")
        with self.runner_temp.in_dir(), open(cf.RESULT_FILE, 'w') as f:
            util.dumpedn(doc, f)

        logger.debug("Made it through EDN read, everything looks good")
Esempio n. 6
0
def config_edn(flname):
    with open(flname) as f:
        doc = util.loadedn(f)
        doc.setdefault("created_on", str(datetime.datetime.fromtimestamp(os.path.getctime(flname))))
        return doc