def testEvalFormatDetail(self): rodir = self.setupEvalFormat() options = { 'detail': "full" } stream = StringIO.StringIO() ro_eval_minim.format(self.eval_result, options, stream) outtxt = stream.getvalue() log.debug("---- Result:\n%s\n----"%(outtxt)) expect = ( [ "Research Object file://%s/:"%rodir , "Nominally complete for %(purpose)s of resource %(target)s"%(self.eval_result) # , "Unsatisfied MUST requirements:" # , "Unsatisfied SHOULD requirements:" , "Unsatisfied MAY requirements:" , " No synonym is present"%(self.eval_result['missingMay'][0][0]['querytestrule']) , "Satisfied requirements:" , " ChemSpider identifier is present" , " InChI identifier is present" , "Research object URI: %(rouri)s"%(self.eval_result) , "Minimum information URI: %(minimuri)s"%(self.eval_result) ]) stream.seek(0) for expect_line in expect: line = stream.readline() self.assertEquals(line, expect_line+"\n") return
def evaluate(progname, configbase, options, args): """ Evaluate RO ro evaluate checklist [ -d <dir> ] <minim> <purpose> [ <target> ]" """ log.debug("evaluate: progname %s, configbase %s, args %s" % (progname, configbase, repr(args))) ro_config = getroconfig(configbase, options) ro_options = ( { "rodir": options.rodir or "" , "function": args[2] }) log.debug("ro_options: " + repr(ro_options)) ro_ref = ro_root_reference(progname + " annotations", ro_config, None, ro_options['rodir']) if not ro_ref: return 1 # Evaluate... if ro_options["function"] == "checklist": if len(args) not in [5, 6]: print ("%s evaluate checklist: wrong number of arguments provided" % (progname)) print ("Usage: %s evaluate checklist [ -d <dir> ] [ -a | -l <level> ] <minim> <purpose> [ <target> ]" % (progname)) return 1 levels = ["summary", "must", "should", "may", "full"] if options.level not in ["summary", "must", "should", "may", "full"]: print ("%s evaluate checklist: invalid reporting level %s, must be one of %s" % (progname, options.level, repr(levels))) return 1 ro_options["minim"] = ((len(args) > 3) and args[3]) or "minim.rdf" ro_options["purpose"] = ((len(args) > 4) and args[4]) or "create" ro_options["target"] = ((len(args) > 5) and args[5]) or "." if options.verbose: print "ro evaluate %(function)s -d \"%(rodir)s\" %(minim)s %(purpose)s %(target)s" % ro_options rometa = ro_metadata(ro_config, ro_ref) (minimgraph, evalresult) = ro_eval_minim.evaluate(rometa, ro_options["minim"], ro_options["target"], ro_options["purpose"]) if options.verbose: print "== Evaluation result ==" print json.dumps(evalresult, indent=2) if options.outformat and options.outformat.upper() in RDFTYPSERIALIZERMAP: # RDF output graph = ro_eval_minim.evalResultGraph(minimgraph, evalresult) graph.serialize(destination=sys.stdout, format=RDFTYPSERIALIZERMAP[options.outformat.upper()]) else: ro_eval_minim.format(evalresult, { "detail" : "full" if options.all else options.level }, sys.stdout) # elif ... other functions here else: print ("%s evaluate: unrecognized function provided (%s)" % (progname, ro_options["function"])) print ("Usage:") print (" %s evaluate checklist [ -d <dir> ] [ -a | -l <level> ] <minim> <purpose> [ <target> ]" % (progname)) return 1 return 0
def testEvalFormatSummary(self): rodir = self.setupEvalFormat() options = { 'detail': "summary" } stream = StringIO.StringIO() ro_eval_minim.format(self.eval_result, options, stream) outtxt = stream.getvalue() expect = ( "Research Object file://%s/:\n"%rodir + "Nominally complete for %(purpose)s of resource %(target)s\n"%(self.eval_result) ) self.assertEquals(outtxt, expect) return
def testEvalFormatDetail(self): rodir = self.setupEvalFormat() options = { 'detail': "full" } stream = StringIO.StringIO() ro_eval_minim.format(self.eval_result, options, stream) expect = ( [ "Research Object file://%s/:"%rodir , "Nominally complete for %(purpose)s of resource %(target)s"%(self.eval_result) , "Unsatisfied MUST requirements:" , " Aggregates resource %s"%(self.eval_result['missingMust'][0][0]['datarule']['aggregates']) , "Unsatisfied SHOULD requirements:" , " Aggregates resource %s"%(self.eval_result['missingShould'][0][0]['datarule']['aggregates']) , "Unsatisfied MAY requirements:" , " Aggregates resource %s"%(self.eval_result['missingMay'][0][0]['datarule']['aggregates']) , "Research object URI: %(rouri)s"%(self.eval_result) , "Minimum information URI: %(minimuri)s"%(self.eval_result) ]) stream.seek(0) for expect_line in expect: line = stream.readline() self.assertEquals(line, expect_line+"\n") return