mustrd 0.3.2__py3-none-any.whl → 0.3.3__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 CHANGED
@@ -98,8 +98,11 @@ def get_query_from_step(triple_store: dict, query_step_uri: URIRef) -> str:
98
98
  ?stepUri a <http://cambridgesemantics.com/ontologies/Graphmarts#Step>;
99
99
  <http://cambridgesemantics.com/ontologies/Graphmarts#transformQuery> ?query
100
100
  }}"""
101
- return json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))[0]['query']
102
-
101
+ result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
102
+ if len(result) == 0:
103
+ raise FileNotFoundError(
104
+ f"Querynot found for step {query_step_uri}")
105
+ return result[0].get("query")
103
106
 
104
107
  def get_queries_from_templated_step(triple_store: dict, query_step_uri: URIRef) -> dict:
105
108
  query = f"""SELECT ?param_query ?query_template WHERE {{
@@ -109,8 +112,11 @@ def get_queries_from_templated_step(triple_store: dict, query_step_uri: URIRef)
109
112
  <http://cambridgesemantics.com/ontologies/Graphmarts#template> ?query_template .
110
113
  }}
111
114
  """
112
- return json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))[0]
113
-
115
+ result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
116
+ if len(result) == 0:
117
+ raise FileNotFoundError(
118
+ f"Templated query not found for {query_step_uri}")
119
+ return result[0]
114
120
 
115
121
  def get_queries_for_layer(triple_store: dict, graphmart_layer_uri: URIRef):
116
122
  query = f"""PREFIX graphmarts: <http://cambridgesemantics.com/ontologies/Graphmarts#>
@@ -129,8 +135,11 @@ SELECT ?query ?param_query ?query_template
129
135
  . }}
130
136
  }}
