mustrd 0.2.0__py3-none-any.whl → 0.2.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mustrd/steprunner.py DELETED
@@ -1,166 +0,0 @@
1
- """
2
- MIT License
3
-
4
- Copyright (c) 2023 Semantic Partners Ltd
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- """
24
-
25
- import json
26
-
27
- from . import logger_setup
28
- from multimethods import MultiMethod, Default
29
- from .namespace import MUST, TRIPLESTORE
30
- from rdflib import Graph, URIRef
31
- from .mustrdRdfLib import execute_select as execute_select_rdflib
32
- from .mustrdRdfLib import execute_construct as execute_construct_rdflib
33
- from .mustrdRdfLib import execute_update as execute_update_rdflib
34
- from .mustrdAnzo import upload_given as upload_given_anzo
35
- from .mustrdAnzo import execute_update as execute_update_anzo
36
- from .mustrdAnzo import execute_construct as execute_construct_anzo
37
- from .mustrdAnzo import execute_select as execute_select_anzo
38
- from .mustrdGraphDb import upload_given as upload_given_graphdb
39
- from .mustrdGraphDb import execute_update as execute_update_graphdb
40
- from .mustrdGraphDb import execute_construct as execute_construct_graphdb
41
- from .mustrdGraphDb import execute_select as execute_select_graphdb
42
- from .spec_component import AnzoWhenSpec, WhenSpec
43
-
44
- log = logger_setup.setup_logger(__name__)
45
-
46
-
47
- def dispatch_upload_given(triple_store: dict, given: Graph):
48
- ts = triple_store['type']
49
- log.info(f"dispatch_upload_given to {ts}")
50
- return ts
51
-
52
-
53
- upload_given = MultiMethod('upload_given', dispatch_upload_given)
54
-
55
-
56
- @upload_given.method(TRIPLESTORE.RdfLib)
57
- def _upload_given_rdflib(triple_store: dict, given: Graph):
58
- triple_store["given"] = given
59
-
60
-
61
- @upload_given.method(TRIPLESTORE.GraphDb)
62
- def _upload_given_graphdb(triple_store: dict, given: Graph):
63
- upload_given_graphdb(triple_store, given)
64
-
65
-
66
- @upload_given.method(TRIPLESTORE.Anzo)
67
- def _upload_given_anzo(triple_store: dict, given: Graph):
68
- upload_given_anzo(triple_store, given)
69
-
70
-
71
- def dispatch_run_when(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
72
- ts = triple_store['type']
73
- query_type = when.queryType
74
- log.info(f"dispatch_run_when to SPARQL type {query_type} to {ts}")
75
- return ts, query_type
76
-
77
-
78
- run_when = MultiMethod('run_when', dispatch_run_when)
79
-
80
-
81
- @run_when.method((TRIPLESTORE.Anzo, MUST.UpdateSparql))
82
- def _anzo_run_when_update(spec_uri: URIRef, triple_store: dict, when: AnzoWhenSpec):
83
- return execute_update_anzo(triple_store, when.value, when.bindings)
84
-
85
-
86
- @run_when.method((TRIPLESTORE.Anzo, MUST.ConstructSparql))
87
- def _anzo_run_when_construct(spec_uri: URIRef, triple_store: dict, when: AnzoWhenSpec):
88
- return execute_construct_anzo(triple_store, when.value, when.bindings)
89
-
90
-
91
- @run_when.method((TRIPLESTORE.Anzo, MUST.SelectSparql))
92
- def _anzo_run_when_select(spec_uri: URIRef, triple_store: dict, when: AnzoWhenSpec):
93
- return execute_select_anzo(triple_store, when.value, when.bindings)
94
-
95
-
96
- @run_when.method((TRIPLESTORE.GraphDb, MUST.UpdateSparql))
97
- def _graphdb_run_when_update(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
98
- return execute_update_graphdb(triple_store, when.value, when.bindings)
99
-
100
-
101
- @run_when.method((TRIPLESTORE.GraphDb, MUST.ConstructSparql))
102
- def _graphdb_run_when_construct(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
103
- return execute_construct_graphdb(triple_store, when.value, when.bindings)
104
-
105
-
106
- @run_when.method((TRIPLESTORE.GraphDb, MUST.SelectSparql))
107
- def _graphdb_run_when_select(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
108
- return execute_select_graphdb(triple_store, when.value, when.bindings)
109
-
110
-
111
- @run_when.method((TRIPLESTORE.RdfLib, MUST.UpdateSparql))
112
- def _rdflib_run_when_update(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
113
- return execute_update_rdflib(triple_store, triple_store["given"], when.value, when.bindings)
114
-
115
-
116
- @run_when.method((TRIPLESTORE.RdfLib, MUST.ConstructSparql))
117
- def _rdflib_run_when_construct(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
118
- return execute_construct_rdflib(triple_store, triple_store["given"], when.value, when.bindings)
119
-
120
-
121
- @run_when.method((TRIPLESTORE.RdfLib, MUST.SelectSparql))
122
- def _rdflib_run_when_select(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
123
- return execute_select_rdflib(triple_store, triple_store["given"], when.value, when.bindings)
124
-
125
-
126
- @run_when.method((TRIPLESTORE.Anzo, MUST.AnzoQueryDrivenUpdateSparql))
127
- def _multi_run_when_anzo_query_driven_update(spec_uri: URIRef, triple_store: dict, when: AnzoWhenSpec):
128
- # run the parameters query to obtain the values for the template step and put them into a dictionary
129
- query_parameters = json.loads(execute_select_anzo(triple_store, when.paramQuery, None))
130
- if len(query_parameters['results']['bindings']) > 0:
131
- # replace the anzo query placeholders with the input and output graphs
132
- when_template = when.queryTemplate.replace(
133
- "${usingSources}",
134
- f"USING <{triple_store['input_graph']}> \nUSING <{triple_store['output_graph']}>").replace(
135
- "${targetGraph}", f"<{triple_store['output_graph']}>")
136
-
137
- # for each set of parameters insert their values into the template an run it
138
- for params in query_parameters['results']['bindings']:
139
- when_query = when_template
140
- for param in params:
141
- if params[param].get('datatype'):
142
- value = params[param]['value']
143
- else:
144
- if params[param]['type'] == 'uri':
145
- value = '<' + params[param]['value'] + '>'
146
- else:
147
- value = '"' + params[param]['value'] + '"'
148
- when_query = when_query.replace("${" + param + "}", value)
149
- result = execute_update_anzo(triple_store, when_query, None)
150
- return result
151
-
152
-
153
- @run_when.method(Default)
154
- def _multi_run_when_default(spec_uri: URIRef, triple_store: dict, when: WhenSpec):
155
- if when.queryType == MUST.AskSparql:
156
- log.warning(f"Skipping {spec_uri}, SPARQL ASK not implemented.")
157
- msg = "SPARQL ASK not implemented."
158
- elif when.queryType == MUST.DescribeSparql:
159
- log.warning(f"Skipping {spec_uri}, SPARQL DESCRIBE not implemented.")
160
- msg = "SPARQL DESCRIBE not implemented."
161
- elif triple_store['type'] not in [TRIPLESTORE.Anzo, TRIPLESTORE.GraphDb, TRIPLESTORE.RdfLib]:
162
- msg = f"{when.queryType} not implemented for {triple_store['type']}"
163
- else:
164
- log.warning(f"Skipping {spec_uri}, {when.queryType} is not a valid SPARQL query type.")
165
- msg = f"{when.queryType} is not a valid SPARQL query type."
166
- raise NotImplementedError(msg)
@@ -1,19 +0,0 @@
1
- <table class="table">
2
- <thead>
3
- <tr>
4
- <th scope="col">module</th>
5
- <th scope="col">class</th>
6
- <th scope="col">test</th>
7
- <th scope="col">status</th>
8
- <tr>
9
- </thead>
10
- <tbody>
11
- {% for result in result_list -%}
12
- <tr>
13
- <td>{{result.module_name}}</td>
14
- <td>{{result.class_name}}</td>
15
- <td>{{result.test_name}}</td>
16
- <td>{{result.status}}</td>
17
- </tr>
18
- {% endfor %}</tbody>
19
- </table>
@@ -1,9 +0,0 @@
1
-
2
- {% for result in result_list %}
3
- <details>
4
- {{environment.get_template("md_stats_template.jinja").render(name = result.name, stats = result.stats)}}
5
- <ul>
6
- {{result.render()}}
7
- </ul>
8
- </details>
9
- {% endfor %}
@@ -1,3 +0,0 @@
1
- <summary>
2
- {{name}}: <br/> total: {{stats.count}}, success: {{stats.success_count}}, fail: {{stats.fail_count}}, skipped: {{stats.skipped_count}}
3
- </summary>
@@ -1,5 +0,0 @@
1
- from mustrd.mustrdTestPlugin import run_test_spec
2
-
3
-
4
- def test_unit(unit_tests):
5
- assert run_test_spec(unit_tests.unit_test)
@@ -1,97 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mustrd
3
- Version: 0.2.0
4
- Summary: A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber.
5
- Home-page: https://github.com/Semantic-partners/mustrd
6
- License: MIT
7
- Author: John Placek
8
- Author-email: john.placek@semanticpartners.com
9
- Requires-Python: ==3.11.7
10
- Classifier: Framework :: Pytest
11
- Classifier: License :: OSI Approved :: MIT License
12
- Classifier: Natural Language :: English
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3
15
- Classifier: Topic :: Software Development :: Quality Assurance
16
- Classifier: Topic :: Software Development :: Testing
17
- Classifier: Topic :: Utilities
18
- Requires-Dist: Jinja2 (==3.1.3)
19
- Requires-Dist: beautifulsoup4 (>=4.11.1,<5.0.0)
20
- Requires-Dist: colorama (==0.4.6)
21
- Requires-Dist: colorlog (>=6.7.0,<7.0.0)
22
- Requires-Dist: coverage (==7.4.3)
23
- Requires-Dist: flake8 (==7.0.0)
24
- Requires-Dist: multimethods-py (>=0.5.3,<0.6.0)
25
- Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
26
- Requires-Dist: pandas (>=1.5.2,<2.0.0)
27
- Requires-Dist: pyanzo (>=3.3.10,<4.0.0)
28
- Requires-Dist: pyshacl (>=0.23.0,<0.24.0)
29
- Requires-Dist: pytest (>=7.2.0,<8.0.0)
30
- Requires-Dist: rdflib (>=6.3.2,<7.0.0)
31
- Requires-Dist: requests (>=2.28.2,<3.0.0)
32
- Requires-Dist: tabulate (>=0.9.0,<0.10.0)
33
- Requires-Dist: toml (>=0.10.2,<0.11.0)
34
- Requires-Dist: tomli (>=2.0.1,<3.0.0)
35
- Requires-Dist: urllib3 (==1.26.15)
36
- Project-URL: Repository, https://github.com/Semantic-partners/mustrd
37
- Description-Content-Type: text/plain
38
-
39
- == Mustrd
40
-
41
- // tag::body[]
42
-
43
- image::https://github.com/Semantic-partners/mustrd/raw/python-coverage-comment-action-data/badge.svg[Coverage badge,link="https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data"]
44
-
45
- === Why?
46
-
47
- How do you know your SPARQL, whether it's in a pipeline, or a query, is doing what you intend?
48
-
49
- As much as we love RDF and SPARQL and Semantic Tech in general, we found a small gap in tooling which would give us that certainty.
50
-
51
- We missed the powerful testing frameworks that have evolved in imperative languages that help ensure you've written code that does what you think it should.
52
-
53
- We wanted to be able to:
54
-
55
- * setup data scenarios and ensure queries worked as expected
56
- * setup edge cases for queries and ensure they still work
57
- * isolate small sparql enrichment / transformation steps and to know we're only INSERTing what we intend
58
-
59
- Enter MustRD.
60
-
61
- === What?
62
-
63
- MustRD is a Spec-By-Example ontology, with a reference python implementation, inspired by the likes of Cucumber.
64
-
65
- It's designed to be triplestore/SPARQL engine agnostic (aren't open standards *wonderful*!).
66
-
67
- === What it is NOT
68
- MustRD is nothing to do with SHACL, or an alternative to it. In fact, we use SHACL for some of our features.
69
-
70
- SHACL provides validation around data.
71
-
72
- MustRD provides validation around data transformations.
73
-
74
- === How?
75
- You define your specs in ttl, or trig files.
76
- We use the SBE approach of *Given*, *When*, *Then* to define starting dataset, an action, and a set of expectations. We build up a set of data.
77
- Then, depending on whether your SPARQL is a CONSTRUCT, SELECT or a INSERT/DELETE, we run it, and compare results against a set of expectations (*Then*) that are defined in the same way as a *Given* .
78
- Alternatively, you could define your *Then*
79
-
80
- * as an explicit ASK, or
81
- * select; or
82
- * in a higher-order expectation language like you will be used to in various platforms, a set of expectations.
83
-
84
-
85
- === When?
86
-
87
- Soon. It's a work in progress, and we're building the things *we* need for the projects we work on at multiple clients, with multiple vendor stacks.
88
- We already think it's useful, but it might not meet *your* needs, out of the box.
89
-
90
- We invite you to try it, see where it doesn't fit, and raise an issue, or even better, a PR! If you need something custom, please check out our consultancy rates, and we might be able to prioritise a new feature for you.
91
-
92
- == Support
93
- We're a specialist consultancy in Semantic Tech, we're putting this out in case it's useful, but if you need more support, kindly contact our business team on info@semanticpartners.com
94
-
95
- // tag::body[]
96
- include::src/README.adoc[tags=body]
97
-
@@ -1,32 +0,0 @@
1
- mustrd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mustrd/logger_setup.py,sha256=AXTXiiyQ4E_SyqNaKlLsZlkkKr_YJfJZ0N4PEoN7d7E,1630
3
- mustrd/model/catalog-v001.xml,sha256=jgD6VOxR6A8izzr3ZmL4AzaTZ5cVwsvt618MTuRlGBk,386
4
- mustrd/model/mustrdShapes.ttl,sha256=BR-9fAwGpQt6glfPpDB0Xx3vFXMt_UTQwi469o6aWUo,9709
5
- mustrd/model/mustrdTestOntology.ttl,sha256=W7IRbPKrhpYFweZvc9QH8gdjBiuZMHKETIuHBepLnYw,2034
6
- mustrd/model/mustrdTestShapes.ttl,sha256=Bcof6p7MtzO2L6H1DWB1hibLSix7Dxo-z6HlFcG31M8,842
7
- mustrd/model/ontology.ttl,sha256=JF6LG5-T7tbi3QfmJcEFQcFo-rQT0CTYGg7PEmuzINY,17303
8
- mustrd/model/test-resources/resources.ttl,sha256=7z1P4qJwuqRdmHzKd_mhnUIs-aQoSQxas7yDCwKYarc,1558
9
- mustrd/model/triplestoreOntology.ttl,sha256=87leTcKot45AgcCGfJLEwbY9rsuRGHbYbnTFeijrzOk,6199
10
- mustrd/model/triplestoreshapes.ttl,sha256=qiLzbclGDzueH5GCKANEwMM9VxOmswu42FiSnITATeQ,1876
11
- mustrd/mustrd.py,sha256=H-j5s3qQmcmJ9g39Q9z5z075HJ5iMapM8OcY8HgcwJs,35081
12
- mustrd/mustrdAnzo.py,sha256=yGoNf93n9MeKMqef8H0qm-1HKvnKm1PO-spekATL6XM,10632
13
- mustrd/mustrdGraphDb.py,sha256=KNXXYyZjYm_IZaeuuxlPBP-XyX9hZ5UvrdxshKnZhwo,5599
14
- mustrd/mustrdQueryProcessor.py,sha256=fpEzD0R7rGy2ktOBSiUpNGevxMSVJxKfxnR3BAg4yRk,6357
15
- mustrd/mustrdRdfLib.py,sha256=LeS-uArlxQwsM-7lrJyp8O8m-6VgxsR1BlpxsOCNePs,2129
16
- mustrd/mustrdTestPlugin.py,sha256=SsTkwrs0n1lvHvuiyQs-z4dsXnjB7p3d6aFWR8_jLV8,15035
17
- mustrd/namespace.py,sha256=3zJbdWEji_2SkhasHK3J2UO3am_phNKDwAFk2htXRYM,3765
18
- mustrd/README.adoc,sha256=y6tY7YDFB6f-vICYJyPN8n615BKLm49lRqqWFWiqrzg,12620
19
- mustrd/run.py,sha256=r3FS_iAuXYpENbbrLfgymGUP4dx-ZGJ_Y2ZvnZdL9dg,4380
20
- mustrd/spec_component.py,sha256=bmfHGE_8uy9yIcbvflWnhEeCW9SCbw86k0E22GQAelk,33304
21
- mustrd/steprunner.py,sha256=n3k4O2SjsLUEG5QOxLG8Z8D3iH9PJzzR63dIV2KHcBE,7555
22
- mustrd/templates/md_ResultList_leaf_template.jinja,sha256=un1XMeNO9xLcry-DmTQ2QoWoTM5Q5CkVUV_LS4O7sHM,526
23
- mustrd/templates/md_ResultList_template.jinja,sha256=RrTaPN1obsTEpG5BjQp7BV9iBFzZOXHwslgvyC0hDKY,211
24
- mustrd/templates/md_stats_template.jinja,sha256=DlNfH9eoEFVHQmvp6QNbQv36cqRLyBkqG1ITOHb_Yu8,157
25
- mustrd/test/test_mustrd.py,sha256=Q2qTTY--I0wfhgHW7hnkIoV3t_sUTXm8xMmirJaFc7o,129
26
- mustrd/TestResult.py,sha256=q5BnvRxhfCEEY062rHasnA61AeKR4oXXs5z8lASvx1o,4986
27
- mustrd/utils.py,sha256=fuvdLE20MdkJtY5atBiU8-u7sVcq1mzIYF0gTcw1UMk,1424
28
- mustrd-0.2.0.dist-info/entry_points.txt,sha256=v7V7sN0_L1aB4Ug_9io5axlQSeJ1C0tNrQWwdXdV58s,50
29
- mustrd-0.2.0.dist-info/LICENSE,sha256=OwjAcbL4HsENdMen1iYR23HH7OEn899oCt100xUo0Zo,1099
30
- mustrd-0.2.0.dist-info/METADATA,sha256=0_uSxV7kB9BlUOd14aTILn9waE18kPWVueSPzjFp8-I,4130
31
- mustrd-0.2.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
- mustrd-0.2.0.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- [pytest11]
2
- mustrd_plugin=mustrd.mustrdTestPlugin
3
-