mustrd 0.3.1a5__py3-none-any.whl → 0.3.1a6__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/mustrdAnzo.py +15 -6
- mustrd/spec_component.py +2 -4
- mustrd/steprunner.py +0 -5
- {mustrd-0.3.1a5.dist-info → mustrd-0.3.1a6.dist-info}/METADATA +86 -18
- {mustrd-0.3.1a5.dist-info → mustrd-0.3.1a6.dist-info}/RECORD +8 -8
- {mustrd-0.3.1a5.dist-info → mustrd-0.3.1a6.dist-info}/LICENSE +0 -0
- {mustrd-0.3.1a5.dist-info → mustrd-0.3.1a6.dist-info}/WHEEL +0 -0
- {mustrd-0.3.1a5.dist-info → mustrd-0.3.1a6.dist-info}/entry_points.txt +0 -0
mustrd/mustrdAnzo.py
CHANGED
@@ -122,8 +122,11 @@ def get_query_from_step(triple_store: dict, query_step_uri: URIRef) -> str:
|
|
122
122
|
?stepUri a <http://cambridgesemantics.com/ontologies/Graphmarts#Step>;
|
123
123
|
<http://cambridgesemantics.com/ontologies/Graphmarts#transformQuery> ?query
|
124
124
|
}}"""
|
125
|
-
|
126
|
-
|
125
|
+
result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
|
126
|
+
if len(result) == 0:
|
127
|
+
raise FileNotFoundError(
|
128
|
+
f"Querynot found for step {query_step_uri}")
|
129
|
+
return result[0].get("query")
|
127
130
|
|
128
131
|
def get_queries_from_templated_step(triple_store: dict, query_step_uri: URIRef) -> dict:
|
129
132
|
query = f"""SELECT ?param_query ?query_template WHERE {{
|
@@ -133,8 +136,11 @@ def get_queries_from_templated_step(triple_store: dict, query_step_uri: URIRef)
|
|
133
136
|
<http://cambridgesemantics.com/ontologies/Graphmarts#template> ?query_template .
|
134
137
|
}}
|
135
138
|
"""
|
136
|
-
|
137
|
-
|
139
|
+
result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
|
140
|
+
if len(result) == 0:
|
141
|
+
raise FileNotFoundError(
|
142
|
+
f"Templated query not found for {query_step_uri}")
|
143
|
+
return result[0]
|
138
144
|
|
139
145
|
def get_queries_for_layer(triple_store: dict, graphmart_layer_uri: URIRef):
|
140
146
|
query = f"""PREFIX graphmarts: <http://cambridgesemantics.com/ontologies/Graphmarts#>
|
@@ -153,8 +159,11 @@ SELECT ?query ?param_query ?query_template
|
|
153
159
|
. }}
|
154
160
|
}}
|
155
161
|
ORDER BY ?index"""
|
156
|
-
|
157
|
-
|
162
|
+
result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
|
163
|
+
if len(result) == 0:
|
164
|
+
raise FileNotFoundError(
|
165
|
+
f"Queries not found for graphmart layer {graphmart_layer_uri}")
|
166
|
+
return result
|
158
167
|
|
159
168
|
def upload_given(triple_store: dict, given: Graph):
|
160
169
|
logging.debug(f"upload_given {triple_store} {given}")
|
mustrd/spec_component.py
CHANGED
@@ -848,9 +848,7 @@ def _get_spec_component_spade_edn_group_source_when(spec_component_details: Spec
|
|
848
848
|
|
849
849
|
if step_type == Keyword("sparql-file"):
|
850
850
|
try:
|
851
|
-
|
852
|
-
resolved_step_file = Path(absolute_file_path).parent / step_file
|
853
|
-
with open(resolved_step_file, 'r') as sparql_file:
|
851
|
+
with open(step_file, 'r') as sparql_file:
|
854
852
|
sparql_query = sparql_file.read()
|
855
853
|
|
856
854
|
# Assume the individuals are ConstructSparql queries
|
@@ -862,7 +860,7 @@ def _get_spec_component_spade_edn_group_source_when(spec_component_details: Spec
|
|
862
860
|
)
|
863
861
|
when_specs.append(when_spec)
|
864
862
|
except FileNotFoundError:
|
865
|
-
raise ValueError(f"SPARQL file not found: {
|
863
|
+
raise ValueError(f"SPARQL file not found: {step_file}")
|
866
864
|
|
867
865
|
spec_component.file = str(absolute_file_path)
|
868
866
|
spec_component.groupId = group_id
|
mustrd/steprunner.py
CHANGED
@@ -185,17 +185,12 @@ def _spade_edn_group_source(spec_uri: URIRef, triple_store: dict, when: SpadeEdn
|
|
185
185
|
def _spade_edn_group_source(spec_uri: URIRef, triple_store: dict, when: SpadeEdnGroupSourceWhenSpec):
|
186
186
|
log.info(f"Running SpadeEdnGroupSource for {spec_uri} using {triple_store}")
|
187
187
|
|
188
|
-
edn_file_dir = os.path.dirname(when.file) # Get the directory of the EDN file
|
189
188
|
merged_graph = Graph()
|
190
189
|
|
191
190
|
# Iterate over the list of WhenSpec objects in `when.value`
|
192
191
|
for step_when_spec in when.value:
|
193
192
|
try:
|
194
193
|
if step_when_spec.queryType == MUST.UpdateSparql:
|
195
|
-
# Resolve file paths relative to the EDN file
|
196
|
-
if hasattr(step_when_spec, 'filepath'):
|
197
|
-
step_when_spec.filepath = os.path.join(edn_file_dir, step_when_spec.filepath)
|
198
|
-
|
199
194
|
log.info(f"Dispatching run_when for UpdateSparql step: {step_when_spec}")
|
200
195
|
query_result = run_when_impl(spec_uri, triple_store, step_when_spec)
|
201
196
|
log.info(f"Executed SPARQL query: {query_result}")
|
@@ -1,14 +1,19 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: mustrd
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.1a6
|
4
4
|
Summary: A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber.
|
5
5
|
License: MIT
|
6
6
|
Author: John Placek
|
7
7
|
Author-email: john.placek@semanticpartners.com
|
8
|
-
Requires-Python: >=3.
|
9
|
-
Classifier: Programming Language :: Python
|
8
|
+
Requires-Python: >=3.11,<4.0
|
10
9
|
Classifier: Framework :: Pytest
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
11
11
|
Classifier: Natural Language :: English
|
12
|
+
Classifier: Programming Language :: Python
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
12
17
|
Classifier: Topic :: Software Development :: Quality Assurance
|
13
18
|
Classifier: Topic :: Software Development :: Testing
|
14
19
|
Classifier: Topic :: Utilities
|
@@ -34,13 +39,13 @@ Requires-Dist: urllib3 (==1.26.19)
|
|
34
39
|
Project-URL: Repository, https://github.com/Semantic-partners/mustrd
|
35
40
|
Description-Content-Type: text/markdown
|
36
41
|
|
37
|
-
#
|
42
|
+
# MustRD
|
38
43
|
|
39
44
|
**"MustRD: Validate your SPARQL queries and transformations with precision and confidence, using BDD and Given-When-Then principles."**
|
40
45
|
|
41
|
-
[
|
46
|
+
[](https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data)
|
42
47
|
|
43
|
-
|
48
|
+
## Why?
|
44
49
|
|
45
50
|
SPARQL is a powerful query language for RDF data, but how can you ensure your queries and transformations are doing what you intend? Whether you're working on a pipeline or a standalone query, certainty is key.
|
46
51
|
|
@@ -48,11 +53,11 @@ While RDF and SPARQL offer great flexibility, we noticed a gap in tooling to val
|
|
48
53
|
|
49
54
|
With MustRD, you can:
|
50
55
|
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
- Define data scenarios and verify that queries produce the expected results.
|
57
|
+
- Test edge cases to ensure your queries remain reliable.
|
58
|
+
- Isolate small SPARQL enrichment or transformation steps and confirm you're only inserting what you intend.
|
54
59
|
|
55
|
-
|
60
|
+
## What?
|
56
61
|
|
57
62
|
MustRD is a Spec-By-Example ontology with a reference Python implementation, inspired by tools like Cucumber. It uses the Given-When-Then approach to define and validate SPARQL queries and transformations.
|
58
63
|
|
@@ -62,23 +67,85 @@ MustRD is designed to be triplestore/SPARQL engine agnostic, leveraging open sta
|
|
62
67
|
|
63
68
|
MustRD is not an alternative to SHACL. While SHACL validates data structures, MustRD focuses on validating data transformations and query results.
|
64
69
|
|
65
|
-
|
70
|
+
## How?
|
66
71
|
|
67
72
|
You define your specs in Turtle (`.ttl`) or TriG (`.trig`) files using the Given-When-Then approach:
|
68
73
|
|
69
|
-
|
70
|
-
|
71
|
-
|
74
|
+
- **Given**: Define the starting dataset.
|
75
|
+
- **When**: Specify the action (e.g., a SPARQL query).
|
76
|
+
- **Then**: Outline the expected results.
|
72
77
|
|
73
78
|
Depending on the type of SPARQL query (CONSTRUCT, SELECT, INSERT/DELETE), MustRD runs the query and compares the results against the expectations defined in the spec.
|
74
79
|
|
75
80
|
Expectations can also be defined as:
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
- INSERT queries.
|
83
|
+
- SELECT queries.
|
84
|
+
- Higher-order expectation languages, similar to those used in various platforms.
|
85
|
+
|
86
|
+
## Example
|
87
|
+
|
88
|
+
### Configuration File
|
89
|
+
|
90
|
+
You'll have a configuration `.ttl` file, which acts as a suite of tests. It tells MustRD where to look for test specifications and any triplestore configurations you might have:
|
91
|
+
|
92
|
+
```ttl
|
93
|
+
:test_example a :MustrdTest;
|
94
|
+
:hasSpecPath "test/specs/";
|
95
|
+
:hasDataPath "test/data/";
|
96
|
+
:hasPytestPath "example";
|
97
|
+
:triplestoreSpecPath "test/triplestore_config/triplestores.ttl";
|
98
|
+
:filterOnTripleStore triplestore:example_test .
|
99
|
+
```
|
100
|
+
|
101
|
+
### Test Specification
|
102
|
+
|
103
|
+
In the directory specified by `:hasSpecPath`, you'll have one or more `.mustrd.ttl` files. These can be organized in a directory structure. MustRD collects them and reports results to your test runner.
|
104
|
+
|
105
|
+
```ttl
|
106
|
+
:test_example :given [ a :FileDataset ;
|
107
|
+
:file "test/data/given.ttl" ] ;
|
108
|
+
:when [ a :TextSparqlSource ;
|
109
|
+
:queryText "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" ;
|
110
|
+
:queryType :SelectSparql ] ;
|
111
|
+
:then [ a :OrderedTableDataset ;
|
112
|
+
:hasRow [ :variable "s" ; :boundValue "example:subject" ;
|
113
|
+
:variable "p" ; :boundValue "example:predicate" ;
|
114
|
+
:variable "o" ; :boundValue "example:object" ] ].
|
115
|
+
```
|
80
116
|
|
81
|
-
|
117
|
+
And you will have a `'test/data/given.ttl'` which contains the given ttl.
|
118
|
+
|
119
|
+
```ttl
|
120
|
+
example:subject example:predicate example:object .
|
121
|
+
```
|
122
|
+
|
123
|
+
### Running Tests
|
124
|
+
|
125
|
+
Run the test using the MustRD Pytest plugin:
|
126
|
+
|
127
|
+
```bash
|
128
|
+
poetry run pytest --mustrd --config=test/mustrd_configuration.ttl --md=render/github_job_summary.md
|
129
|
+
```
|
130
|
+
|
131
|
+
This will validate your SPARQL queries against the defined dataset and expected results, ensuring your transformations behave as intended.
|
132
|
+
|
133
|
+
You can refer to SPARQL inline, in files, or in Anzo Graphmarts, Steps, or Layers. See `GETSTARTED.adoc` for more details.
|
134
|
+
|
135
|
+
#### Integrating with Visual Studio Code (vscode)
|
136
|
+
We have a pytest plugin.
|
137
|
+
1. Choose a python interpreter (probably a venv)
|
138
|
+
2. `pip install mustrd ` in it.
|
139
|
+
3. add to your settings.json
|
140
|
+
```json
|
141
|
+
"python.testing.pytestArgs": [
|
142
|
+
"--mustrd", "--md=junit/github_job_summary.md", "--config=test/test_config_local.ttl"
|
143
|
+
],
|
144
|
+
```
|
145
|
+
4. VS Code should auto discover your tests and they'll show up in the flask icon 'tab'.
|
146
|
+

|
147
|
+
|
148
|
+
## When?
|
82
149
|
|
83
150
|
MustRD is a work in progress, built to meet the needs of our projects across multiple clients and vendor stacks. While we find it useful, it may not meet your needs out of the box.
|
84
151
|
|
@@ -89,3 +156,4 @@ We invite you to try it, raise issues, or contribute via pull requests. If you n
|
|
89
156
|
Semantic Partners is a specialist consultancy in Semantic Technology. If you need more support, contact us at info@semanticpartners.com or mustrd@semanticpartners.com.
|
90
157
|
|
91
158
|
|
159
|
+
|
@@ -13,20 +13,20 @@ mustrd/model/test-resources/resources.ttl,sha256=1Dsp1nuNxauj9bxeX-HShQsiO-CVy5I
|
|
13
13
|
mustrd/model/triplestoreOntology.ttl,sha256=9K5gj0hDOolRYjHc58UT4igex8cUnq9h7SUe4ToYbdw,5834
|
14
14
|
mustrd/model/triplestoreshapes.ttl,sha256=G1kdgASdPa8s5JVGXL4KM2ewp-F5Vmbdist0f77VTBc,1706
|
15
15
|
mustrd/mustrd.py,sha256=Ac42FUVY_6u1rt8uQmmIRo6-lV1vmOTy5fNu1CqPEIQ,41021
|
16
|
-
mustrd/mustrdAnzo.py,sha256=
|
16
|
+
mustrd/mustrdAnzo.py,sha256=Ick0phX4B0bSWw5LrsEFfn7X203RQJW8sPRr62fZTxU,8783
|
17
17
|
mustrd/mustrdGraphDb.py,sha256=Ro_fxDPFl64r-FAM18awhZydydEY1-IXO0zdKpvZD3U,5405
|
18
18
|
mustrd/mustrdRdfLib.py,sha256=1dYoyohjDhonKItYMNkFybySFt9lgez3zYN2kU9mW-I,2369
|
19
19
|
mustrd/mustrdTestPlugin.py,sha256=hbYo8i1j4uFuRekXGd4Mnjt9wkSgQrS5o809xtbcLgs,19664
|
20
20
|
mustrd/namespace.py,sha256=1l8RJDFI7rYkWvmRokaTvSvqrDJEdRNIkq3lmPb0xpI,3854
|
21
21
|
mustrd/run.py,sha256=5xZUgKPMBQ-03cWROAnwtbOs2Nb0Vat6n8Fi6EyfS-k,4257
|
22
|
-
mustrd/spec_component.py,sha256=
|
23
|
-
mustrd/steprunner.py,sha256=
|
22
|
+
mustrd/spec_component.py,sha256=FQPLX5W0wGOLUOJgPxf-9YpyNhMYnV3xU2nJch99NOI,38452
|
23
|
+
mustrd/steprunner.py,sha256=BHY4UhN7oqHVoXYPk4ROnv0nCqy4-NXfbzFzOyb3G4k,10032
|
24
24
|
mustrd/templates/md_ResultList_leaf_template.jinja,sha256=IzwZjliCx7-viipATDQK6MQg_5q1kLMKdeNSZg1sXXY,508
|
25
25
|
mustrd/templates/md_ResultList_template.jinja,sha256=_8joJ7vtw_qoqxv3HhUtBgRfhOeqmgfaRFwEo4MROvQ,203
|
26
26
|
mustrd/templates/md_stats_template.jinja,sha256=96W62cMWu9UGLNv65ZQ8RYLjkxKHhJy-FlUtXgud6XY,155
|
27
27
|
mustrd/utils.py,sha256=OGdLvw7GvjrFgTJo0J97Xwdh-_ZgSmapmOistrEchO0,1387
|
28
|
-
mustrd-0.3.
|
29
|
-
mustrd-0.3.
|
30
|
-
mustrd-0.3.
|
31
|
-
mustrd-0.3.
|
32
|
-
mustrd-0.3.
|
28
|
+
mustrd-0.3.1a6.dist-info/LICENSE,sha256=r8nmh5fUct9h2w8_RDl13EIscvmwCLoarPr1kg35MnA,1078
|
29
|
+
mustrd-0.3.1a6.dist-info/METADATA,sha256=H2Bu5MUHmU4srpHpcm6xGHch30h2G9QX45lvIWyhUPI,6677
|
30
|
+
mustrd-0.3.1a6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
31
|
+
mustrd-0.3.1a6.dist-info/entry_points.txt,sha256=v7V7sN0_L1aB4Ug_9io5axlQSeJ1C0tNrQWwdXdV58s,50
|
32
|
+
mustrd-0.3.1a6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|