Esempio n. 1
0
    def test_all_nodes(self):
        outf = StringIO()
        with (redirect_stderr(outf)):
            evaluate_cli(
                f"{rdffile} {shexfile} -s http://example.org/shapes/S".split())
        self.assertEqual(
            'Error: You must specify one or more graph focus nodes, supply a SPARQL query, '
            'or use the "-A" option',
            outf.getvalue().strip())
        outf = StringIO()
        with (redirect_stdout(outf)):
            evaluate_cli(
                f"{rdffile} {shexfile}  -A -s http://example.org/shapes/S".
                split())
        self.assertEqual(
            """Errors:
  Focus: http://a.example/s1
  Start: http://example.org/shapes/S
  Reason:   Testing :s1 against shape http://example.org/shapes/S
       No matching triples found for predicate :s4

  Focus: http://a.example/s2
  Start: http://example.org/shapes/S
  Reason:   Testing :s2 against shape http://example.org/shapes/S
       No matching triples found for predicate :s4

  Focus: http://a.example/s3
  Start: http://example.org/shapes/S
  Reason:   Testing :s3 against shape http://example.org/shapes/S
       No matching triples found for predicate :s4""",
            outf.getvalue().strip())
Esempio n. 2
0
   def test_nostart(self):
       outf = StringIO()
       with (redirect_stdout(outf)):
           evaluate_cli(f"{rdffile} {shexfile} -A".split())
       self.assertEqual(
           """Errors:
 Focus: None
 Start: None
 Reason: START node is not specified""",
           outf.getvalue().strip())
Esempio n. 3
0
    def test_inline_rdf(self):
        """ Issue #28. Make sure inline SPARQL with no carriage return works """
        shex = os.path.join(data_dir, 'biolink-model.shex')
        sparql = 'select ?item where{graph ?g {?item a <http://w3id.org/biolink/vocab/Protein>}}'

        # This raises an InvalidSchema error
        messages = StringIO()
        with redirect_stdout(messages):
            evaluate_cli((['-ss', '-sq', sparql, 'http://graphdb.dumontierlab.com/repositories/ncats-red-kg',
                           shex, '-ut', '-pb']))
        print(messages.getvalue())
Esempio n. 4
0
 def test_messages(self):
     """ Test failures with no reasons supplied """
     shex = os.path.join(data_dir, 'biolink-model.shex')
     sparql = os.path.join(data_dir, 'biolink_model.sparql')
     messages = StringIO()
     with redirect_stdout(messages):
         evaluate_cli(
             f'-ss -sq {sparql}  http://graphdb.dumontierlab.com/repositories/ncats-red-kg {shex} -ut -pb'
         )
     for line in messages.getvalue().split('\n'):
         self.assertFalse(line.strip().endswith('Reason:'))
Esempio n. 5
0
 def test_observation_online(self):
     """ Test online FHIR example """
     source_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'data')
     result = os.path.join(source_dir, 'example-haplotype2.results')
     outf = StringIO()
     with (redirect_stdout(outf)):
         evaluate_cli(
             "http://build.fhir.org/observation-example-haplotype2.ttl "
             "http://build.fhir.org/observation.shex "
             "-fn http://hl7.org/fhir/Observation/example-haplotype2")
     with open(result) as f:
         self.assertEqual(f.read(), outf.getvalue())
Esempio n. 6
0
 def test_obseration(self):
     """ Test of local FHIR example """
     source_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
     rdf = os.path.join(source_dir, 'example-haplotype2.ttl')
     shex = os.path.join(source_dir, 'observation.shex')
     result = os.path.join(source_dir, 'example-haplotype2.results')
     outf = StringIO()
     with(redirect_stdout(outf)):
         evaluate_cli(f"{rdf} {shex} -fn http://hl7.org/fhir/Observation/example-haplotype2")
     if not os.path.exists(result):
         with open(result, 'w') as f:
             f.write(outf.getvalue())
         self.assertTrue(False, "Created test file -- rerun ")
     with open(result) as f:
         self.assertEqual(f.read(), outf.getvalue())
Esempio n. 7
0
    def test_fail(self):
        """ Test max cardinality of 0 AND error reporting """
        datadir = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'data'))
        shexpath = os.path.join(datadir, 'issue_20.shex')
        rdfpath = os.path.join(datadir, 'issue_20.ttl')
        expectedpath = os.path.join(datadir, 'issue_20.errors')

        pl = PrefixLibrary(rdfpath)
        output = StringIO()
        with redirect_stdout(output):
            evaluate_cli(f"{rdfpath} {shexpath} -fn {pl.EX.BPM1}")
            evaluate_cli(f"{rdfpath} {shexpath} -fn {pl.EX.BPM2}")

        if not os.path.exists(expectedpath):
            with open(expectedpath, 'w') as f:
                f.write(output.getvalue())
            self.assertTrue(False, "Output created, rerun")
        with open(expectedpath) as f:
            expected = f.read()

        self.maxDiff = None
        self.assertEqual(expected, output.getvalue())
Esempio n. 8
0
 def prog_ep(self, argv: List[str]) -> bool:
     return bool(evaluate_cli(argv, prog=self.testprog))
Esempio n. 9
0
 def test_anon_start(self):
     self.assertEqual(0, evaluate_cli(f"{rdffile} {shexfile} -A"))