aboutsummaryrefslogtreecommitdiff
path: root/test/test_shex.py
diff options
context:
space:
mode:
authorlltommy2020-11-11 09:56:12 +0100
committerlltommy2020-11-11 09:56:12 +0100
commitd6aa323b6fc7a82e45cc1df51fc72c2d547146eb (patch)
tree6e8b77bde4dc34fab3fa8804906f3cb821f61dae /test/test_shex.py
parentc5fe5de7e4c77bfb48b1ae2f662c2d9cc120c06e (diff)
parentc872248e43c1c66e5fed8ef341f7b4ac21d63e6f (diff)
downloadbh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.tar.gz
bh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.tar.lz
bh20-seq-resource-d6aa323b6fc7a82e45cc1df51fc72c2d547146eb.zip
Merge branch 'master' of https://github.com/arvados/bh20-seq-resource
Diffstat (limited to 'test/test_shex.py')
-rw-r--r--test/test_shex.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/test_shex.py b/test/test_shex.py
new file mode 100644
index 0000000..728bfdc
--- /dev/null
+++ b/test/test_shex.py
@@ -0,0 +1,36 @@
+# Run with python3 test/test_shex.py
+
+import schema_salad.schema
+import schema_salad.ref_resolver
+import schema_salad.jsonld_context
+from pyshex.evaluate import evaluate
+import unittest
+
+class TestShexMethods(unittest.TestCase):
+
+ def test_schema(self):
+ with open("bh20sequploader/bh20seq-schema.yml") as schema_resource:
+ metadata_schema = schema_salad.schema.load_schema("bh20sequploader/bh20seq-schema.yml")
+ (document_loader,
+ avsc_names,
+ schema_metadata,
+ metaschema_loader) = metadata_schema
+ # print(metadata_schema)
+ self.assertTrue(isinstance(avsc_names, schema_salad.avro.schema.Names))
+ metadatafile = "test/data/input/TN_UT2.yaml"
+ doc, metadata = schema_salad.schema.load_and_validate(document_loader, avsc_names, metadatafile, True)
+ print(doc)
+ g = schema_salad.jsonld_context.makerdf("workflow", doc, document_loader.ctx)
+ with open("bh20sequploader/bh20seq-shex.rdf") as f:
+ shex = f.read()
+ # Note the https link simply acts as a URI descriptor (it does not fetch)
+ rslt, reason = evaluate(g, shex, doc["id"], "https://raw.githubusercontent.com/arvados/bh20-seq-resource/master/bh20sequploader/bh20seq-shex.rdf#submissionShape")
+
+ with open("test/data/regression/TN_UT2.rdf","w") as f:
+ f.write(g.serialize(format="ntriples").decode("utf-8"))
+
+ if not rslt:
+ raise Exception(reason)
+
+if __name__ == '__main__':
+ unittest.main()