mustrd 0.1.0__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-0.1.0.dist-info/LICENSE +21 -0
- mustrd-0.1.0.dist-info/METADATA +93 -0
- mustrd-0.1.0.dist-info/RECORD +23 -0
- mustrd-0.1.0.dist-info/WHEEL +4 -0
- mustrd-0.1.0.dist-info/entry_points.txt +3 -0
- src/README.adoc +201 -0
- src/TestResult.py +110 -0
- src/__init__.py +0 -0
- src/logger_setup.py +48 -0
- src/mustrd.py +776 -0
- src/mustrdAnzo.py +236 -0
- src/mustrdGraphDb.py +125 -0
- src/mustrdRdfLib.py +56 -0
- src/mustrdTestPlugin.py +175 -0
- src/namespace.py +118 -0
- src/plugin.py +56 -0
- src/run.py +106 -0
- src/spec_component.py +683 -0
- src/steprunner.py +166 -0
- src/templates/md_ResultList_leaf_template.jinja +19 -0
- src/templates/md_ResultList_template.jinja +9 -0
- src/templates/md_stats_template.jinja +3 -0
- src/utils.py +38 -0
src/namespace.py
ADDED
@@ -0,0 +1,118 @@
|
|
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
|
+
from rdflib import URIRef
|
26
|
+
from rdflib.namespace import DefinedNamespace, Namespace
|
27
|
+
|
28
|
+
|
29
|
+
class MUST(DefinedNamespace):
|
30
|
+
_NS = Namespace("https://mustrd.com/model/")
|
31
|
+
|
32
|
+
# test configuration
|
33
|
+
TestConfig: URIRef
|
34
|
+
hasTestFunction: URIRef
|
35
|
+
hasSpecPath: URIRef
|
36
|
+
hasDataPath: URIRef
|
37
|
+
triplestoreSpecPath: URIRef
|
38
|
+
filterOnTripleStore: URIRef
|
39
|
+
|
40
|
+
# Specification classes
|
41
|
+
TestSpec: URIRef
|
42
|
+
SelectSparql: URIRef
|
43
|
+
ConstructSparql: URIRef
|
44
|
+
UpdateSparql: URIRef
|
45
|
+
AnzoQueryDrivenUpdateSparql: URIRef
|
46
|
+
AskSparql: URIRef
|
47
|
+
DescribeSparql: URIRef
|
48
|
+
|
49
|
+
# Specification properties
|
50
|
+
given: URIRef
|
51
|
+
when: URIRef
|
52
|
+
then: URIRef
|
53
|
+
inputGraph: URIRef
|
54
|
+
outputGraph: URIRef # anzo specials?
|
55
|
+
dataSource: URIRef
|
56
|
+
file: URIRef
|
57
|
+
fileName: URIRef
|
58
|
+
queryFolder: URIRef
|
59
|
+
queryName: URIRef
|
60
|
+
dataSourceUrl: URIRef
|
61
|
+
queryText: URIRef
|
62
|
+
queryType: URIRef
|
63
|
+
hasStatement: URIRef
|
64
|
+
hasRow: URIRef
|
65
|
+
hasBinding: URIRef
|
66
|
+
variable: URIRef
|
67
|
+
boundValue: URIRef
|
68
|
+
focus:URIRef
|
69
|
+
|
70
|
+
# Specification data sources
|
71
|
+
TableDataset: URIRef
|
72
|
+
StatementsDataset: URIRef
|
73
|
+
FileDataset: URIRef
|
74
|
+
HttpDataset: URIRef
|
75
|
+
TextSparqlSource: URIRef
|
76
|
+
FileSparqlSource: URIRef
|
77
|
+
FolderSparqlSource: URIRef
|
78
|
+
FolderDataset: URIRef
|
79
|
+
EmptyGraph: URIRef
|
80
|
+
EmptyTable: URIRef
|
81
|
+
InheritedDataset: URIRef
|
82
|
+
|
83
|
+
# runner uris
|
84
|
+
fileSource: URIRef
|
85
|
+
loadedFromFile: URIRef
|
86
|
+
specSourceFile: URIRef
|
87
|
+
|
88
|
+
# Triple store config parameters
|
89
|
+
url: URIRef
|
90
|
+
port: URIRef
|
91
|
+
username: URIRef
|
92
|
+
password: URIRef
|
93
|
+
inputGraph: URIRef
|
94
|
+
repository: URIRef
|
95
|
+
|
96
|
+
# RDFLib
|
97
|
+
RdfLib: URIRef
|
98
|
+
RdfLibConfig: URIRef
|
99
|
+
|
100
|
+
# Anzo
|
101
|
+
Anzo: URIRef
|
102
|
+
AnzoConfig: URIRef
|
103
|
+
AnzoGraphmartDataset: URIRef
|
104
|
+
AnzoQueryBuilderSparqlSource: URIRef
|
105
|
+
AnzoGraphmartStepSparqlSource: URIRef
|
106
|
+
AnzoGraphmartLayerSparqlSource: URIRef
|
107
|
+
AnzoGraphmartQueryDrivenTemplatedStepSparqlSource: URIRef
|
108
|
+
anzoQueryStep: URIRef
|
109
|
+
anzoGraphmartLayer: URIRef
|
110
|
+
|
111
|
+
|
112
|
+
graphmart: URIRef
|
113
|
+
layer: URIRef
|
114
|
+
gqeURI: URIRef
|
115
|
+
|
116
|
+
# GraphDb
|
117
|
+
GraphDb: URIRef
|
118
|
+
GraphDbConfig: URIRef
|
src/plugin.py
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
from typing import Dict
|
2
|
+
from mustrdTestPlugin import MustrdTestPlugin, TestConfig
|
3
|
+
from utils import get_project_root
|
4
|
+
from rdflib import RDF, Graph
|
5
|
+
from namespace import MUST
|
6
|
+
from collections import defaultdict
|
7
|
+
|
8
|
+
project_root = get_project_root()
|
9
|
+
|
10
|
+
|
11
|
+
def pytest_addoption(parser):
|
12
|
+
group = parser.getgroup("md summary")
|
13
|
+
group.addoption(
|
14
|
+
"--md",
|
15
|
+
action="store",
|
16
|
+
dest="mdpath",
|
17
|
+
metavar="path",
|
18
|
+
default=None,
|
19
|
+
help="create md summary file at that path.",
|
20
|
+
)
|
21
|
+
group.addoption(
|
22
|
+
"--config",
|
23
|
+
action="store",
|
24
|
+
dest="configpath",
|
25
|
+
metavar="path",
|
26
|
+
default=None,
|
27
|
+
required=True,
|
28
|
+
help="Ttl file containing the list of test to construct.",
|
29
|
+
)
|
30
|
+
return
|
31
|
+
|
32
|
+
|
33
|
+
def pytest_configure(config) -> None:
|
34
|
+
|
35
|
+
# Read configuration file
|
36
|
+
test_configs: Dict[str, TestConfig] = defaultdict(lambda: defaultdict(list))
|
37
|
+
config_graph = Graph().parse(project_root / config.getoption("configpath"))
|
38
|
+
for test_config_subject in config_graph.subjects(predicate=RDF.type, object=MUST.TestConfig):
|
39
|
+
test_function = get_config_param(config_graph, test_config_subject, MUST.hasTestFunction, str)
|
40
|
+
spec_path = get_config_param(config_graph, test_config_subject, MUST.hasSpecPath, str)
|
41
|
+
data_path = get_config_param(config_graph, test_config_subject, MUST.hasDataPath, str)
|
42
|
+
triplestore_spec_path = get_config_param(config_graph, test_config_subject, MUST.triplestoreSpecPath, str)
|
43
|
+
filter_on_tripleStore = list(config_graph.objects(subject=test_config_subject,
|
44
|
+
predicate=MUST.filterOnTripleStore))
|
45
|
+
|
46
|
+
test_configs[test_function] = TestConfig(test_function=test_function,
|
47
|
+
spec_path=spec_path, data_path=data_path,
|
48
|
+
triplestore_spec_path=triplestore_spec_path,
|
49
|
+
filter_on_tripleStore=filter_on_tripleStore)
|
50
|
+
|
51
|
+
config.pluginmanager.register(MustrdTestPlugin(config.getoption("mdpath"), test_configs))
|
52
|
+
|
53
|
+
|
54
|
+
def get_config_param(config_graph, config_subject, config_param, convert_function):
|
55
|
+
raw_value = config_graph.value(subject=config_subject, predicate=config_param, any=True)
|
56
|
+
return convert_function(raw_value) if raw_value else None
|
src/run.py
ADDED
@@ -0,0 +1,106 @@
|
|
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 argparse
|
26
|
+
import logger_setup
|
27
|
+
import sys
|
28
|
+
import os
|
29
|
+
from rdflib import Graph
|
30
|
+
from mustrd import get_triple_store_graph, run_specs, get_triple_stores, review_results, validate_specs, get_specs
|
31
|
+
from pathlib import Path
|
32
|
+
from namespace import MUST
|
33
|
+
from utils import get_project_root
|
34
|
+
import logging
|
35
|
+
log = logger_setup.setup_logger(__name__)
|
36
|
+
|
37
|
+
|
38
|
+
def parse_args() -> argparse.Namespace:
|
39
|
+
parser = argparse.ArgumentParser()
|
40
|
+
parser.add_argument("-p", "--put", help="Path under test - required", required=True)
|
41
|
+
parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
|
42
|
+
parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
|
43
|
+
parser.add_argument("-d", "--data", help="Path to test data", default=None)
|
44
|
+
parser.add_argument("-g", "--given", help="Override path for given files", default=None)
|
45
|
+
parser.add_argument("-w", "--when", help="Override path for when files", default=None)
|
46
|
+
parser.add_argument("-t", "--then", help="Override path for then files", default=None)
|
47
|
+
|
48
|
+
return parser.parse_args()
|
49
|
+
|
50
|
+
|
51
|
+
# https://github.com/Semantic-partners/mustrd/issues/108
|
52
|
+
def main(argv):
|
53
|
+
#given_path = when_path = then_path = None
|
54
|
+
project_root = get_project_root()
|
55
|
+
run_config = {}
|
56
|
+
args = parse_args()
|
57
|
+
run_config["spec_path"] = Path(args.put)
|
58
|
+
log.info(f"Path under test is { run_config['spec_path']}")
|
59
|
+
|
60
|
+
verbose = args.verbose
|
61
|
+
if verbose:
|
62
|
+
log.info(f"Verbose set")
|
63
|
+
run_config["verbose"] = True
|
64
|
+
|
65
|
+
if args.config:
|
66
|
+
triplestore_spec_path = Path(args.config)
|
67
|
+
log.info(f"Path for triple store configuration is {triplestore_spec_path}")
|
68
|
+
triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
|
69
|
+
else:
|
70
|
+
log.info(f"No triple store configuration added, running default configuration")
|
71
|
+
triple_stores = [{'type': MUST.RdfLib}]
|
72
|
+
log.info("Triple Stores: " + str(triple_stores))
|
73
|
+
if args.data:
|
74
|
+
run_config["data_path"] = Path(args.data)
|
75
|
+
else:
|
76
|
+
run_config["data_path"] = Path(args.put)
|
77
|
+
log.info(f"Path for test data folder is {run_config['data_path']}")
|
78
|
+
|
79
|
+
if args.given:
|
80
|
+
run_config["given_path"] = Path(args.given)
|
81
|
+
log.info(f"Path for given folder is {run_config['given_path']}")
|
82
|
+
|
83
|
+
if args.when:
|
84
|
+
run_config["when_path"] = Path(args.when)
|
85
|
+
log.info(f"Path for when folder is {run_config['when_path']}")
|
86
|
+
|
87
|
+
if args.then:
|
88
|
+
run_config["then_path"] = Path(args.then)
|
89
|
+
log.info(f"Path for then folder is {run_config['then_path']}")
|
90
|
+
|
91
|
+
shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
|
92
|
+
ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
|
93
|
+
|
94
|
+
valid_spec_uris, spec_graph, invalid_spec_results = \
|
95
|
+
validate_specs(run_config, triple_stores, shacl_graph, ont_graph)
|
96
|
+
|
97
|
+
specs, skipped_spec_results = \
|
98
|
+
get_specs(valid_spec_uris, spec_graph, triple_stores, run_config)
|
99
|
+
|
100
|
+
results = invalid_spec_results + skipped_spec_results + run_specs(specs)
|
101
|
+
|
102
|
+
review_results(results, verbose)
|
103
|
+
|
104
|
+
|
105
|
+
if __name__ == "__main__":
|
106
|
+
main(sys.argv[1:])
|