131
137
  ORDER BY ?index"""
132
- return json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
133
-
138
+ result = json_to_dictlist(query_configuration(anzo_config=triple_store, query=query))
139
+ if len(result) == 0:
140
+ raise FileNotFoundError(
141
+ f"Queries not found for graphmart layer {graphmart_layer_uri}")
142
+ return result
134
143
 
135
144
  def upload_given(triple_store: dict, given: Graph):
136
145
  logging.debug(f"upload_given {triple_store} {given}")
mustrd/spec_component.py CHANGED
@@ -675,7 +675,7 @@ def get_spec_component_from_file(path: Path) -> str:
675
675
  raise ValueError(f"Path {path} is a directory, expected a file")
676
676
 
677
677
  try:
678
- content = path.read_text()
678
+ content = path.read_text(encoding='utf-8')
679
679
  except FileNotFoundError:
680
680
  raise
681
681
  return str(content)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: mustrd
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber.
5
5
  License: MIT
6
6
  Author: John Placek
@@ -34,13 +34,13 @@ Requires-Dist: urllib3 (==1.26.19)
34
34
  Project-URL: Repository, https://github.com/Semantic-partners/mustrd
35
35
  Description-Content-Type: text/markdown
36
36
 
37
- # mustrd
37
+ # MustRD
38
38
 
39
39
  **"MustRD: Validate your SPARQL queries and transformations with precision and confidence, using BDD and Given-When-Then principles."**
40
40
 
41
- [<img src="https://github.com/Semantic-partners/mustrd/raw/python-coverage-comment-action-data/badge.svg?sanitize=true" alt="coverage badge">](https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data)
41
+ [![Coverage Badge](https://github.com/Semantic-partners/mustrd/raw/python-coverage-comment-action-data/badge.svg?sanitize=true)](https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data)
42
42
 
43
- ### Why?
43
+ ## Why?
44
44
 
45
45
  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
46
 
@@ -48,11 +48,11 @@ While RDF and SPARQL offer great flexibility, we noticed a gap in tooling to val
48
48
 
49
49
  With MustRD, you can:
50
50
 
51
- * Define data scenarios and verify that queries produce the expected results.
52
- * Test edge cases to ensure your queries remain reliable.
53
- * Isolate small SPARQL enrichment or transformation steps and confirm you're only inserting what you intend.
51
+ - Define data scenarios and verify that queries produce the expected results.
52
+ - Test edge cases to ensure your queries remain reliable.
53
+ - Isolate small SPARQL enrichment or transformation steps and confirm you're only inserting what you intend.
54
54
 
55
- ### What?
55
+ ## What?
56
56
 
57
57
  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
58
 
@@ -62,23 +62,85 @@ MustRD is designed to be triplestore/SPARQL engine agnostic, leveraging open sta
62
62
 
63
63
  MustRD is not an alternative to SHACL. While SHACL validates data structures, MustRD focuses on validating data transformations and query results.
64
64
 
65
- ### How?
65
+ ## How?
66
66
 
67
67
  You define your specs in Turtle (`.ttl`) or TriG (`.trig`) files using the Given-When-Then approach:
68
68
 
69
- * **Given**: Define the starting dataset.
70
- * **When**: Specify the action (e.g., a SPARQL query).
71
- * **Then**: Outline the expected results.
69
+ - **Given**: Define the starting dataset.
70
+ - **When**: Specify the action (e.g., a SPARQL query).
71
+ - **Then**: Outline the expected results.
72
72
 
73
73
  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
74
 
75
75
  Expectations can also be defined as:
76
76
 
77
- * INSERT queries.
78
- * SELECT queries.
79
- * Higher-order expectation languages, similar to those used in various platforms.
77
+ - INSERT queries.
78
+ - SELECT queries.
79
+ - Higher-order expectation languages, similar to those used in various platforms.
80
80
 
81
- ### When?
81
+ ## Example
82
+
83
+ ### Configuration File
84
+
85
+ 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:
86
+
87
+ ```ttl
88
+ :test_example a :MustrdTest;
89
+ :hasSpecPath "test/specs/";
90
+ :hasDataPath "test/data/";
91
+ :hasPytestPath "example";
92
+ :triplestoreSpecPath "test/triplestore_config/triplestores.ttl";
93
+ :filterOnTripleStore triplestore:example_test .
94
+ ```
95
+
96
+ ### Test Specification
97
+
98
+ 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.
99
+
100
+ ```ttl
101
+ :test_example :given [ a :FileDataset ;
102
+ :file "test/data/given.ttl" ] ;
103
+ :when [ a :TextSparqlSource ;
104
+ :queryText "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" ;
105
+ :queryType :SelectSparql ] ;
106
+ :then [ a :OrderedTableDataset ;
107
+ :hasRow [ :variable "s" ; :boundValue "example:subject" ;
108
+ :variable "p" ; :boundValue "example:predicate" ;
109
+ :variable "o" ; :boundValue "example:object" ] ].
110
+ ```
111
+
112
+ And you will have a `'test/data/given.ttl'` which contains the given ttl.
113
+
114
+ ```ttl
115
+ example:subject example:predicate example:object .
116
+ ```
117
+
118
+ ### Running Tests
119
+
120
+ Run the test using the MustRD Pytest plugin:
121
+
122
+ ```bash
123
+ poetry run pytest --mustrd --config=test/mustrd_configuration.ttl --md=render/github_job_summary.md
124
+ ```
125
+
126
+ This will validate your SPARQL queries against the defined dataset and expected results, ensuring your transformations behave as intended.
127
+
128
+ You can refer to SPARQL inline, in files, or in Anzo Graphmarts, Steps, or Layers. See `GETSTARTED.adoc` for more details.
129
+
130
+ #### Integrating with Visual Studio Code (vscode)
131
+ We have a pytest plugin.
132
+ 1. Choose a python interpreter (probably a venv)
133
+ 2. `pip install mustrd ` in it.
134
+ 3. add to your settings.json
135
+ ```json
136
+ "python.testing.pytestArgs": [
137
+ "--mustrd", "--md=junit/github_job_summary.md", "--config=test/test_config_local.ttl"
138
+ ],
139
+ ```
140
+ 4. VS Code should auto discover your tests and they'll show up in the flask icon 'tab'.
141
+ ![alt text](image.png)
142
+
143
+ ## When?
82
144
 
83
145
  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
146
 
@@ -89,3 +151,4 @@ We invite you to try it, raise issues, or contribute via pull requests. If you n
89
151
  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
152
 
91
153
 
154
+
@@ -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=B5uwN17XBuIJu5IBE7GKZ_SuA8yLDzeKywVz3HzAWYI,7451
16
+ mustrd/mustrdAnzo.py,sha256=Vicc8B-zP3EwO2TF6hh7Cz-JHPNGLzG2M9KrfjzATxE,7882
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=n6xISiYP1WrntcKOhtL0XZhdZigmBBHFfwrB5CEyV70,20577
20
20
  mustrd/namespace.py,sha256=1l8RJDFI7rYkWvmRokaTvSvqrDJEdRNIkq3lmPb0xpI,3854
21
21
  mustrd/run.py,sha256=5xZUgKPMBQ-03cWROAnwtbOs2Nb0Vat6n8Fi6EyfS-k,4257
22
- mustrd/spec_component.py,sha256=515XqP4Wc_TVaCOSswxTJM5i00bnuXvJZyEYa0N9_-o,38627
22
+ mustrd/spec_component.py,sha256=W4EWp-IJCp5CGG4Cy6m3D2-cViPoi0NrJCcSZiSqT2U,38643
23
23
  mustrd/steprunner.py,sha256=JnajkFay-oeSJnBH3OxFVGfz5WhKjxEH1PV4WUoRPRE,10752
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.2.dist-info/LICENSE,sha256=r8nmh5fUct9h2w8_RDl13EIscvmwCLoarPr1kg35MnA,1078
29
- mustrd-0.3.2.dist-info/METADATA,sha256=0ksOxgbiJlegZeLCQjwnSz4dlOw3pBhBVUqzrG8wP5Q,4107
30
- mustrd-0.3.2.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
31
- mustrd-0.3.2.dist-info/entry_points.txt,sha256=v7V7sN0_L1aB4Ug_9io5axlQSeJ1C0tNrQWwdXdV58s,50
32
- mustrd-0.3.2.dist-info/RECORD,,
28
+ mustrd-0.3.3.dist-info/LICENSE,sha256=r8nmh5fUct9h2w8_RDl13EIscvmwCLoarPr1kg35MnA,1078
29
+ mustrd-0.3.3.dist-info/METADATA,sha256=aS5-0doN-yd9b-SPO9Qqm8DpxBmjjHtHxDLxbpU4w_Y,6423
30
+ mustrd-0.3.3.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
31
+ mustrd-0.3.3.dist-info/entry_points.txt,sha256=v7V7sN0_L1aB4Ug_9io5axlQSeJ1C0tNrQWwdXdV58s,50
32
+ mustrd-0.3.3.dist-info/RECORD,,
File without changes