mustrd 0.2.1__py3-none-any.whl → 0.2.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.
@@ -85,37 +85,44 @@ def pytest_configure(config) -> None:
85
85
  if config.getoption("mustrd"):
86
86
  test_configs = parse_config(config.getoption("configpath"))
87
87
  config.pluginmanager.register(MustrdTestPlugin(config.getoption("mdpath"),
88
- test_configs, config.getoption("secrets")))
89
-
88
+ test_configs, config.getoption("secrets")))
89
+
90
+
90
91
  def parse_config(config_path):
91
92
  test_configs = []
92
93
  config_graph = Graph().parse(config_path)
93
94
  shacl_graph = Graph().parse(Path(os.path.join(mustrd_root, "model/mustrdTestShapes.ttl")))
94
95
  ont_graph = Graph().parse(Path(os.path.join(mustrd_root, "model/mustrdTestOntology.ttl")))
95
96
  conforms, results_graph, results_text = validate(
96
- data_graph= config_graph,
97
- shacl_graph = shacl_graph,
98
- ont_graph = ont_graph,
99
- advanced= True,
100
- inference= 'none'
97
+ data_graph=config_graph,
98
+ shacl_graph=shacl_graph,
99
+ ont_graph=ont_graph,
100
+ advanced=True,
101
+ inference='none'
101
102
  )
102
103
  if not conforms:
103
- raise ValueError(f"Mustrd test configuration not conform to the shapes. SHACL report: {results_text}", results_graph)
104
-
104
+ raise ValueError(f"Mustrd test configuration not conform to the shapes. SHACL report: {results_text}",
105
+ results_graph)
106
+
105
107
  for test_config_subject in config_graph.subjects(predicate=RDF.type, object=MUSTRDTEST.MustrdTest):
106
108
  spec_path = get_config_param(config_graph, test_config_subject, MUSTRDTEST.hasSpecPath, str)
107
109
  data_path = get_config_param(config_graph, test_config_subject, MUSTRDTEST.hasDataPath, str)
108
110
  triplestore_spec_path = get_config_param(config_graph, test_config_subject, MUSTRDTEST.triplestoreSpecPath, str)
109
111
  pytest_path = get_config_param(config_graph, test_config_subject, MUSTRDTEST.hasPytestPath, str)
110
112
  filter_on_tripleStore = list(config_graph.objects(subject=test_config_subject,
111
- predicate=MUSTRDTEST.filterOnTripleStore))
113
+ predicate=MUSTRDTEST.filterOnTripleStore))
114
+
115
+ # Root path is the mustrd test config path
116
+ root_path = Path(config_path).parent
117
+ spec_path = root_path / Path(spec_path) if spec_path else None
118
+ data_path = root_path / Path(data_path) if data_path else None
119
+ triplestore_spec_path = root_path / Path(triplestore_spec_path) if triplestore_spec_path else None
112
120
 
113
121
  test_configs.append(TestConfig(spec_path=spec_path, data_path=data_path,
114
- triplestore_spec_path=triplestore_spec_path,
115
- pytest_path = pytest_path,
116
- filter_on_tripleStore=filter_on_tripleStore))
122
+ triplestore_spec_path=triplestore_spec_path,
123
+ pytest_path=pytest_path,
124
+ filter_on_tripleStore=filter_on_tripleStore))
117
125
  return test_configs
118
-
119
126
 
120
127
 
121
128
  def get_config_param(config_graph, config_subject, config_param, convert_function):
@@ -125,18 +132,19 @@ def get_config_param(config_graph, config_subject, config_param, convert_functio
125
132
 
126
133
  @dataclass
127
134
  class TestConfig:
128
- spec_path: str
129
- data_path: str
130
- triplestore_spec_path: str
135
+ spec_path: Path
136
+ data_path: Path
137
+ triplestore_spec_path: Path
131
138
  pytest_path: str
132
139
  filter_on_tripleStore: str = None
133
-
140
+
134
141
 
135
142
  @dataclass
136
143
  class TestParamWrapper:
137
144
  test_config: TestConfig
138
145
  unit_test: Union[Specification, SpecSkipped]
139
146
 
147
+
140
148
  class MustrdTestPlugin:
141
149
  md_path: str
142
150
  test_configs: list
@@ -149,7 +157,7 @@ class MustrdTestPlugin:
149
157
  self.test_configs = test_configs
150
158
  self.secrets = secrets
151
159
  self.items = []
152
-
160
+
153
161
  @pytest.hookimpl(tryfirst=True)
154
162
  def pytest_collection(self, session):
155
163
  self.unit_tests = []
@@ -157,7 +165,7 @@ class MustrdTestPlugin:
157
165
  if len(args) > 0:
158
166
  file_name = self.get_file_name_from_arg(args[0])
159
167
  # Filter test to collect only specified path
160
- config_to_collect = list(filter(lambda config:
168
+ config_to_collect = list(filter(lambda config:
161
169
  # Case we want to collect everything
162
170
  MUSTRD_PYTEST_PATH not in args[0]
163
171
  # Case we want to collect a test or sub test
@@ -165,30 +173,33 @@ class MustrdTestPlugin:
165
173
  # Case we want to collect a whole test folder
166
174
  or args[0].replace(f"./{MUSTRD_PYTEST_PATH}", "") in config.pytest_path,
167
175
  self.test_configs))
168
-
169
- # Redirect everything to test_mustrd.py, no need to filter on specified test: Only specified test will be collected anyway
176
+
177
+ # Redirect everything to test_mustrd.py,
178
+ # no need to filter on specified test: Only specified test will be collected anyway
170
179
  session.config.args[0] = os.path.join(mustrd_root, "test/test_mustrd.py")
171
180
  # Collecting only relevant tests
172
-
173
- for one_test_config in config_to_collect:
181
+
182
+ for one_test_config in config_to_collect:
174
183
  triple_stores = self.get_triple_stores_from_file(one_test_config)
175
184
 
176
185
  if one_test_config.filter_on_tripleStore and not triple_stores:
177
- self.unit_tests.extend(list(map(lambda triple_store:
178
- TestParamWrapper(test_config = one_test_config, unit_test=SpecSkipped(MUST.TestSpec, triple_store, "No triplestore found")),
179
- one_test_config.filter_on_tripleStore)))
186
+ self.unit_tests.extend(list(map(
187
+ lambda triple_store:
188
+ TestParamWrapper(test_config=one_test_config,
189
+ unit_test=SpecSkipped(MUST.TestSpec, triple_store, "No triplestore found")),
190
+ one_test_config.filter_on_tripleStore)))
180
191
  else:
181
- specs = self.generate_tests_for_config({"spec_path": Path(one_test_config.spec_path),
182
- "data_path": Path(one_test_config.data_path)},
183
- triple_stores, file_name)
184
- self.unit_tests.extend(list(map(lambda spec: TestParamWrapper(test_config = one_test_config, unit_test=spec),specs)))
185
-
192
+ specs = self.generate_tests_for_config({"spec_path": one_test_config.spec_path,
193
+ "data_path": one_test_config.data_path},
194
+ triple_stores, file_name)
195
+ self.unit_tests.extend(list(map(
196
+ lambda spec: TestParamWrapper(test_config=one_test_config, unit_test=spec), specs)))
197
+
186
198
  def get_file_name_from_arg(self, arg):
187
199
  if arg and len(arg) > 0 and "[" in arg and ".mustrd.ttl@" in arg:
188
200
  return arg[arg.index("[") + 1: arg.index(".mustrd.ttl@")]
189
201
  return None
190
-
191
-
202
+
192
203
  @pytest.hookimpl(hookwrapper=True)
193
204
  def pytest_pycollect_makeitem(self, collector, name, obj):
194
205
  report = yield
@@ -196,18 +207,17 @@ class MustrdTestPlugin:
196
207
  items = report.get_result()
197
208
  new_results = []
198
209
  for item in items:
199
- virtual_path = MUSTRD_PYTEST_PATH + (item.callspec.params["unit_tests"].test_config.pytest_path or "default")
210
+ virtual_path = MUSTRD_PYTEST_PATH + (item.callspec.params["unit_tests"].test_config.pytest_path or "default")
200
211
  item.fspath = Path(virtual_path)
201
212
  item._nodeid = virtual_path + "::" + item.name
202
213
  self.items.append(item)
203
214
  new_results.append(item)
204
215
  return new_results
205
-
206
216
 
207
217
  # Hook called at collection time: reads the configuration of the tests, and generate pytests from it
208
218
  def pytest_generate_tests(self, metafunc):
209
219
  if len(metafunc.fixturenames) > 0:
210
- if metafunc.function.__name__ == "test_unit":
220
+ if metafunc.function.__name__ == "test_unit":
211
221
  # Create the test in itself
212
222
  if self.unit_tests:
213
223
  metafunc.parametrize(metafunc.fixturenames[0], self.unit_tests,
@@ -217,9 +227,6 @@ class MustrdTestPlugin:
217
227
  metafunc.parametrize(metafunc.fixturenames[0],
218
228
  [SpecSkipped(MUST.TestSpec, None, "No triplestore found")],
219
229
  ids=lambda x: "No configuration found for this test")
220
-
221
-
222
-
223
230
 
224
231
  # Generate test for each triple store available
225
232
  def generate_tests_for_config(self, config, triple_stores, file_name):
@@ -250,7 +257,7 @@ class MustrdTestPlugin:
250
257
  def get_triple_stores_from_file(self, test_config):
251
258
  if test_config.triplestore_spec_path:
252
259
  try:
253
- triple_stores = get_triple_stores(get_triple_store_graph(Path(test_config.triplestore_spec_path),
260
+ triple_stores = get_triple_stores(get_triple_store_graph(test_config.triplestore_spec_path,
254
261
  self.secrets))
255
262
  except Exception as e:
256
263
  print(f"""Triplestore configuration parsing failed {test_config.triplestore_spec_path}.
mustrd/namespace.py CHANGED
@@ -25,10 +25,11 @@ SOFTWARE.
25
25
  from rdflib import URIRef
26
26
  from rdflib.namespace import DefinedNamespace, Namespace
27
27
 
28
+
28
29
  # Namespace for the test specifications
29
30
  class MUST(DefinedNamespace):
30
31
  _NS = Namespace("https://mustrd.com/model/")
31
-
32
+
32
33
  # Specification classes
33
34
  TestSpec: URIRef
34
35
  SelectSparql: URIRef
@@ -55,7 +56,7 @@ class MUST(DefinedNamespace):
55
56
  hasBinding: URIRef
56
57
  variable: URIRef
57
58
  boundValue: URIRef
58
- focus:URIRef
59
+ focus: URIRef
59
60
 
60
61
  # Specification data sources
61
62
  TableDataset: URIRef
@@ -85,16 +86,16 @@ class MUST(DefinedNamespace):
85
86
  AnzoGraphmartQueryDrivenTemplatedStepSparqlSource: URIRef
86
87
  anzoQueryStep: URIRef
87
88
  anzoGraphmartLayer: URIRef
88
-
89
+
89
90
  graphmart: URIRef
90
91
  layer: URIRef
91
92
 
92
-
93
93
  # FIXME: There is nothing to do that by default?
94
94
  @classmethod
95
95
  def get_local_name(cls, uri: URIRef):
96
96
  return str(uri).split(cls._NS)[1]
97
97
 
98
+
98
99
  # Namespace for triplestores
99
100
  class TRIPLESTORE(DefinedNamespace):
100
101
  _NS = Namespace("https://mustrd.com/triplestore/")
@@ -103,16 +104,17 @@ class TRIPLESTORE(DefinedNamespace):
103
104
  Anzo: URIRef
104
105
  ExternalTripleStore: URIRef
105
106
  InternalTripleStore: URIRef
106
-
107
+
107
108
  gqeURI: URIRef
108
- inputGraph: URIRef
109
- outputGraph: URIRef # anzo specials? # Triple store config parameters
109
+ inputGraph: URIRef
110
+ outputGraph: URIRef # anzo specials? # Triple store config parameters
110
111
  url: URIRef
111
112
  port: URIRef
112
113
  username: URIRef
113
114
  password: URIRef
114
115
  repository: URIRef
115
116
 
117
+
116
118
  # namespace for pytest_mustrd config
117
119
  class MUSTRDTEST(DefinedNamespace):
118
120
  _NS = Namespace("https://mustrd.com/mustrdTest/")
@@ -122,4 +124,3 @@ class MUSTRDTEST(DefinedNamespace):
122
124
  triplestoreSpecPath: URIRef
123
125
  hasPytestPath: URIRef
124
126
  filterOnTripleStore: URIRef
125
-
mustrd/run.py CHANGED
@@ -31,7 +31,6 @@ from .mustrd import get_triple_store_graph, run_specs, get_triple_stores, review
31
31
  from pathlib import Path
32
32
  from .namespace import TRIPLESTORE
33
33
  from .utils import get_project_root
34
- import logging
35
34
  log = logger_setup.setup_logger(__name__)
36
35
 
37
36
 
@@ -50,7 +49,7 @@ def parse_args() -> argparse.Namespace:
50
49
 
51
50
  # https://github.com/Semantic-partners/mustrd/issues/108
52
51
  def main(argv):
53
- #given_path = when_path = then_path = None
52
+ # Given_path = when_path = then_path = None
54
53
  project_root = get_project_root()
55
54
  run_config = {}
56
55
  args = parse_args()
@@ -59,7 +58,7 @@ def main(argv):
59
58
 
60
59
  verbose = args.verbose
61
60
  if verbose:
62
- log.info(f"Verbose set")
61
+ log.info("Verbose set")
63
62
  run_config["verbose"] = True
64
63
 
65
64
  if args.config:
@@ -67,7 +66,7 @@ def main(argv):
67
66
  log.info(f"Path for triple store configuration is {triplestore_spec_path}")
68
67
  triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
69
68
  else:
70
- log.info(f"No triple store configuration added, running default configuration")
69
+ log.info("No triple store configuration added, running default configuration")
71
70
  triple_stores = [{'type': TRIPLESTORE.RdfLib}]
72
71
  log.info("Triple Stores: " + str(triple_stores))
73
72
  if args.data: