def testCreateReadRoAnnotationBody(self): """ Test function to create simple annotation body """ rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate") roresource = "." attrdict = { "type": rdflib.Literal("Research Object"), # @@TODO: handle lists "keywords": ["test", "research", "object"], "description": rdflib.Literal("Test research object"), "format": rdflib.Literal("application/vnd.wf4ever.ro"), "note": rdflib.Literal("Research object created for annotation testing"), "title": rdflib.Literal("Test research object"), "created": rdflib.Literal("2011-12-07") } annotationfilebase = ro_annotation.createAnnotationBody( ro_config, rodir, roresource, attrdict) # Ann-%04d%02d%02d-%04d-%s.rdf self.assertRegexpMatches(annotationfilebase, r"Ann-\d\d\d\d\d\d\d\d-\d+-RO_test_annotation\.rdf", msg="Unexpected filename form for annotation: "+annotationfilebase) annotationfilename = ro_annotation.makeAnnotationFilename(rodir, annotationfilebase) annotationgraph = ro_annotation.readAnnotationBody(rodir, annotationfilename) attrpropdict = { "type": DCTERMS.type, # @@TODO "keywords": DCTERMS.subject, "description": DCTERMS.description, "format": DCTERMS.format, "note": ROTERMS.note, "title": DCTERMS.title, "created": DCTERMS.created } s = ro_manifest.getComponentUri(rodir, roresource) log.debug("annotation subject %s"%repr(s)) for k in attrpropdict: p = attrpropdict[k] log.debug("annotation predicate %s"%repr(p)) v = attrdict[k] a = annotationgraph.value(s, p, None) log.debug("annotation value %s"%repr(a)) #self.assertEqual(len(a), 1, "Singleton result expected") self.assertEqual(a, v) self.deleteTestRo(rodir) return
def testCreateReadFileAnnotationBody(self): """ Test function to create simple annotation body """ rodir = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate") roresource = "subdir1/subdir1-file.txt" attrdict = { "type": "Test file", "description": "File in test research object", "note": "File in research object created for annotation testing", "title": "Test file in RO", "created": "2011-12-07" } annotationfilebase = ro_annotation.createAnnotationBody( ro_config, rodir, roresource, attrdict) # Ann-%04d%02d%02d-%04d-%s.rdf self.assertRegexpMatches(annotationfilebase, r"Ann-\d\d\d\d\d\d\d\d-\d+-subdir1-file\.txt\.rdf", msg="Unexpected filename form for annotation: "+annotationfilebase) annotationfilename = ro_annotation.makeAnnotationFilename(rodir, annotationfilebase) annotationgraph = ro_annotation.readAnnotationBody(rodir, annotationfilename) attrpropdict = { "type": DCTERMS.type, "description": DCTERMS.description, "note": ROTERMS.note, "title": DCTERMS.title, "created": DCTERMS.created } s = ro_manifest.getComponentUri(rodir, roresource) log.debug("annotation subject %s"%repr(s)) for k in attrpropdict: p = attrpropdict[k] log.debug("annotation predicate %s"%repr(p)) v = attrdict[k] a = annotationgraph.value(s, p, None) log.debug("annotation value %s"%repr(a)) #self.assertEqual(len(a), 1, "Singleton result expected") self.assertEqual(a, v) self.deleteTestRo(rodir) return