mustrd 0.1.5__tar.gz → 0.1.7__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.
Files changed (25) hide show
  1. {mustrd-0.1.5 → mustrd-0.1.7}/PKG-INFO +1 -1
  2. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/mustrd.py +7 -5
  3. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/mustrdTestPlugin.py +68 -6
  4. {mustrd-0.1.5 → mustrd-0.1.7}/pyproject.toml +2 -2
  5. mustrd-0.1.5/mustrd/plugin.py +0 -78
  6. {mustrd-0.1.5 → mustrd-0.1.7}/LICENSE +0 -0
  7. {mustrd-0.1.5 → mustrd-0.1.7}/README.adoc +0 -0
  8. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/README.adoc +0 -0
  9. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/TestResult.py +0 -0
  10. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/__init__.py +0 -0
  11. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/logger_setup.py +0 -0
  12. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/model/mustrdShapes.ttl +0 -0
  13. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/model/ontology.ttl +0 -0
  14. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/model/test-resources/resources.ttl +0 -0
  15. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/mustrdAnzo.py +0 -0
  16. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/mustrdGraphDb.py +0 -0
  17. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/mustrdRdfLib.py +0 -0
  18. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/namespace.py +0 -0
  19. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/run.py +0 -0
  20. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/spec_component.py +0 -0
  21. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/steprunner.py +0 -0
  22. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/templates/md_ResultList_leaf_template.jinja +0 -0
  23. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/templates/md_ResultList_template.jinja +0 -0
  24. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/templates/md_stats_template.jinja +0 -0
  25. {mustrd-0.1.5 → mustrd-0.1.7}/mustrd/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mustrd
3
- Version: 0.1.5
3
+ Version: 0.1.7
4
4
  Summary: A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber.
5
5
  Home-page: https://github.com/Semantic-partners/mustrd
6
6
  License: MIT
@@ -381,11 +381,13 @@ def run_spec(spec: Specification) -> SpecResult:
381
381
  # if type(mustrd_triple_store) == MustrdAnzo and close_connection:
382
382
  # mustrd_triple_store.clear_graph()
383
383
 
384
-
385
-
386
- def get_triple_store_graph(triple_store_graph_path: Path):
387
- secret_path = triple_store_graph_path.parent / Path(triple_store_graph_path.stem + "_secrets" + triple_store_graph_path.suffix)
388
- return Graph().parse(triple_store_graph_path).parse(secret_path)
384
+ def get_triple_store_graph(triple_store_graph_path: Path, secrets: str):
385
+ if secrets:
386
+ return Graph().parse(triple_store_graph_path).parse(data = secrets)
387
+ else:
388
+ secret_path = triple_store_graph_path.parent / Path(triple_store_graph_path.stem + "_secrets" + triple_store_graph_path.suffix)
389
+ return Graph().parse(triple_store_graph_path).parse(source = secret_path)
390
+
389
391
 
390
392
  def get_triple_stores(triple_store_graph: Graph) -> list[dict]:
391
393
  triple_stores = []
@@ -27,20 +27,79 @@ import pytest
27
27
  import os
28
28
  from pathlib import Path
29
29
  from rdflib.namespace import Namespace
30
- from rdflib import Graph
30
+ from rdflib import Graph, RDF
31
31
  from pytest import Session
32
32
  from typing import Dict
33
33
 
34
34
  from mustrd.TestResult import ResultList, TestResult, get_result_list
35
35
  from mustrd.utils import get_mustrd_root
36
- from mustrd.mustrd import get_triple_store_graph, get_triple_stores, SpecSkipped, validate_specs, get_specs, SpecPassed, run_spec
36
+ from mustrd.mustrd import get_triple_store_graph, get_triple_stores
37
+ from mustrd.mustrd import SpecSkipped, validate_specs, get_specs, SpecPassed, run_spec
37
38
  from mustrd.namespace import MUST
39
+ from collections import defaultdict
38
40
 
39
41
  spnamespace = Namespace("https://semanticpartners.com/data/test/")
40
42
 
41
43
  mustrd_root = get_mustrd_root()
42
44
 
43
45
 
46
+ def pytest_addoption(parser):
47
+ group = parser.getgroup("md summary")
48
+ group.addoption(
49
+ "--md",
50
+ action="store",
51
+ dest="mdpath",
52
+ metavar="pathToMdSummary",
53
+ default=None,
54
+ help="create md summary file at that path.",
55
+ )
56
+ group.addoption(
57
+ "--config",
58
+ action="store",
59
+ dest="configpath",
60
+ metavar="pathToTestConfig",
61
+ default=None,
62
+ required=True,
63
+ help="Ttl file containing the list of test to construct.",
64
+ )
65
+ group.addoption(
66
+ "--secrets",
67
+ action="store",
68
+ dest="secrets",
69
+ metavar="Secrets",
70
+ default=None,
71
+ required=False,
72
+ help="Give the secrets by command line in order to be able to store secrets safely in CI tools",
73
+ )
74
+ return
75
+
76
+
77
+ def pytest_configure(config) -> None:
78
+ # Read configuration file
79
+ test_configs: Dict[str, TestConfig] = defaultdict(lambda: defaultdict(list))
80
+ config_graph = Graph().parse(config.getoption("configpath"))
81
+ for test_config_subject in config_graph.subjects(predicate=RDF.type, object=MUST.TestConfig):
82
+ test_function = get_config_param(config_graph, test_config_subject, MUST.hasTestFunction, str)
83
+ spec_path = get_config_param(config_graph, test_config_subject, MUST.hasSpecPath, str)
84
+ data_path = get_config_param(config_graph, test_config_subject, MUST.hasDataPath, str)
85
+ triplestore_spec_path = get_config_param(config_graph, test_config_subject, MUST.triplestoreSpecPath, str)
86
+ filter_on_tripleStore = list(config_graph.objects(subject=test_config_subject,
87
+ predicate=MUST.filterOnTripleStore))
88
+
89
+ test_configs[test_function] = TestConfig(test_function=test_function,
90
+ spec_path=spec_path, data_path=data_path,
91
+ triplestore_spec_path=triplestore_spec_path,
92
+ filter_on_tripleStore=filter_on_tripleStore)
93
+
94
+ config.pluginmanager.register(MustrdTestPlugin(config.getoption("mdpath"),
95
+ test_configs, config.getoption("secrets")))
96
+
97
+
98
+ def get_config_param(config_graph, config_subject, config_param, convert_function):
99
+ raw_value = config_graph.value(subject=config_subject, predicate=config_param, any=True)
100
+ return convert_function(raw_value) if raw_value else None
101
+
102
+
44
103
  @dataclass
45
104
  class TestConfig:
46
105
  test_function: str
@@ -61,10 +120,12 @@ class TestConfig:
61
120
  class MustrdTestPlugin:
62
121
  md_path: str
63
122
  test_configs: Dict[str, TestConfig]
123
+ secrets: str
64
124
 
65
- def __init__(self, md_path, test_configs):
125
+ def __init__(self, md_path, test_configs, secrets):
66
126
  self.md_path = md_path
67
127
  self.test_configs = test_configs
128
+ self.secrets = secrets
68
129
 
69
130
  # Hook called at collection time: reads the configuration of the tests, and generate pytests from it
70
131
  def pytest_generate_tests(self, metafunc):
@@ -122,10 +183,11 @@ class MustrdTestPlugin:
122
183
  def get_triple_stores_from_file(self, test_config):
123
184
  if test_config.triplestore_spec_path:
124
185
  try:
125
- triple_stores = get_triple_stores(get_triple_store_graph(Path(test_config.triplestore_spec_path)))
126
- except Exception:
186
+ triple_stores = get_triple_stores(get_triple_store_graph(Path(test_config.triplestore_spec_path),
187
+ self.secrets))
188
+ except Exception as e:
127
189
  print(f"""No triple store configuration found at {test_config.triplestore_spec_path}.
128
- Fall back: only embedded rdflib will be executed""")
190
+ Fall back: only embedded rdflib will be executed""", e)
129
191
  triple_stores = [{'type': MUST.RdfLib}]
130
192
  else:
131
193
  print("No triple store configuration required: using embedded rdflib")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mustrd"
3
- version = "0.1.5"
3
+ version = "0.1.7"
4
4
  description = "A Spec By Example framework for RDF and SPARQL, Inspired by Cucumber."
5
5
  authors = ["John Placek <john.placek@semanticpartners.com>",
6
6
  "Juliane Piñeiro-Winkler <juliane.pineiro-winkler@semanticpartners.com>",
@@ -51,4 +51,4 @@ requires = ["poetry-core>=1.0.0"]
51
51
  build-backend = "poetry.core.masonry.api"
52
52
 
53
53
  [tool.poetry.plugins.pytest11]
54
- mustrd_plugin = "mustrd.plugin"
54
+ mustrd_plugin = "mustrd.mustrdTestPlugin"
@@ -1,78 +0,0 @@
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 typing import Dict
26
- from .mustrdTestPlugin import MustrdTestPlugin, TestConfig
27
- from rdflib import RDF, Graph
28
- from .namespace import MUST
29
- from collections import defaultdict
30
-
31
-
32
-
33
- def pytest_addoption(parser):
34
- group = parser.getgroup("md summary")
35
- group.addoption(
36
- "--md",
37
- action="store",
38
- dest="mdpath",
39
- metavar="path",
40
- default=None,
41
- help="create md summary file at that path.",
42
- )
43
- group.addoption(
44
- "--config",
45
- action="store",
46
- dest="configpath",
47
- metavar="path",
48
- default=None,
49
- required=True,
50
- help="Ttl file containing the list of test to construct.",
51
- )
52
- return
53
-
54
-
55
- def pytest_configure(config) -> None:
56
-
57
- # Read configuration file
58
- test_configs: Dict[str, TestConfig] = defaultdict(lambda: defaultdict(list))
59
- config_graph = Graph().parse(config.getoption("configpath"))
60
- for test_config_subject in config_graph.subjects(predicate=RDF.type, object=MUST.TestConfig):
61
- test_function = get_config_param(config_graph, test_config_subject, MUST.hasTestFunction, str)
62
- spec_path = get_config_param(config_graph, test_config_subject, MUST.hasSpecPath, str)
63
- data_path = get_config_param(config_graph, test_config_subject, MUST.hasDataPath, str)
64
- triplestore_spec_path = get_config_param(config_graph, test_config_subject, MUST.triplestoreSpecPath, str)
65
- filter_on_tripleStore = list(config_graph.objects(subject=test_config_subject,
66
- predicate=MUST.filterOnTripleStore))
67
-
68
- test_configs[test_function] = TestConfig(test_function=test_function,
69
- spec_path=spec_path, data_path=data_path,
70
- triplestore_spec_path=triplestore_spec_path,
71
- filter_on_tripleStore=filter_on_tripleStore)
72
-
73
- config.pluginmanager.register(MustrdTestPlugin(config.getoption("mdpath"), test_configs))
74
-
75
-
76
- def get_config_param(config_graph, config_subject, config_param, convert_function):
77
- raw_value = config_graph.value(subject=config_subject, predicate=config_param, any=True)
78
- return convert_function(raw_value) if raw_value else None
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes