def testLinkWithNotExistentGraph(self):
     rodir  = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     rofile = rodir+"/"+"subdir1/subdir1-file.txt"
     # Apply non-exietent graph annotation
     annotation_graph_filename = os.path.join(os.path.abspath(rodir), "annotate-none.rdf")
     rouri = ro_manifest.getRoUri(rodir)
     args = ["ro", "annotate", rodir+"/", "-g", annotation_graph_filename ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     # Read manifest and check for annotation
     annotations = ro_annotation.getAllAnnotations(rodir)
     expected_annotations = (
         [ ( rouri, DCTERMS.identifier,  rdflib.Literal('ro-testRoAnnotate')  )
         , ( rouri, DCTERMS.description, rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.title,       rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.creator,     rdflib.Literal('Test User') )
         , ( rouri, RDF.type,            RO.ResearchObject )
         ])
     count = 0
     for next in list(annotations):
         if ( # not isinstance(next[2], rdflib.BNode) and
              not next[1] in [ORE.aggregates, DCTERMS.created] and
              not next[1] == DCTERMS.created ):
             log.debug("- next %s"%(str(next[0])) )
             log.debug("       - (%s, %s)"%(str(next[1]),str(next[2])) )
             if next in expected_annotations:
                 count += 1
             else:
                 self.assertTrue(False, "Not expected (%d) %s"%(count, repr(next)))
     self.assertEqual(count,5)
     # Clean up
     self.deleteTestRo(rodir)
     return
 def testAnnotateWildcardPattern2(self):
     """
     Same as previous test, but includes filenames with spaces and hashes
     """
     rodir  = self.createTestRo(testbase, "data/ro-test-1", "RO test annotation", "ro-testRoAnnotate")
     self.populateTestRo(testbase, rodir)
     # Apply annotation to filename pattern
     rouri = ro_manifest.getRoUri(rodir)
     args = ["ro", "annotate"
            ,"-d", rodir+"/"
            , "-w", "\\.txt$"
            , "dcterms:description", "pattern annotation" ]
     with SwitchStdout(self.outstr):
         status = ro.runCommand(ro_test_config.CONFIGDIR, ro_test_config.ROBASEDIR, args)
     outtxt = self.outstr.getvalue()
     assert status == 0, outtxt
     # Read manifest and check for annotation
     annotations = ro_annotation.getAllAnnotations(rodir)
     res_spc_uri = ro_manifest.getComponentUriAbs(rodir, "filename%20with%20spaces.txt")
     res_hsh_uri = ro_manifest.getComponentUriAbs(rodir, "filename%23with%23hashes.txt")
     resource1uri = ro_manifest.getComponentUriAbs(rodir, "subdir1/subdir1-file.txt")
     resource2uri = ro_manifest.getComponentUriAbs(rodir, "subdir2/subdir2-file.txt")
     expected_annotations = (
         [ ( rouri, DCTERMS.identifier,  rdflib.Literal('ro-testRoAnnotate')  )
         , ( rouri, DCTERMS.description, rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.title,       rdflib.Literal('RO test annotation') )
         , ( rouri, DCTERMS.creator,     rdflib.Literal('Test User') )
         , ( rouri, RDF.type,            RO.ResearchObject )
         , ( res_spc_uri,  DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( res_hsh_uri,  DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( resource1uri, DCTERMS.description, rdflib.Literal('pattern annotation') )
         , ( resource2uri, DCTERMS.description, rdflib.Literal('pattern annotation') )
         ])
     count = 0
     for next in list(annotations):
         if ( not isinstance(next[2], rdflib.BNode) and
              not next[1] in [ORE.aggregates, DCTERMS.created] ):
             log.debug("- next %s"%(str(next[0])) )
             log.debug("       - (%s, %s)"%(str(next[1]),str(next[2])) )
             if next in expected_annotations:
                 count += 1
             else:
                 self.assertTrue(False, "Not expected (%d) %s"%(count, repr(next)))
     self.assertEqual(count,9)
     # Clean up
     #self.deleteTestRo(rodir)
     return
 def testAddGetAllAnnotations(self):
     rodir = self.createTestRo(testbase, "data/ro-test-1", "Test get all annotations", "ro-testRoAnnotate")
     roresource = "subdir1/subdir1-file.txt"
     # Add anotations for file
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "type",         "Test file")
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "description",  "File in test research object")
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "note",         "Research object file created for annotation testing")
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "title",        "Test file in RO")
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "created",      "2011-12-07")
     ro_annotation._addSimpleAnnotation(ro_config, rodir, roresource,
         "rdf:type",     ROTERMS.resource)
     # Retrieve the file anotations
     annotations = ro_annotation.getAllAnnotations(rodir)
     rouri       = ro_manifest.getRoUri(rodir)
     resourceuri = ro_manifest.getComponentUri(rodir, roresource)
     log.debug("resourceuri: %s"%(resourceuri))
     expected_annotations = (
         [ (rouri,       DCTERMS.description,  rdflib.Literal('Test get all annotations'))
         , (rouri,       DCTERMS.title,        rdflib.Literal('Test get all annotations'))
         , (rouri,       DCTERMS.created,      rdflib.Literal('unknown'))
         , (rouri,       DCTERMS.creator,      rdflib.Literal('Test User'))
         , (rouri,       DCTERMS.identifier,   rdflib.Literal('ro-testRoAnnotate'))
         , (rouri,       RDF.type,             RO.ResearchObject)
         , (resourceuri, DCTERMS.type,         rdflib.Literal('Test file'))
         , (resourceuri, DCTERMS.description,  rdflib.Literal('File in test research object'))
         , (resourceuri, ROTERMS.note,         rdflib.Literal('Research object file created for annotation testing'))
         , (resourceuri, DCTERMS.title,        rdflib.Literal('Test file in RO'))
         , (resourceuri, DCTERMS.created,      rdflib.Literal('2011-12-07'))
         , (resourceuri, RDF.type,             ROTERMS.resource)
         ])
     for i in range(12+1+6):      # Annotations + aggregations
         next = annotations.next()
         #log.debug("Next %s"%(repr(next)))
         if ( next not in expected_annotations and
              next[1] != DCTERMS.created       and
              next[1] != ORE.aggregates        ):
             self.assertTrue(False, "Not expected (%d) %s"%(i, repr(next)))
     self.assertRaises(StopIteration, annotations.next)
     self.deleteTestRo(rodir)
     return