Esempio n. 1
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
 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")
           , 'derives':  ro_minim.getElementUri(minimbase, "#environment-software/python-27")
           }
         , '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")
           , 'derives':    ro_minim.getElementUri(minimbase, "#isPresent/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") 
           , 'derives':    ro_minim.getElementUri(minimbase, "#isPresent/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
 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")
           , 'derives':  ro_minim.getElementUri(minimbase, "#environment-software/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
           , 'derives':  ro_minim.getElementUri(minimbase, "#isPresent/workflow-instance")
           , '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
Esempio n. 4
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
Esempio n. 5
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
Esempio 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
Esempio 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
Esempio n. 8
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
Esempio n. 9
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
Esempio 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
Esempio 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
Esempio n. 12
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
Esempio n. 13
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