mustrd 0.1.8__tar.gz → 0.2.0a1__tar.gz
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-0.1.8 → mustrd-0.2.0a1}/LICENSE +21 -21
- mustrd-0.2.0a1/PKG-INFO +24 -0
- mustrd-0.2.0a1/pyproject.toml +44 -0
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/README.adoc +201 -201
- mustrd-0.2.0a1/src/mustrd/execute_update_spec.py +18 -0
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/logger_setup.py +48 -48
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/mustrd.py +842 -788
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/mustrdAnzo.py +208 -236
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/mustrdGraphDb.py +128 -125
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/mustrdRdfLib.py +56 -56
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/namespace.py +104 -125
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/run.py +95 -106
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/spec_component.py +617 -682
- mustrd-0.2.0a1/src/mustrd/triple_store_dispatch.py +115 -0
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/utils.py +30 -38
- mustrd-0.1.8/PKG-INFO +0 -97
- mustrd-0.1.8/README.adoc +0 -58
- mustrd-0.1.8/mustrd/TestResult.py +0 -136
- mustrd-0.1.8/mustrd/model/catalog-v001.xml +0 -5
- mustrd-0.1.8/mustrd/model/mustrdShapes.ttl +0 -253
- mustrd-0.1.8/mustrd/model/mustrdTestOntology.ttl +0 -51
- mustrd-0.1.8/mustrd/model/mustrdTestShapes.ttl +0 -24
- mustrd-0.1.8/mustrd/model/ontology.ttl +0 -494
- mustrd-0.1.8/mustrd/model/test-resources/resources.ttl +0 -60
- mustrd-0.1.8/mustrd/model/triplestoreOntology.ttl +0 -174
- mustrd-0.1.8/mustrd/model/triplestoreshapes.ttl +0 -42
- mustrd-0.1.8/mustrd/mustrdTestPlugin.py +0 -328
- mustrd-0.1.8/mustrd/steprunner.py +0 -166
- mustrd-0.1.8/mustrd/templates/md_ResultList_leaf_template.jinja +0 -19
- mustrd-0.1.8/mustrd/templates/md_ResultList_template.jinja +0 -9
- mustrd-0.1.8/mustrd/templates/md_stats_template.jinja +0 -3
- mustrd-0.1.8/mustrd/test/test_mustrd.py +0 -5
- mustrd-0.1.8/pyproject.toml +0 -54
- {mustrd-0.1.8 → mustrd-0.2.0a1/src}/mustrd/__init__.py +0 -0
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2023 Semantic Partners Ltd
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Semantic Partners Ltd
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
mustrd-0.2.0a1/PKG-INFO
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Metadata-Version: 2.3
|
2
|
+
Name: mustrd
|
3
|
+
Version: 0.2.0a1
|
4
|
+
Summary: A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber.
|
5
|
+
Author: John Placek
|
6
|
+
Author-email: john.placek@semanticpartners.com
|
7
|
+
Requires-Python: >=3.11,<4.0.0
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Programming Language :: Python :: 3.11
|
10
|
+
Classifier: Programming Language :: Python :: 3.12
|
11
|
+
Classifier: Programming Language :: Python :: 3.13
|
12
|
+
Requires-Dist: beautifulsoup4 (>=4.11.1)
|
13
|
+
Requires-Dist: colorlog (>=6.7.0)
|
14
|
+
Requires-Dist: multimethods-py (>=0.5.3)
|
15
|
+
Requires-Dist: openpyxl (>=3.1.2)
|
16
|
+
Requires-Dist: pandas (>=1.5.2)
|
17
|
+
Requires-Dist: pyanzo (>=3.3.7)
|
18
|
+
Requires-Dist: pyshacl (>=0.23.0)
|
19
|
+
Requires-Dist: pytest (>=7.2.0)
|
20
|
+
Requires-Dist: rdflib (>=6.2.0)
|
21
|
+
Requires-Dist: requests (>=2.28.2)
|
22
|
+
Requires-Dist: tabulate (>=0.9.0)
|
23
|
+
Requires-Dist: toml (>=0.10.2)
|
24
|
+
Requires-Dist: tomli (>=2.0.1)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
[project]
|
2
|
+
name = "mustrd"
|
3
|
+
version = "0.2.0-alpha.1"
|
4
|
+
description = "A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber."
|
5
|
+
requires-python = ">=3.11,<4.0.0"
|
6
|
+
authors = [
|
7
|
+
{name= "John Placek", email = "john.placek@semanticpartners.com"},
|
8
|
+
{name= "Juliane Piñeiro-Winkler", email = "juliane.pineiro-winkler@semanticpartners.com>"},
|
9
|
+
{name= "Aymeric Picou", email = "aymeric.picou@semanticpartners.com>"},
|
10
|
+
{name= "James Lawrence", email = "james.lawrence@semanticpartners.com>"},
|
11
|
+
{name= "Lance Paine", email = "lance.paine@semanticpartners.com>"},
|
12
|
+
{name= "Andrew Large", email = "andy.large@semanticpartners.com>"}]
|
13
|
+
|
14
|
+
dependencies=[
|
15
|
+
"rdflib>=6.2.0",
|
16
|
+
"pytest>=7.2.0",
|
17
|
+
"pandas>=1.5.2",
|
18
|
+
"multimethods-py>=0.5.3",
|
19
|
+
"colorlog>=6.7.0",
|
20
|
+
"requests>=2.28.2",
|
21
|
+
"pyanzo>=3.3.7",
|
22
|
+
"tabulate>=0.9.0",
|
23
|
+
"beautifulsoup4>=4.11.1",
|
24
|
+
"openpyxl>=3.1.2",
|
25
|
+
"toml>=0.10.2",
|
26
|
+
"pyshacl>=0.23.0",
|
27
|
+
"tomli>=2.0.1",
|
28
|
+
]
|
29
|
+
|
30
|
+
|
31
|
+
[tool.poetry.group.dev.dependencies]
|
32
|
+
autopep8 = "^2.0.2"
|
33
|
+
|
34
|
+
[build-system]
|
35
|
+
requires = ["poetry-core>=1.0.0"]
|
36
|
+
build-backend = "poetry.core.masonry.api"
|
37
|
+
|
38
|
+
[tool.poetry]
|
39
|
+
packages = [
|
40
|
+
{ include = "mustrd", from = "src" }
|
41
|
+
]
|
42
|
+
|
43
|
+
[tool.poetry.dependencies]
|
44
|
+
python = ">=3.11,<4.0.0"
|
@@ -1,201 +1,201 @@
|
|
1
|
-
= Developer helper
|
2
|
-
// tag::body[]
|
3
|
-
|
4
|
-
== Try it out
|
5
|
-
|
6
|
-
Ensure you have python3 installed, before you begin.
|
7
|
-
To install the necessary dependencies, run the following command from the project root.
|
8
|
-
|
9
|
-
`pip3 install -r requirements.txt`
|
10
|
-
|
11
|
-
Run the following command to execute the accompanying tests specifications.
|
12
|
-
|
13
|
-
`python3 src/run.py -v -p "test/test-specs" -g "test/data" -w "test/data" -t "test/data"`
|
14
|
-
|
15
|
-
You will see some warnings. Do not worry, some tests specifications are invalid and intentionally skipped.
|
16
|
-
|
17
|
-
For a brief explanation of the meaning of these options use the help option.
|
18
|
-
|
19
|
-
`python3 src/run.py --help`
|
20
|
-
|
21
|
-
== Run the tests
|
22
|
-
|
23
|
-
Run `pytest` from the project root.
|
24
|
-
|
25
|
-
== Creating your own Test Specifications
|
26
|
-
|
27
|
-
If you have got this far then you are probably ready to create your own specifications to test your application SPARQL queries. These will be executed against the default RDFLib triplestore unless you configure one or more alternatives. The instructions for this are included in <<Configuring external triplestores>> below.
|
28
|
-
|
29
|
-
=== Givens
|
30
|
-
These are used to specify the dataset against which the SPARQL statement will be run.
|
31
|
-
They can be generated from external sources such as an existing graph, or a file or folder containing serialised RDF. It is also possible to specify the dataset as reified RDF directly in the test step. Currently tabular data sources such as csv files or TableDatasets are not supported.
|
32
|
-
Multiple given statements can be supplied and data is combined into a single dataset for the test.
|
33
|
-
|
34
|
-
* *InheritedDataset* - This is where no data is specified but the existing data in the target graph is retained rather than being replaced with a defined set. This can be used to chain tests together or to perform checks on application data.
|
35
|
-
----
|
36
|
-
must:given [ a must:InheritedDataset ] ;
|
37
|
-
----
|
38
|
-
* *FileDataset* - The dataset is a local file containing serialised RDF. The formats supported are the same as those for the RDFLib Graph().parse function i.e. Turtle (.ttl), NTriples (.nt), N3 (.n3), RDF/XML (.xml) and TriX. The data is used to replace any existing content in the target graph for the test.
|
39
|
-
----
|
40
|
-
must:given [ a must:FileDataset ;
|
41
|
-
must:file "test/data/given.ttl" . ] ;
|
42
|
-
----
|
43
|
-
* *FolderDataset* - Very similar to the file dataset except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -g option on the command line.
|
44
|
-
----
|
45
|
-
must:given [ a must:FolderDataset ;
|
46
|
-
must:fileName "given.ttl" ] ;
|
47
|
-
----
|
48
|
-
* *StatementsDataset* - The dataset is defined within the test in the form of reified RDF statements. e.g.
|
49
|
-
----
|
50
|
-
must:given [ a must:StatementsDataset ;
|
51
|
-
must:hasStatement [ a rdf:Statement ;
|
52
|
-
rdf:subject test-data:sub ;
|
53
|
-
rdf:predicate test-data:pred ;
|
54
|
-
rdf:object test-data:obj ; ] ; ] ;
|
55
|
-
----
|
56
|
-
* *AnzoGraphmartDataset* - The dataset is contained in an Anzo graphmart and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
57
|
-
----
|
58
|
-
must:given [ a must:AnzoGraphmartDataset ;
|
59
|
-
must:graphmart "http://cambridgesemantics.com/Graphmart/43445aeadf674e09818c81cf7049e46a";
|
60
|
-
must:layer "http://cambridgesemantics.com/Layer/33b97531d7e148748b75e4e3c6bbf164";
|
61
|
-
] .
|
62
|
-
----
|
63
|
-
=== Whens
|
64
|
-
These are the actual SPARQL queries that you wish to test. Queries can be supplied as a string directly in the test or as a file containing the query. Only single When statements are currently supported.
|
65
|
-
Mustrd does not derive the query type from the actual query, so it is necessary to provide this in the specification. Supported query types are SelectSparql, ConstructSparql and UpdateSparql.
|
66
|
-
|
67
|
-
* *TextSparqlSource* - The SPARQL query is included in the test as a (multiline) string value for the property queryText.
|
68
|
-
e.g.
|
69
|
-
----
|
70
|
-
must:when [ a must:TextSparqlSource ;
|
71
|
-
must:queryText "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" ;
|
72
|
-
must:queryType must:SelectSparql ] ;
|
73
|
-
----
|
74
|
-
|
75
|
-
* *FileSparqlSource* - The SPARQL query is contained in a local file.
|
76
|
-
e.g.
|
77
|
-
----
|
78
|
-
must:when [ a must:FileSparqlSource ;
|
79
|
-
must:file "test/data/construct.rq" ;
|
80
|
-
must:queryType must:ConstructSparql ; ] ;
|
81
|
-
----
|
82
|
-
* *FolderSparqlSource* - Similar to the file SPARQL source except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -w option on the command line.
|
83
|
-
----
|
84
|
-
must:when [ a must:FolderSparqlSource ;
|
85
|
-
must:fileName "construct.rq" ;
|
86
|
-
must:queryType must:ConstructSparql ; ] ;
|
87
|
-
----
|
88
|
-
* *AnzoQueryBuilderDataset* - The query is saved in the Query Builder of an Anzo instance and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
89
|
-
----
|
90
|
-
must:when [ a must:AnzoQueryBuilderDataset ;
|
91
|
-
must:queryFolder "Mustrd";
|
92
|
-
must:queryName "mustrd-construct" ;
|
93
|
-
must:queryType must:ConstructSparql
|
94
|
-
];
|
95
|
-
----
|
96
|
-
=== Thens
|
97
|
-
Then clauses are used to specify the expected result dataset for the test. These datasets can be specified in the same way as <<Givens>> except that an extended set of dataset types is supported. For the tabular results of SELECT queries TabularDatasets are required and again can be in file format such as CSV, or an inline table within the specification.
|
98
|
-
* *FileDataset* - The dataset is a local file containing serialised RDF or tabular data. The formats supported are the same as those for the RDFLib Graph().parse function i.e. Turtle (.ttl), NTriples (.nt), N3 (.n3), RDF/XML (.xml) and TriX, as well as tabular formats (.csv, .xls, .xlsx).
|
99
|
-
----
|
100
|
-
must:then [ a must:FileDataset ;
|
101
|
-
must:file "test/data/thenSuccess.xlsx" ] .
|
102
|
-
----
|
103
|
-
----
|
104
|
-
must:then [ a must:FileDataset ;
|
105
|
-
must:file "test/data/thenSuccess.nt" ] .
|
106
|
-
----
|
107
|
-
* *FolderDataset* - Very similar to the file dataset except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -t option on the command line.
|
108
|
-
----
|
109
|
-
must:then [ a must:FolderDataset ;
|
110
|
-
must:fileName "then.ttl" ] ;
|
111
|
-
----
|
112
|
-
* *StatementsDataset* - The dataset is defined within the test in the form of reified RDF statements e.g.
|
113
|
-
----
|
114
|
-
must:then [ a must:StatementsDataset ;
|
115
|
-
must:hasStatement [ a rdf:Statement ;
|
116
|
-
rdf:subject test-data:sub ;
|
117
|
-
rdf:predicate test-data:pred ;
|
118
|
-
rdf:object test-data:obj ; ] ; ] ;
|
119
|
-
----
|
120
|
-
* *TableDataset* - The contents of the table defined in RDF syntax within the specification.
|
121
|
-
E.g. a table dataset consisting of a single row and three columns.
|
122
|
-
----
|
123
|
-
must:then [ a must:TableDataset ;
|
124
|
-
must:hasRow [ must:hasBinding[
|
125
|
-
must:variable "s" ;
|
126
|
-
must:boundValue test-data:sub ; ],
|
127
|
-
[ must:variable "p" ;
|
128
|
-
must:boundValue test-data:pred ; ],
|
129
|
-
[ must:variable "o" ;
|
130
|
-
must:boundValue test-data:obj ; ] ;
|
131
|
-
] ; ] .
|
132
|
-
----
|
133
|
-
* *OrderedTableDataset* - This is an extension of the TableDataset which allows the row order of the dataset to be specified using the SHACL order property to support the ORDER BY clause in SPARQL SELECT queries
|
134
|
-
E.g. A table dataset consisting of two ordered rows and three columns.
|
135
|
-
----
|
136
|
-
must:then [ a must:OrderedTableDataset ;
|
137
|
-
must:hasRow [ sh:order 1 ;
|
138
|
-
must:hasBinding[ must:variable "s" ;
|
139
|
-
must:boundValue test-data:sub1 ; ],
|
140
|
-
[ must:variable "p" ;
|
141
|
-
must:boundValue test-data:pred1 ; ],
|
142
|
-
[ must:variable "o" ;
|
143
|
-
must:boundValue test-data:obj1 ; ] ; ] ,
|
144
|
-
[ sh:order 2 ;
|
145
|
-
must:hasBinding[ must:variable "s" ;
|
146
|
-
must:boundValue test-data:sub2 ; ],
|
147
|
-
[ must:variable "p" ;
|
148
|
-
must:boundValue test-data:pred2 ; ],
|
149
|
-
[ must:variable "o" ;
|
150
|
-
must:boundValue test-data:obj2 ; ] ; ] ;
|
151
|
-
] .
|
152
|
-
----
|
153
|
-
* *EmptyTable* - This is used to indicate that we are expecting an empty result from a SPARQL SELECT query.
|
154
|
-
----
|
155
|
-
must:then [ a must:EmptyTable ] .
|
156
|
-
----
|
157
|
-
* *EmptyGraph* - Similar to EmptyTable but used to indicate that we are expecting an empty graph as a result from a SPARQL query.
|
158
|
-
----
|
159
|
-
must:then [ a must:EmptyGraph ] .
|
160
|
-
----
|
161
|
-
* *AnzoGraphmartDataset* - The dataset is contained in an Anzo graphmart and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
162
|
-
----
|
163
|
-
must:then [ a must:AnzoGraphmartDataset ;
|
164
|
-
must:graphmart "http://cambridgesemantics.com/Graphmart/43445aeadf674e09818c81cf7049e46a";
|
165
|
-
must:layer "http://cambridgesemantics.com/Layer/33b97531d7e148748b75e4e3c6bbf164";
|
166
|
-
] .
|
167
|
-
----
|
168
|
-
== Configuring external triplestores
|
169
|
-
The configuration file for external triplestores can be located outside of the project root as it is specified as an argument to the mustard module or as the -c option on the commandline when running run.py.
|
170
|
-
|
171
|
-
It is anticipated that the external triplestore is running as mustrd is not configured to start them.
|
172
|
-
|
173
|
-
Currently, the supported external triplestores are GraphDB and Anzo.
|
174
|
-
|
175
|
-
The configuration file should be serialised RDF. An example in Turtle format is included below for GraphDB. For Anzo the *must:repository* value is replaced with a *must:gqeURI*.
|
176
|
-
----
|
177
|
-
@prefix must: <https://mustrd.com/model/> .
|
178
|
-
must:GraphDbConfig1 a must:GraphDbConfig ;
|
179
|
-
must:url "http://localhost";
|
180
|
-
must:port "7200";
|
181
|
-
must:
|
182
|
-
must:
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
----
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
----
|
192
|
-
|
193
|
-
== Additional Notes for Developers
|
194
|
-
Mustrd remains very much under development. It is anticipated that additional functionality and triplestore support will be added over time. The project uses https://python-poetry.org/docs/[Poetry] to manage dependencies so it will be necessary to have this installed to contribute towards the project. The link contains instructions on how to install and use this.
|
195
|
-
As the project is actually built from the requirements.txt file at the project root, it is necessary to export dependencies from poetry to this file before committing and pushing changes to the repository, using the following command.
|
196
|
-
|
197
|
-
`poetry export -f requirements.txt --without-hashes > requirements.txt`
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
// end::body[]
|
1
|
+
= Developer helper
|
2
|
+
// tag::body[]
|
3
|
+
|
4
|
+
== Try it out
|
5
|
+
|
6
|
+
Ensure you have python3 installed, before you begin.
|
7
|
+
To install the necessary dependencies, run the following command from the project root.
|
8
|
+
|
9
|
+
`pip3 install -r requirements.txt`
|
10
|
+
|
11
|
+
Run the following command to execute the accompanying tests specifications.
|
12
|
+
|
13
|
+
`python3 src/run.py -v -p "test/test-specs" -g "test/data" -w "test/data" -t "test/data"`
|
14
|
+
|
15
|
+
You will see some warnings. Do not worry, some tests specifications are invalid and intentionally skipped.
|
16
|
+
|
17
|
+
For a brief explanation of the meaning of these options use the help option.
|
18
|
+
|
19
|
+
`python3 src/run.py --help`
|
20
|
+
|
21
|
+
== Run the tests
|
22
|
+
|
23
|
+
Run `pytest` from the project root.
|
24
|
+
|
25
|
+
== Creating your own Test Specifications
|
26
|
+
|
27
|
+
If you have got this far then you are probably ready to create your own specifications to test your application SPARQL queries. These will be executed against the default RDFLib triplestore unless you configure one or more alternatives. The instructions for this are included in <<Configuring external triplestores>> below.
|
28
|
+
|
29
|
+
=== Givens
|
30
|
+
These are used to specify the dataset against which the SPARQL statement will be run.
|
31
|
+
They can be generated from external sources such as an existing graph, or a file or folder containing serialised RDF. It is also possible to specify the dataset as reified RDF directly in the test step. Currently tabular data sources such as csv files or TableDatasets are not supported.
|
32
|
+
Multiple given statements can be supplied and data is combined into a single dataset for the test.
|
33
|
+
|
34
|
+
* *InheritedDataset* - This is where no data is specified but the existing data in the target graph is retained rather than being replaced with a defined set. This can be used to chain tests together or to perform checks on application data.
|
35
|
+
----
|
36
|
+
must:given [ a must:InheritedDataset ] ;
|
37
|
+
----
|
38
|
+
* *FileDataset* - The dataset is a local file containing serialised RDF. The formats supported are the same as those for the RDFLib Graph().parse function i.e. Turtle (.ttl), NTriples (.nt), N3 (.n3), RDF/XML (.xml) and TriX. The data is used to replace any existing content in the target graph for the test.
|
39
|
+
----
|
40
|
+
must:given [ a must:FileDataset ;
|
41
|
+
must:file "test/data/given.ttl" . ] ;
|
42
|
+
----
|
43
|
+
* *FolderDataset* - Very similar to the file dataset except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -g option on the command line.
|
44
|
+
----
|
45
|
+
must:given [ a must:FolderDataset ;
|
46
|
+
must:fileName "given.ttl" ] ;
|
47
|
+
----
|
48
|
+
* *StatementsDataset* - The dataset is defined within the test in the form of reified RDF statements. e.g.
|
49
|
+
----
|
50
|
+
must:given [ a must:StatementsDataset ;
|
51
|
+
must:hasStatement [ a rdf:Statement ;
|
52
|
+
rdf:subject test-data:sub ;
|
53
|
+
rdf:predicate test-data:pred ;
|
54
|
+
rdf:object test-data:obj ; ] ; ] ;
|
55
|
+
----
|
56
|
+
* *AnzoGraphmartDataset* - The dataset is contained in an Anzo graphmart and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
57
|
+
----
|
58
|
+
must:given [ a must:AnzoGraphmartDataset ;
|
59
|
+
must:graphmart "http://cambridgesemantics.com/Graphmart/43445aeadf674e09818c81cf7049e46a";
|
60
|
+
must:layer "http://cambridgesemantics.com/Layer/33b97531d7e148748b75e4e3c6bbf164";
|
61
|
+
] .
|
62
|
+
----
|
63
|
+
=== Whens
|
64
|
+
These are the actual SPARQL queries that you wish to test. Queries can be supplied as a string directly in the test or as a file containing the query. Only single When statements are currently supported.
|
65
|
+
Mustrd does not derive the query type from the actual query, so it is necessary to provide this in the specification. Supported query types are SelectSparql, ConstructSparql and UpdateSparql.
|
66
|
+
|
67
|
+
* *TextSparqlSource* - The SPARQL query is included in the test as a (multiline) string value for the property queryText.
|
68
|
+
e.g.
|
69
|
+
----
|
70
|
+
must:when [ a must:TextSparqlSource ;
|
71
|
+
must:queryText "SELECT ?s ?p ?o WHERE { ?s ?p ?o }" ;
|
72
|
+
must:queryType must:SelectSparql ] ;
|
73
|
+
----
|
74
|
+
|
75
|
+
* *FileSparqlSource* - The SPARQL query is contained in a local file.
|
76
|
+
e.g.
|
77
|
+
----
|
78
|
+
must:when [ a must:FileSparqlSource ;
|
79
|
+
must:file "test/data/construct.rq" ;
|
80
|
+
must:queryType must:ConstructSparql ; ] ;
|
81
|
+
----
|
82
|
+
* *FolderSparqlSource* - Similar to the file SPARQL source except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -w option on the command line.
|
83
|
+
----
|
84
|
+
must:when [ a must:FolderSparqlSource ;
|
85
|
+
must:fileName "construct.rq" ;
|
86
|
+
must:queryType must:ConstructSparql ; ] ;
|
87
|
+
----
|
88
|
+
* *AnzoQueryBuilderDataset* - The query is saved in the Query Builder of an Anzo instance and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
89
|
+
----
|
90
|
+
must:when [ a must:AnzoQueryBuilderDataset ;
|
91
|
+
must:queryFolder "Mustrd";
|
92
|
+
must:queryName "mustrd-construct" ;
|
93
|
+
must:queryType must:ConstructSparql
|
94
|
+
];
|
95
|
+
----
|
96
|
+
=== Thens
|
97
|
+
Then clauses are used to specify the expected result dataset for the test. These datasets can be specified in the same way as <<Givens>> except that an extended set of dataset types is supported. For the tabular results of SELECT queries TabularDatasets are required and again can be in file format such as CSV, or an inline table within the specification.
|
98
|
+
* *FileDataset* - The dataset is a local file containing serialised RDF or tabular data. The formats supported are the same as those for the RDFLib Graph().parse function i.e. Turtle (.ttl), NTriples (.nt), N3 (.n3), RDF/XML (.xml) and TriX, as well as tabular formats (.csv, .xls, .xlsx).
|
99
|
+
----
|
100
|
+
must:then [ a must:FileDataset ;
|
101
|
+
must:file "test/data/thenSuccess.xlsx" ] .
|
102
|
+
----
|
103
|
+
----
|
104
|
+
must:then [ a must:FileDataset ;
|
105
|
+
must:file "test/data/thenSuccess.nt" ] .
|
106
|
+
----
|
107
|
+
* *FolderDataset* - Very similar to the file dataset except that the location of the file is passed to the test specification as an argument from the caller. i.e. the -t option on the command line.
|
108
|
+
----
|
109
|
+
must:then [ a must:FolderDataset ;
|
110
|
+
must:fileName "then.ttl" ] ;
|
111
|
+
----
|
112
|
+
* *StatementsDataset* - The dataset is defined within the test in the form of reified RDF statements e.g.
|
113
|
+
----
|
114
|
+
must:then [ a must:StatementsDataset ;
|
115
|
+
must:hasStatement [ a rdf:Statement ;
|
116
|
+
rdf:subject test-data:sub ;
|
117
|
+
rdf:predicate test-data:pred ;
|
118
|
+
rdf:object test-data:obj ; ] ; ] ;
|
119
|
+
----
|
120
|
+
* *TableDataset* - The contents of the table defined in RDF syntax within the specification.
|
121
|
+
E.g. a table dataset consisting of a single row and three columns.
|
122
|
+
----
|
123
|
+
must:then [ a must:TableDataset ;
|
124
|
+
must:hasRow [ must:hasBinding[
|
125
|
+
must:variable "s" ;
|
126
|
+
must:boundValue test-data:sub ; ],
|
127
|
+
[ must:variable "p" ;
|
128
|
+
must:boundValue test-data:pred ; ],
|
129
|
+
[ must:variable "o" ;
|
130
|
+
must:boundValue test-data:obj ; ] ;
|
131
|
+
] ; ] .
|
132
|
+
----
|
133
|
+
* *OrderedTableDataset* - This is an extension of the TableDataset which allows the row order of the dataset to be specified using the SHACL order property to support the ORDER BY clause in SPARQL SELECT queries
|
134
|
+
E.g. A table dataset consisting of two ordered rows and three columns.
|
135
|
+
----
|
136
|
+
must:then [ a must:OrderedTableDataset ;
|
137
|
+
must:hasRow [ sh:order 1 ;
|
138
|
+
must:hasBinding[ must:variable "s" ;
|
139
|
+
must:boundValue test-data:sub1 ; ],
|
140
|
+
[ must:variable "p" ;
|
141
|
+
must:boundValue test-data:pred1 ; ],
|
142
|
+
[ must:variable "o" ;
|
143
|
+
must:boundValue test-data:obj1 ; ] ; ] ,
|
144
|
+
[ sh:order 2 ;
|
145
|
+
must:hasBinding[ must:variable "s" ;
|
146
|
+
must:boundValue test-data:sub2 ; ],
|
147
|
+
[ must:variable "p" ;
|
148
|
+
must:boundValue test-data:pred2 ; ],
|
149
|
+
[ must:variable "o" ;
|
150
|
+
must:boundValue test-data:obj2 ; ] ; ] ;
|
151
|
+
] .
|
152
|
+
----
|
153
|
+
* *EmptyTable* - This is used to indicate that we are expecting an empty result from a SPARQL SELECT query.
|
154
|
+
----
|
155
|
+
must:then [ a must:EmptyTable ] .
|
156
|
+
----
|
157
|
+
* *EmptyGraph* - Similar to EmptyTable but used to indicate that we are expecting an empty graph as a result from a SPARQL query.
|
158
|
+
----
|
159
|
+
must:then [ a must:EmptyGraph ] .
|
160
|
+
----
|
161
|
+
* *AnzoGraphmartDataset* - The dataset is contained in an Anzo graphmart and needs to be retrieved from there. The Anzo instance containing the dataset needs to be indicated in the configuration file as documented in <<Configuring external triplestores>>.
|
162
|
+
----
|
163
|
+
must:then [ a must:AnzoGraphmartDataset ;
|
164
|
+
must:graphmart "http://cambridgesemantics.com/Graphmart/43445aeadf674e09818c81cf7049e46a";
|
165
|
+
must:layer "http://cambridgesemantics.com/Layer/33b97531d7e148748b75e4e3c6bbf164";
|
166
|
+
] .
|
167
|
+
----
|
168
|
+
== Configuring external triplestores
|
169
|
+
The configuration file for external triplestores can be located outside of the project root as it is specified as an argument to the mustard module or as the -c option on the commandline when running run.py.
|
170
|
+
|
171
|
+
It is anticipated that the external triplestore is running as mustrd is not configured to start them.
|
172
|
+
|
173
|
+
Currently, the supported external triplestores are GraphDB and Anzo.
|
174
|
+
|
175
|
+
The configuration file should be serialised RDF. An example in Turtle format is included below for GraphDB. For Anzo the *must:repository* value is replaced with a *must:gqeURI*.
|
176
|
+
----
|
177
|
+
@prefix must: <https://mustrd.com/model/> .
|
178
|
+
must:GraphDbConfig1 a must:GraphDbConfig ;
|
179
|
+
must:url "http://localhost";
|
180
|
+
must:port "7200";
|
181
|
+
must:username "test/triplestore_config/tripleStoreCredentials.toml" ;
|
182
|
+
must:password "test/triplestore_config/tripleStoreCredentials.toml" ;
|
183
|
+
must:inputGraph "http://localhost:7200/test-graph" ;
|
184
|
+
must:repository "mustrd" .
|
185
|
+
----
|
186
|
+
The triplestore credentials are held in a separate TOML file so that configurations can be shared without sharing credentials.
|
187
|
+
----
|
188
|
+
["https://mustrd.com/model/GraphDbConfig1"]
|
189
|
+
"username"="<username>"
|
190
|
+
"password"="<password>"
|
191
|
+
----
|
192
|
+
|
193
|
+
== Additional Notes for Developers
|
194
|
+
Mustrd remains very much under development. It is anticipated that additional functionality and triplestore support will be added over time. The project uses https://python-poetry.org/docs/[Poetry] to manage dependencies so it will be necessary to have this installed to contribute towards the project. The link contains instructions on how to install and use this.
|
195
|
+
As the project is actually built from the requirements.txt file at the project root, it is necessary to export dependencies from poetry to this file before committing and pushing changes to the repository, using the following command.
|
196
|
+
|
197
|
+
`poetry export -f requirements.txt --without-hashes > requirements.txt`
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
// end::body[]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
from multimethods import MultiMethod
|
2
|
+
import logging
|
3
|
+
from rdflib import Graph, URIRef
|
4
|
+
from namespace import MUST
|
5
|
+
|
6
|
+
|
7
|
+
def dispatch_update(triple_store: dict, given: Graph, when: str, bindings: dict) -> URIRef:
|
8
|
+
to = triple_store["type"]
|
9
|
+
logging.info(f"dispatch_update to triple store {to}")
|
10
|
+
return to
|
11
|
+
|
12
|
+
|
13
|
+
execute_update_spec = MultiMethod('execute_update_spec', dispatch_update)
|
14
|
+
|
15
|
+
|
16
|
+
@execute_update_spec.method(MUST.GraphDb)
|
17
|
+
def execute_update_graphdb(triple_store: dict, given: Graph, when: str, bindings: dict = None) -> Graph:
|
18
|
+
return execute_graphdb_update(triple_store, given, when, bindings)
|
@@ -1,48 +1,48 @@
|
|
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 logging
|
26
|
-
import sys
|
27
|
-
from colorlog import ColoredFormatter
|
28
|
-
|
29
|
-
|
30
|
-
LOG_LEVEL = logging.INFO
|
31
|
-
LOG_FORMAT = '%(log_color)s%(levelname)s:%(name)s:%(white)s%(message)s'
|
32
|
-
|
33
|
-
|
34
|
-
def setup_logger(name: str) -> logging.Logger:
|
35
|
-
log = logging.getLogger(name)
|
36
|
-
log.setLevel(LOG_LEVEL)
|
37
|
-
|
38
|
-
ch = logging.StreamHandler(sys.stdout)
|
39
|
-
ch.setLevel(LOG_LEVEL)
|
40
|
-
ch.setFormatter(ColoredFormatter(LOG_FORMAT))
|
41
|
-
log.addHandler(ch)
|
42
|
-
|
43
|
-
return log
|
44
|
-
|
45
|
-
|
46
|
-
def flush():
|
47
|
-
logging.shutdown()
|
48
|
-
sys.stdout.flush()
|
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 logging
|
26
|
+
import sys
|
27
|
+
from colorlog import ColoredFormatter
|
28
|
+
|
29
|
+
|
30
|
+
LOG_LEVEL = logging.INFO
|
31
|
+
LOG_FORMAT = '%(log_color)s%(levelname)s:%(name)s:%(white)s%(message)s'
|
32
|
+
|
33
|
+
|
34
|
+
def setup_logger(name: str) -> logging.Logger:
|
35
|
+
log = logging.getLogger(name)
|
36
|
+
log.setLevel(LOG_LEVEL)
|
37
|
+
|
38
|
+
ch = logging.StreamHandler(sys.stdout)
|
39
|
+
ch.setLevel(LOG_LEVEL)
|
40
|
+
ch.setFormatter(ColoredFormatter(LOG_FORMAT))
|
41
|
+
log.addHandler(ch)
|
42
|
+
|
43
|
+
return log
|
44
|
+
|
45
|
+
|
46
|
+
def flush():
|
47
|
+
logging.shutdown()
|
48
|
+
sys.stdout.flush()
|