Example #1
0
 def testChecklistEvalExcel(self):
     """
     Test checklist evaluation with generated Minim file from Excel source
     """
     self.setupConfig()
     rodir = self.createTestRo(testbase, "testro", "RO for testMkMinim", "ro-testMkMinim")
     self.populateTestRo(testbase, rodir)
     self.annotateResource(testbase, rodir, "", "FileAnnotations.ttl")
     rouri = ro_manifest.getRoUri(rodir)
     # Create minim graph from CSV file
     gridname = "TestMkMinim.xls"
     griduri = ro_manifest.getComponentUri(rodir, gridname)
     gridxls = os.path.join(rodir, gridname)
     gridbase = "http://example.org/base/"
     grid = GridExcel(gridxls, baseuri=gridbase)
     (status, minimgr) = mkminim.mkminim(grid, baseuri=grid.resolveUri(""))
     self.assertEquals(status, 0)
     # Write Minim
     minimname = "TestMkMinim_minim.ttl"
     with open(rodir + "/" + minimname, "w") as minimfile:
         minimgr.serialize(minimfile, format="turtle")
     # Evaluate checklist
     minimuri = ro_manifest.getComponentUri(rodir, minimname)
     minimpurpose = "test1"
     args = ["ro", "evaluate", "checklist", "-a", "-d", rodir + "/", minimname, minimpurpose, "."]
     self.outstr.seek(0)
     with StdoutContext.SwitchStdout(self.outstr):
         status = ro.runCommand(
             os.path.join(testbase, TestConfig.ro_test_config.CONFIGDIR),
             os.path.join(testbase, TestConfig.ro_test_config.ROBASEDIR),
             args,
         )
     outtxt = self.outstr.getvalue()
     assert status == 0, "Status %d, outtxt: %s" % (status, outtxt)
     log.debug("status %d, outtxt: %s" % (status, outtxt))
     # Check response returned
     # filelist  = [ unicode(ro_manifest.getComponentUri(rodir, f))
     #               for f in ["File1.txt", "File2.txt", "File3.txt"] ]
     filelist = ValueList(
         [str(ro_manifest.getComponentUri(rodir, f)) for f in ["File1.txt", "File2.txt", "File3.txt"]]
     )
     expect = [
         "Research Object file://%s/:" % (rodir),
         "Fully complete for test1 of resource .",
         "Satisfied requirements:",
         "  At least 3 file as part values are present",
         "  At most 3 file as part values are present",
         "  All part resource files %s are aggregated in RO" % (filelist),
         "  All file as part resources are accessible (live)",
         "  Python 2.7.x present",
         "  Files as part are partOf some indicated whole",
         "  File exists as a part",
         "Research object URI:     %s" % (rouri),
         "Minimum information URI: %s" % (minimuri),
     ]
     self.outstr.seek(0)
     for line in self.outstr:
         self.assertIn(str(line)[:-1], expect)
     self.deleteTestRo(rodir)
     return
Example #2
0
    def testMkMinim(self):
        self.setupConfig()
        rodir = self.createTestRo(testbase, "testro", "RO for testMkMinim", "ro-testMkMinim")
        rouri = ro_manifest.getRoUri(rodir)
        # Create minim graph from CSV file
        # NOTE: a base URI may be specoified when decoding the grid or when constructing the minim
        #       graph.  The Minim graph uses its own relative references, so for consistency it may
        #       be necessary to pass the grid base URI to mkminim.  The code below does this.
        gridname = "TestMkMinim.csv"
        griduri = ro_manifest.getComponentUri(rodir, gridname)
        gridcsv = os.path.join(rodir, gridname)
        gridbase = "http://example.org/base/"
        with open(gridcsv, "rU") as gridfile:
            grid = GridCSV(gridfile, baseuri=gridbase, dialect=csv.excel)
        (status, minimgr) = mkminim.mkminim(grid, baseuri=grid.resolveUri(""))
        self.assertEquals(status, 0)
        # Read expected graph
        graphname = os.path.join(rodir, "TestMkMinim.ttl")
        expectgr = rdflib.Graph()
        with open(graphname) as expectfile:
            expectgr.parse(file=expectfile, publicID=gridbase, format="turtle")
        # Check content of minim graph
        ###minimgr.serialize(sys.stdout, format="turtle")
        self.checkTargetGraph(minimgr.graph(), expectgr, msg="Not found in constructed minim graph")

        self.deleteTestRo(rodir)
        return