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")
def write_result(self, error=False, exc=None): """ Write the remaining information to make the final test result object. This includes: * check for errors in the previous steps. if there are any skip and move directory to the error directory * Creating ``CONFIG_FILE`` and ``PIPELINESPEC_FILE`` for result metadata * Moving the ``output`` directory to its final resting place """ # set the result path to error, or the one appropriate for our # runner type ('tr' for test 'vr' for verification result) if error: self.result_code = '{}-error'.format(self.result_code) self.result_path = os.path.join("er", self.result_code) else: self.result_path = os.path.join(self.runner_temp.result_leader.lower(), self.result_code) self.full_result_path = os.path.join(cf.LOCAL_REPOSITORY_PATH, self.result_path) # if there was an error, create the traceback file as well with self.runner_temp.in_dir(), open(cf.EXCEPTION_FILE, 'w') as f: f.write(str(exc or '')) # create the kimspec.edn file for the test results logger.debug("Create %s file" % cf.CONFIG_FILE) kimspec = {} kimspec[self.runner.runner_name] = self.runner.kim_code kimspec[self.subject.subject_name] = self.subject.kim_code kimspec['domain'] = 'openkim.org' pipelinespec = {} if self.info_dict: pipelinespec['profiling'] = self.info_dict if self.result_code: if error: kimspec['error-result-id'] = self.result_code pipelinespec['error-result-id'] = self.result_code else: kimspec['test-result-id'] = self.result_code pipelinespec['test-result-id'] = self.result_code with self.runner_temp.in_dir(), open(os.path.join(cf.OUTPUT_DIR,cf.CONFIG_FILE),'w') as f: util.dumpedn(kimspec, f, allow_nils=False) with self.runner_temp.in_dir(), open(os.path.join(cf.OUTPUT_DIR,cf.PIPELINESPEC_FILE),'w') as f: util.dumpedn(pipelinespec, f, allow_nils=False) logger.debug("Result path = %s", self.full_result_path) outputdir = os.path.join(self.runner_temp.path,cf.OUTPUT_DIR) # short circuit moving over the result tree if we have not trcode if not self.result_code: logger.info("No Test Result ID provided, leaving in %s", outputdir) return # copy over the entire tree if it is done logger.info("Copying the contents of %s to %s", outputdir, self.full_result_path) try: shutil.rmtree(self.full_result_path) except OSError: pass finally: shutil.copytree(outputdir, self.full_result_path)