def testEvalShouldMissing(self):
     """
     Evaluate complete RO against Minim description 
     """
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-1", "RO test minim", "ro-testMinim")
     self.populateTestRo(testbase, rodir)
     rometa = ro_metadata(ro_config, rodir)
     minimbase  = rometa.getComponentUri("Minim-UserRequirements.rdf")
     modeluri   = ro_minim.getElementUri(minimbase, "#missingShouldRequirement")
     (g,evalresult) = ro_eval_minim.evaluate(rometa,
         "Minim-UserRequirements.rdf",               # Minim file
         "docs/UserRequirements-bio.html",           # Target resource
         "create")                                   # Purpose
     missing_should = (
         { 'level': "SHOULD"
         , 'model': modeluri 
         , 'label': rdflib.Literal("aggregates docs/missing.css")
         , 'datarule':
           { 'aggregates': rometa.getComponentUri("docs/missing.css")
           , 'show':       None
           , 'showpass':   None
           , 'showfail':   None
           , 'derives':    ro_minim.getElementUri(minimbase, "#isPresent/docs/missing.css")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/docs/missing.css") 
         })
     self.maxDiff=None
     self.assertEquals(evalresult['summary'],       [MINIM.minimallySatisfies])
     self.assertEquals(evalresult['missingMust'],   [] )
     self.assertEquals(evalresult['missingShould'], [(missing_should,{})] )
     self.assertEquals(evalresult['missingMay'],    [] )
     self.deleteTestRo(rodir)
     return
Exemplo n.º 2
0
 def testGetRequirements(self):
     def compare_reqs(req_expect, req_found):
         for k in req_expect:
             if not k in req_found:
                 log.debug("- not found: %s"%(k))
                 return False
             elif isinstance(req_expect[k], dict) and isinstance(req_found[k], dict):
                 if not compare_reqs(req_expect[k], req_found[k]): return False
             elif req_found[k] != req_expect[k]:
                 log.debug("- not found: %s: %s != %s "%(k,req_expect[k],req_found[k]))
                 return False
         return True
     self.setupConfig()
     rodir        = self.createTestRo(testbase, "test-data-2", "RO test minim", "ro-testMinim")
     rouri        = ro_manifest.getRoUri(rodir)
     minimbase    = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements2.rdf")
     model        = ro_minim.getElementUri(minimbase, "#runnableRO")
     minimgraph   = ro_minim.readMinimGraph(minimbase)
     requirements = ro_minim.getRequirements(minimgraph, model)
     r1 = (
         { 'level': "MUST"
         , 'label': rdflib.Literal("aggregates data/UserRequirements-astro.ods")
         , 'querytestrule':
           { 'query':        rdflib.Literal("?ro a ro:ResearchObject")
           , 'resultmod':    None
           , 'aggregates_t': rdflib.Literal("data/UserRequirements-astro.ods")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isAggregated/data/UserRequirements-astro.ods") 
         })
     r2 = (
         { 'level': "MUST"
         , 'label': rdflib.Literal("accessible data/UserRequirements-astro.ods")
         , 'querytestrule':
           { 'query':        rdflib.Literal("?ro a ro:ResearchObject")
           , 'resultmod':    None
           , 'islive_t':     rdflib.Literal("data/UserRequirements-astro.ods")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isAccessible/data/UserRequirements-astro.ods") 
         })
     r3 = (
         { 'level': "MUST"
         , 'label': rdflib.Literal("labeled data/UserRequirements-astro.ods")
         , 'querytestrule':
           { 'query':        rdflib.Literal("?ro a ro:ResearchObject")
           , 'resultmod':    rdflib.Literal("ORDER BY ?ro")
           , 'exists':       rdflib.Literal("<data/UserRequirements-astro.ods> rdfs:label ?label")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isLabeled/data/UserRequirements-astro.ods") 
         })
     r1_found = r2_found = r3_found = False
     for r in requirements:
         log.debug("requirement: %s"%(repr(r)))
         if compare_reqs(r1, r): r1_found = True
         if compare_reqs(r2, r): r2_found = True
         if compare_reqs(r3, r): r3_found = True
     self.assertTrue(r1_found, "Expected requirement(1) not found in minim")
     self.assertTrue(r2_found, "Expected requirement(2) not found in minim")
     self.assertTrue(r3_found, "Expected requirement(3) not found in minim")
     return
Exemplo n.º 3
0
 def testGetModelRemote(self):
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     m = ro_minim.getModel(minimgraph, model)
     self.assertEquals(m['label'], rdflib.Literal("Runnable RO"))
     self.assertEquals(m['uri'],   model)
     return
Exemplo n.º 4
0
 def testGetRequirements(self):
     def compare_reqs(req_expect, req_found):
         for k in req_expect:
             if not k in req_found:
                 log.debug("- not found: %s"%(k))
                 return False
             elif isinstance(req_expect[k], dict) and isinstance(req_found[k], dict):
                 if not compare_reqs(req_expect[k], req_found[k]): return False
             elif req_found[k] != req_expect[k]:
                 log.debug("- not found: %s: %s != %s "%(k,req_expect[k],req_found[k]))
                 return False
         return True
     self.setupConfig()
     rodir        = self.createTestRo(testbase, "test-data-1", "RO test minim", "ro-testMinim")
     rouri        = ro_manifest.getRoUri(rodir)
     minimbase    = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements.rdf")
     model        = ro_minim.getElementUri(minimbase, "#runnableRequirementRO")
     minimgraph   = ro_minim.readMinimGraph(minimbase)
     requirements = ro_minim.getRequirements(minimgraph, model)
     expected_found = False
     r1 = (
         { 'level': "MUST"
         , 'label': rdflib.Literal("Python 2.7")
         , 'softwarerule':
           { 'command':  rdflib.Literal("python -V")
           , 'response': rdflib.Literal("Python 2.7")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#environment-software/python-27") 
         })
     r2 = (
         { 'level': "MUST"
         , 'label': rdflib.Literal("aggregates data/UserRequirements-astro.ods")
         , 'datarule':
           { 'aggregates': ro_manifest.getComponentUri(rodir, "data/UserRequirements-astro.ods")
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/data/UserRequirements-astro.ods") 
         })
     r3 = (
         { 'level': "SHOULD"
         , 'label': rdflib.Literal("aggregates docs/reqs.css")
         , 'datarule':
           { 'aggregates': ro_manifest.getComponentUri(rodir, "docs/reqs.css") 
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/docs/reqs.css") 
         })
     r1_found = r2_found = r3_found = False
     for r in requirements:
         log.debug("requirement: %s"%(repr(r)))
         if compare_reqs(r1, r): r1_found = True
         if compare_reqs(r2, r): r2_found = True
         if compare_reqs(r3, r): r3_found = True
     self.assertTrue(r1_found, "Expected requirement(1) not found in minim")
     self.assertTrue(r2_found, "Expected requirement(2) not found in minim")
     self.assertTrue(r3_found, "Expected requirement(3) not found in minim")
     return
Exemplo n.º 5
0
 def testGetRequirementsRemote(self):
     def compare_reqs(req_expect, req_found):
         for k in req_expect:
             if not k in req_found:
                 log.debug("- not found: %s"%(k))
                 return False
             elif isinstance(req_expect[k], dict) and isinstance(req_found[k], dict):
                 if not compare_reqs(req_expect[k], req_found[k]): return False
             elif req_found[k] != req_expect[k]:
                 log.debug("- not found: %s: %s != %s "%(k,req_expect[k],req_found[k]))
                 return False
         return True
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     requirements = ro_minim.getRequirements(minimgraph, model)
     expected_found = False
     r1 = (
         { 'level': "MUST"
         , 'label': None
         , 'softwarerule':
           { 'command':  rdflib.Literal("python -V")
           , 'response': rdflib.Literal("Python 2.7")
           , 'show': rdflib.term.Literal('python -V command %(command)s returns %(response)s')
           , 'showfail': None
           , 'showpass': None
           }
         , 'model': model
         , 'uri': ro_minim.getElementUri(minimbase, "#environment-software/python-27") 
         })
     r2 = (
         { 'level': 'MUST'
         , 'label': None
         , 'contentmatchrule':
           { 'exists':   rdflib.term.Literal('\n          ?wf rdf:type wfdesc:Workflow .\n        ')
           , 'show':     None
           , 'template': None
           , 'forall':   None
           , 'showfail': rdflib.term.Literal('No workflow instance or template found')
           , 'showpass': rdflib.term.Literal('Workflow instance or template found')
           }
         , 'model': model
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/workflow-instance")
         })
     r1_found = r2_found = False
     for r in requirements:
         log.debug("requirement: %s"%(repr(r)))
         if compare_reqs(r1, r): r1_found = True
         if compare_reqs(r2, r): r2_found = True
     self.assertTrue(r1_found, "Expected requirement(1) not found in minim")
     self.assertTrue(r2_found, "Expected requirement(2) not found in minim")
     return
Exemplo n.º 6
0
 def testGetConstraintRemote(self):
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     c = ro_minim.getConstraint(minimgraph, rouri,
         ".",
         "Runnable")
     self.assertEquals(c['target'],   rouri)
     self.assertEquals(c['purpose'],  rdflib.Literal("Runnable"))
     self.assertEquals(c['model'],    model)
     self.assertEquals(c['uri'],      constraint)
     return
Exemplo n.º 7
0
 def testGetModelsRemote(self):
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     models     = ro_minim.getModels(minimgraph)
     expected_found = False
     for m in models:
         if ( m['label']  == rdflib.Literal("Runnable RO") and
              m['uri']    == model ) :
             expected_found = True
             break
     self.assertTrue(expected_found, "Expected model not found in minim")
     return
Exemplo n.º 8
0
 def testGetConstraint(self):
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-1", "RO test minim", "ro-testMinim")
     rouri      = ro_manifest.getRoUri(rodir)
     minimbase  = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements.rdf")
     model      = ro_minim.getElementUri(minimbase, "#runnableRequirementRO")
     constraint = ro_minim.getElementUri(minimbase, "#create/docs/UserRequirements-astro.csv")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     c = ro_minim.getConstraint(minimgraph, rodir,
         "docs/UserRequirements-astro.csv",
         r"create.*UserRequirements-astro\.csv")
     self.assertEquals(c['target'],   ro_manifest.getComponentUri(rodir, "docs/UserRequirements-astro.csv"))
     self.assertEquals(c['purpose'],  rdflib.Literal("create UserRequirements-astro.csv"))
     self.assertEquals(c['model'],    model)
     self.assertEquals(c['uri'],      constraint)
     return
Exemplo n.º 9
0
 def testEvalMayMissing(self):
     """
     Evaluate complete RO against Minim description 
     """
     self.setupConfig()
     rodir     = self.createTestRo(testbase, "test-data-1", "RO test minim", "ro-testMinim")
     self.populateTestRo(testbase, rodir)
     rometa    = ro_metadata(ro_config, rodir)
     minimbase = rometa.getComponentUri("Minim-UserRequirements.rdf")
     modeluri  = ro_minim.getElementUri(minimbase, "#missingMayRequirement")
     (g,evalresult) = ro_eval_minim.evaluate(rometa,
         "Minim-UserRequirements.rdf",               # Minim file
         "docs/UserRequirements-bio.pdf",            # Target resource
         "create")                                   # Purpose
     missing_may = (
         { 'level': "MAY"
         , 'model': modeluri 
         , 'label': rdflib.Literal("aggregates docs/missing.css")
         , 'datarule':
           { 'aggregates': rometa.getComponentUri("docs/missing.css")
           , 'show':       rdflib.Literal("05 - aggregates docs/missing.css")
           , 'showpass':   None
           , 'showfail':   None
           , 'showmiss':   None
           , 'list':       []
           , 'listpass':   []
           , 'listfail':   []
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/docs/missing.css")
         , 'ruleuri': evalresult['missingMay'][0][0]['ruleuri']
         , 'seq': "05 - aggregates docs/missing.css"
         })
     self.maxDiff=None
     self.assertEquals(evalresult['summary'],        [MINIM.nominallySatisfies, MINIM.minimallySatisfies])
     self.assertEquals(evalresult['missingMust'],    [] )
     self.assertEquals(evalresult['missingShould'],  [] )
     self.assertEquals(evalresult['missingMay'],     [(missing_may,{})] )
     self.assertEquals(evalresult['rouri'],          rometa.getRoUri())
     self.assertEquals(evalresult['minimuri'],       rometa.getComponentUri("Minim-UserRequirements.rdf"))
     self.assertEquals(evalresult['target'],         "docs/UserRequirements-bio.pdf")
     self.assertEquals(evalresult['purpose'],        "create")
     self.assertEquals(evalresult['constrainturi'],  
         rometa.getComponentUriAbs("Minim-UserRequirements.rdf#create/docs/UserRequirements-bio.pdf"))
     self.assertEquals(evalresult['modeluri'],
         rometa.getComponentUriAbs("Minim-UserRequirements.rdf#missingMayRequirement"))
     self.deleteTestRo(rodir)
     return
Exemplo n.º 10
0
 def testGetConstraintsRemote(self):
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     # Read Minim as graph, scan constraints and look for expected value
     minimgraph = ro_minim.readMinimGraph(minimbase)
     constraints = ro_minim.getConstraints(minimgraph)
     expected_found = False
     for c in constraints:
         if ( c['target']   == rouri                      and
              c['purpose']  == rdflib.Literal("Runnable") and
              c['model']    == model                      and
              c['uri']      == constraint ) :
             expected_found = True
             break
     self.assertTrue(expected_found, "Expected constraint not found in minim")
     return
Exemplo n.º 11
0
 def testMinimReadRemote(self):
     """
     Basic test that remote Minim test file can be read
     """
     rouri      = rdflib.URIRef(remotehost+remoterobase+remoteroname)
     minimbase  = rdflib.URIRef(remotehost+remoterobase+remoteroname+remoteminim)
     constraint = ro_minim.getElementUri(minimbase, "#runnable_RO")
     model      = ro_minim.getElementUri(minimbase, "#runnable_RO_model")
     target     = rouri
     g = ro_minim.readMinimGraph(minimbase)
     expected_minim = (
         [ (target,     MINIM.hasConstraint, constraint                 )
         , (constraint, MINIM.forPurpose,    rdflib.Literal('Runnable') )
         , (constraint, MINIM.toModel,       model                      )
         , (model,      RDF.type,            MINIM.Model                )
         ])
     self.checkTargetGraph(g, expected_minim, msg="Not found in Minim")
     return
Exemplo n.º 12
0
 def testGetModel(self):
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-2", "RO test minim", "ro-testMinim")
     rouri      = ro_manifest.getRoUri(rodir)
     minimbase  = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements2.rdf")
     model      = ro_minim.getElementUri(minimbase, "#runnableRO")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     m = ro_minim.getModel(minimgraph, model)
     self.assertEquals(m['label'], rdflib.Literal("Runnable RO"))
     self.assertEquals(m['uri'],   model)
     return
Exemplo n.º 13
0
 def testGetConstraints(self):
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-2", "RO test minim", "ro-testMinim")
     rouri      = ro_manifest.getRoUri(rodir)
     minimbase  = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements2.rdf")
     model      = ro_minim.getElementUri(minimbase, "#runnableRO")
     constraint = ro_minim.getElementUri(minimbase, "#create/data/UserRequirements-astro.ods")
     # Read Minim as graph, scan constraints and look for expected value
     minimgraph = ro_minim.readMinimGraph(minimbase)
     constraints = ro_minim.getConstraints(minimgraph)
     expected_found = False
     for c in constraints:
         if ( c['target']   == ro_manifest.getComponentUri(rodir, "data/UserRequirements-astro.ods") and
              c['purpose']  == rdflib.Literal("create UserRequirements-astro.ods")                   and
              c['model']    == model                                                                 and
              c['uri']      == constraint ) :
             expected_found = True
             break
     self.assertTrue(expected_found, "Expected constraint not found in minim")
     return
Exemplo n.º 14
0
 def testMinimRead(self):
     """
     Basic test that Minim test file can be read
     """
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-2", "RO test minim", "ro-testMinim")
     rouri      = ro_manifest.getRoUri(rodir)
     minimbase  = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements2.rdf")
     target     = ro_manifest.getComponentUri(rodir, "data/UserRequirements-astro.ods")
     constraint = ro_minim.getElementUri(minimbase, "#create/data/UserRequirements-astro.ods")
     model      = ro_minim.getElementUri(minimbase, "#runnableRO")
     g = ro_minim.readMinimGraph(minimbase)
     expected_minim = (
         [ (target,     MINIM.hasChecklist,  constraint                                          )
         , (constraint, MINIM.forPurpose,    rdflib.Literal('create UserRequirements-astro.ods') )
         , (constraint, MINIM.toModel,       model                                               )
         , (model,      RDF.type,            MINIM.Model                                         )
         ])
     self.checkTargetGraph(g, expected_minim, msg="Not found in Minim")
     self.deleteTestRo(rodir)
     return
Exemplo n.º 15
0
 def testGetModels(self):
     self.setupConfig()
     rodir      = self.createTestRo(testbase, "test-data-2", "RO test minim", "ro-testMinim")
     rouri      = ro_manifest.getRoUri(rodir)
     minimbase  = ro_manifest.getComponentUri(rodir, "Minim-UserRequirements2.rdf")
     model      = ro_minim.getElementUri(minimbase, "#runnableRO")
     minimgraph = ro_minim.readMinimGraph(minimbase)
     models     = ro_minim.getModels(minimgraph)
     expected_found = False
     for m in models:
         if ( m['label']  == rdflib.Literal("Runnable RO") and
              m['uri']    == model ) :
             expected_found = True
             break
     self.assertTrue(expected_found, "Expected model not found in minim")
     return
Exemplo n.º 16
0
 def setupEvalFormat(self):
     self.setupConfig()
     rodir     = self.createTestRo(testbase, "test-data-1", "RO test minim", "ro-testMinim")
     rometa    = ro_metadata(ro_config, rodir)
     minimbase = rometa.getComponentUri("Minim-UserRequirements.rdf")
     modeluri  = ro_minim.getElementUri(minimbase, "#test-formatting-constraint")
     self.missing_must = (
         { 'level': "MUST"
         , 'model': modeluri 
         , 'label': rdflib.Literal("aggregates data/UserRequirements-bio.ods")
         , 'datarule':
           { 'aggregates': rometa.getComponentUri("data/UserRequirements-bio.ods")
           , 'show':       None
           , 'showpass':   None
           , 'showfail':   None
           , 'showmiss':   None
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/data/UserRequirements-bio.ods") 
         })
     self.missing_should = (
         { 'level': "SHOULD"
         , 'model': modeluri 
         , 'label': rdflib.Literal("aggregates docs/missing.css")
         , 'datarule':
           { 'aggregates': rometa.getComponentUri("docs/missing.css")
           , 'show':       None
           , 'showpass':   None
           , 'showfail':   None
           , 'showmiss':   None
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/docs/missing.css") 
         })
     self.missing_may = (
         { 'level': "MAY"
         , 'model': modeluri 
         , 'label': rdflib.Literal("aggregates docs/missing.css")
         , 'datarule':
           { 'aggregates': rometa.getComponentUri("docs/missing.css")
           , 'show':       None
           , 'showpass':   None
           , 'showfail':   None
           , 'showmiss':   None
           }
         , 'uri': ro_minim.getElementUri(minimbase, "#isPresent/docs/missing.css") 
         })
     self.eval_result = (
         { 'summary':        [MINIM.nominallySatisfies, MINIM.minimallySatisfies]
         , 'missingMust':    [(self.missing_must,   {})]
         , 'missingShould':  [(self.missing_should, {})]
         , 'missingMay':     [(self.missing_may,    {})]
         , 'satisfied':      []
         , 'rodir':          rodir
         , 'rouri':          rometa.getRoUri()
         , 'minimuri':       minimbase
         , 'target':         "test-formatting-target"
         , 'purpose':        "test formatting"
         , 'constrainturi':  rometa.getComponentUri("Minim-UserRequirements.rdf#test-formatting-constraint")
         , 'modeluri':       rometa.getComponentUri("Minim-UserRequirements.rdf#test-formatting-constraint")
         })
     self.deleteTestRo(rodir)
     return rodir