mustrd 0.2.0__tar.gz → 0.2.2__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.2.0 → mustrd-0.2.2}/LICENSE +21 -21
- {mustrd-0.2.0 → mustrd-0.2.2}/PKG-INFO +11 -4
- {mustrd-0.2.0 → mustrd-0.2.2}/README.adoc +62 -58
- mustrd-0.2.2/mustrd/README.adoc +33 -0
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/TestResult.py +136 -136
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/logger_setup.py +48 -48
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/catalog-v001.xml +5 -5
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/mustrdShapes.ttl +253 -253
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/mustrdTestShapes.ttl +24 -24
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/ontology.ttl +494 -494
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/test-resources/resources.ttl +60 -60
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/triplestoreOntology.ttl +174 -174
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/triplestoreshapes.ttl +41 -41
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/mustrd.py +778 -787
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/mustrdAnzo.py +251 -220
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/mustrdGraphDb.py +125 -125
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/mustrdRdfLib.py +56 -56
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/mustrdTestPlugin.py +334 -328
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/namespace.py +126 -125
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/run.py +105 -106
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/spec_component.py +701 -690
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/steprunner.py +166 -166
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/templates/md_ResultList_leaf_template.jinja +18 -18
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/templates/md_ResultList_template.jinja +8 -8
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/templates/md_stats_template.jinja +2 -2
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/test/test_mustrd.py +5 -5
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/utils.py +39 -38
- {mustrd-0.2.0 → mustrd-0.2.2}/pyproject.toml +55 -54
- mustrd-0.2.0/mustrd/README.adoc +0 -210
- mustrd-0.2.0/mustrd/mustrdQueryProcessor.py +0 -136
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/__init__.py +0 -0
- {mustrd-0.2.0 → mustrd-0.2.2}/mustrd/model/mustrdTestOntology.ttl +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.
|
@@ -1,17 +1,19 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: mustrd
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.2
|
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
|
7
7
|
Author: John Placek
|
8
8
|
Author-email: john.placek@semanticpartners.com
|
9
|
-
Requires-Python:
|
9
|
+
Requires-Python: >=3.11,<4.0
|
10
10
|
Classifier: Framework :: Pytest
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
12
12
|
Classifier: Natural Language :: English
|
13
13
|
Classifier: Programming Language :: Python
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
15
17
|
Classifier: Topic :: Software Development :: Quality Assurance
|
16
18
|
Classifier: Topic :: Software Development :: Testing
|
17
19
|
Classifier: Topic :: Utilities
|
@@ -22,6 +24,7 @@ Requires-Dist: colorlog (>=6.7.0,<7.0.0)
|
|
22
24
|
Requires-Dist: coverage (==7.4.3)
|
23
25
|
Requires-Dist: flake8 (==7.0.0)
|
24
26
|
Requires-Dist: multimethods-py (>=0.5.3,<0.6.0)
|
27
|
+
Requires-Dist: numpy (>=1.26.0,<1.27.0)
|
25
28
|
Requires-Dist: openpyxl (>=3.1.2,<4.0.0)
|
26
29
|
Requires-Dist: pandas (>=1.5.2,<2.0.0)
|
27
30
|
Requires-Dist: pyanzo (>=3.3.10,<4.0.0)
|
@@ -32,7 +35,7 @@ Requires-Dist: requests (>=2.28.2,<3.0.0)
|
|
32
35
|
Requires-Dist: tabulate (>=0.9.0,<0.10.0)
|
33
36
|
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
34
37
|
Requires-Dist: tomli (>=2.0.1,<3.0.0)
|
35
|
-
Requires-Dist: urllib3 (==1.26.
|
38
|
+
Requires-Dist: urllib3 (==1.26.19)
|
36
39
|
Project-URL: Repository, https://github.com/Semantic-partners/mustrd
|
37
40
|
Description-Content-Type: text/plain
|
38
41
|
|
@@ -93,5 +96,9 @@ We invite you to try it, see where it doesn't fit, and raise an issue, or even b
|
|
93
96
|
We're a specialist consultancy in Semantic Tech, we're putting this out in case it's useful, but if you need more support, kindly contact our business team on info@semanticpartners.com
|
94
97
|
|
95
98
|
// tag::body[]
|
96
|
-
|
99
|
+
|
100
|
+
include::GETSTARTED.adoc[Get started]
|
101
|
+
|
102
|
+
Developer doc:
|
103
|
+
include::mustrd/README.adoc[tags=body]
|
97
104
|
|
@@ -1,58 +1,62 @@
|
|
1
|
-
== Mustrd
|
2
|
-
|
3
|
-
// tag::body[]
|
4
|
-
|
5
|
-
image::https://github.com/Semantic-partners/mustrd/raw/python-coverage-comment-action-data/badge.svg[Coverage badge,link="https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data"]
|
6
|
-
|
7
|
-
=== Why?
|
8
|
-
|
9
|
-
How do you know your SPARQL, whether it's in a pipeline, or a query, is doing what you intend?
|
10
|
-
|
11
|
-
As much as we love RDF and SPARQL and Semantic Tech in general, we found a small gap in tooling which would give us that certainty.
|
12
|
-
|
13
|
-
We missed the powerful testing frameworks that have evolved in imperative languages that help ensure you've written code that does what you think it should.
|
14
|
-
|
15
|
-
We wanted to be able to:
|
16
|
-
|
17
|
-
* setup data scenarios and ensure queries worked as expected
|
18
|
-
* setup edge cases for queries and ensure they still work
|
19
|
-
* isolate small sparql enrichment / transformation steps and to know we're only INSERTing what we intend
|
20
|
-
|
21
|
-
Enter MustRD.
|
22
|
-
|
23
|
-
=== What?
|
24
|
-
|
25
|
-
MustRD is a Spec-By-Example ontology, with a reference python implementation, inspired by the likes of Cucumber.
|
26
|
-
|
27
|
-
It's designed to be triplestore/SPARQL engine agnostic (aren't open standards *wonderful*!).
|
28
|
-
|
29
|
-
=== What it is NOT
|
30
|
-
MustRD is nothing to do with SHACL, or an alternative to it. In fact, we use SHACL for some of our features.
|
31
|
-
|
32
|
-
SHACL provides validation around data.
|
33
|
-
|
34
|
-
MustRD provides validation around data transformations.
|
35
|
-
|
36
|
-
=== How?
|
37
|
-
You define your specs in ttl, or trig files.
|
38
|
-
We use the SBE approach of *Given*, *When*, *Then* to define starting dataset, an action, and a set of expectations. We build up a set of data.
|
39
|
-
Then, depending on whether your SPARQL is a CONSTRUCT, SELECT or a INSERT/DELETE, we run it, and compare results against a set of expectations (*Then*) that are defined in the same way as a *Given* .
|
40
|
-
Alternatively, you could define your *Then*
|
41
|
-
|
42
|
-
* as an explicit ASK, or
|
43
|
-
* select; or
|
44
|
-
* in a higher-order expectation language like you will be used to in various platforms, a set of expectations.
|
45
|
-
|
46
|
-
|
47
|
-
=== When?
|
48
|
-
|
49
|
-
Soon. It's a work in progress, and we're building the things *we* need for the projects we work on at multiple clients, with multiple vendor stacks.
|
50
|
-
We already think it's useful, but it might not meet *your* needs, out of the box.
|
51
|
-
|
52
|
-
We invite you to try it, see where it doesn't fit, and raise an issue, or even better, a PR! If you need something custom, please check out our consultancy rates, and we might be able to prioritise a new feature for you.
|
53
|
-
|
54
|
-
== Support
|
55
|
-
We're a specialist consultancy in Semantic Tech, we're putting this out in case it's useful, but if you need more support, kindly contact our business team on info@semanticpartners.com
|
56
|
-
|
57
|
-
// tag::body[]
|
58
|
-
|
1
|
+
== Mustrd
|
2
|
+
|
3
|
+
// tag::body[]
|
4
|
+
|
5
|
+
image::https://github.com/Semantic-partners/mustrd/raw/python-coverage-comment-action-data/badge.svg[Coverage badge,link="https://github.com/Semantic-partners/mustrd/tree/python-coverage-comment-action-data"]
|
6
|
+
|
7
|
+
=== Why?
|
8
|
+
|
9
|
+
How do you know your SPARQL, whether it's in a pipeline, or a query, is doing what you intend?
|
10
|
+
|
11
|
+
As much as we love RDF and SPARQL and Semantic Tech in general, we found a small gap in tooling which would give us that certainty.
|
12
|
+
|
13
|
+
We missed the powerful testing frameworks that have evolved in imperative languages that help ensure you've written code that does what you think it should.
|
14
|
+
|
15
|
+
We wanted to be able to:
|
16
|
+
|
17
|
+
* setup data scenarios and ensure queries worked as expected
|
18
|
+
* setup edge cases for queries and ensure they still work
|
19
|
+
* isolate small sparql enrichment / transformation steps and to know we're only INSERTing what we intend
|
20
|
+
|
21
|
+
Enter MustRD.
|
22
|
+
|
23
|
+
=== What?
|
24
|
+
|
25
|
+
MustRD is a Spec-By-Example ontology, with a reference python implementation, inspired by the likes of Cucumber.
|
26
|
+
|
27
|
+
It's designed to be triplestore/SPARQL engine agnostic (aren't open standards *wonderful*!).
|
28
|
+
|
29
|
+
=== What it is NOT
|
30
|
+
MustRD is nothing to do with SHACL, or an alternative to it. In fact, we use SHACL for some of our features.
|
31
|
+
|
32
|
+
SHACL provides validation around data.
|
33
|
+
|
34
|
+
MustRD provides validation around data transformations.
|
35
|
+
|
36
|
+
=== How?
|
37
|
+
You define your specs in ttl, or trig files.
|
38
|
+
We use the SBE approach of *Given*, *When*, *Then* to define starting dataset, an action, and a set of expectations. We build up a set of data.
|
39
|
+
Then, depending on whether your SPARQL is a CONSTRUCT, SELECT or a INSERT/DELETE, we run it, and compare results against a set of expectations (*Then*) that are defined in the same way as a *Given* .
|
40
|
+
Alternatively, you could define your *Then*
|
41
|
+
|
42
|
+
* as an explicit ASK, or
|
43
|
+
* select; or
|
44
|
+
* in a higher-order expectation language like you will be used to in various platforms, a set of expectations.
|
45
|
+
|
46
|
+
|
47
|
+
=== When?
|
48
|
+
|
49
|
+
Soon. It's a work in progress, and we're building the things *we* need for the projects we work on at multiple clients, with multiple vendor stacks.
|
50
|
+
We already think it's useful, but it might not meet *your* needs, out of the box.
|
51
|
+
|
52
|
+
We invite you to try it, see where it doesn't fit, and raise an issue, or even better, a PR! If you need something custom, please check out our consultancy rates, and we might be able to prioritise a new feature for you.
|
53
|
+
|
54
|
+
== Support
|
55
|
+
We're a specialist consultancy in Semantic Tech, we're putting this out in case it's useful, but if you need more support, kindly contact our business team on info@semanticpartners.com
|
56
|
+
|
57
|
+
// tag::body[]
|
58
|
+
|
59
|
+
include::GETSTARTED.adoc[Get started]
|
60
|
+
|
61
|
+
Developer doc:
|
62
|
+
include::mustrd/README.adoc[tags=body]
|
@@ -0,0 +1,33 @@
|
|
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
|
+
== Additional Notes for Developers
|
26
|
+
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.
|
27
|
+
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.
|
28
|
+
|
29
|
+
`poetry export -f requirements.txt --without-hashes > requirements.txt`
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
// end::body[]
|
@@ -1,136 +1,136 @@
|
|
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 Union
|
26
|
-
from itertools import groupby
|
27
|
-
from jinja2 import Environment, FileSystemLoader
|
28
|
-
from dataclasses import dataclass
|
29
|
-
from enum import Enum
|
30
|
-
from pathlib import Path
|
31
|
-
import os
|
32
|
-
from mustrd.utils import get_mustrd_root
|
33
|
-
|
34
|
-
|
35
|
-
class testType(Enum):
|
36
|
-
MUSTRD = "Mustrd"
|
37
|
-
PYTEST = "Pytest"
|
38
|
-
|
39
|
-
|
40
|
-
class testStatus(Enum):
|
41
|
-
PASSED = "passed"
|
42
|
-
FAILED = "failed"
|
43
|
-
SKIPPED = "skipped"
|
44
|
-
|
45
|
-
|
46
|
-
TEMPLATE_FOLDER =
|
47
|
-
|
48
|
-
|
49
|
-
RESULT_LIST_MD_TEMPLATE = "md_ResultList_template.jinja"
|
50
|
-
RESULT_LIST_LEAF_MD_TEMPLATE = "md_ResultList_leaf_template.jinja"
|
51
|
-
|
52
|
-
|
53
|
-
@dataclass
|
54
|
-
class TestResult:
|
55
|
-
test_name: str
|
56
|
-
class_name: str
|
57
|
-
module_name: str
|
58
|
-
status: str
|
59
|
-
is_mustrd: bool
|
60
|
-
type: str
|
61
|
-
|
62
|
-
def __init__(self, test_name: str, class_name: str, module_name: str, status: str, is_mustrd: bool):
|
63
|
-
self.test_name = test_name
|
64
|
-
self.class_name = class_name
|
65
|
-
self.module_name = module_name
|
66
|
-
self.status = status
|
67
|
-
self.is_mustrd = is_mustrd
|
68
|
-
self.type = testType.MUSTRD.value if self.is_mustrd else testType.PYTEST.value
|
69
|
-
|
70
|
-
|
71
|
-
@dataclass
|
72
|
-
class Stats:
|
73
|
-
count: int
|
74
|
-
success_count: int
|
75
|
-
fail_count: int
|
76
|
-
skipped_count: int
|
77
|
-
|
78
|
-
def __init__(self, count: int, success_count: int, fail_count: int, skipped_count: int):
|
79
|
-
self.count = count
|
80
|
-
self.success_count = success_count
|
81
|
-
self.fail_count = fail_count
|
82
|
-
self.skipped_count = skipped_count
|
83
|
-
|
84
|
-
|
85
|
-
def get_result_list(test_results: list[TestResult], *group_functions):
|
86
|
-
if len(group_functions) > 0:
|
87
|
-
return list(map(lambda key_group:
|
88
|
-
ResultList(key_group[0],
|
89
|
-
get_result_list(key_group[1],
|
90
|
-
*group_functions[1:]),
|
91
|
-
len(group_functions) == 1),
|
92
|
-
groupby(sorted(test_results, key=group_functions[0]), group_functions[0])))
|
93
|
-
else:
|
94
|
-
return list(test_results)
|
95
|
-
|
96
|
-
|
97
|
-
@dataclass
|
98
|
-
class ResultList:
|
99
|
-
name: str
|
100
|
-
stats: Stats
|
101
|
-
is_leaf: bool
|
102
|
-
# string type to workaround recursive call
|
103
|
-
result_list: Union[list['ResultList'], list[TestResult]]
|
104
|
-
|
105
|
-
def __init__(self, name: str, result_list: Union[list['ResultList'], list[TestResult]], is_leaf: bool = False):
|
106
|
-
self.name = name
|
107
|
-
self.result_list = result_list
|
108
|
-
self.is_leaf = is_leaf
|
109
|
-
self.compute_stats()
|
110
|
-
|
111
|
-
def compute_stats(self):
|
112
|
-
count, success_count, fail_count, skipped_count = 0, 0, 0, 0
|
113
|
-
|
114
|
-
if self.is_leaf:
|
115
|
-
count = len(self.result_list)
|
116
|
-
success_count = len(
|
117
|
-
list(filter(lambda x: x.status == testStatus.PASSED.value, self.result_list)))
|
118
|
-
fail_count = len(
|
119
|
-
list(filter(lambda x: x.status == testStatus.FAILED.value, self.result_list)))
|
120
|
-
skipped_count = len(
|
121
|
-
list(filter(lambda x: x.status == testStatus.SKIPPED.value, self.result_list)))
|
122
|
-
else:
|
123
|
-
for test_results in self.result_list:
|
124
|
-
sub_count, sub_success_count, sub_fail_count, sub_skipped_count = test_results.compute_stats()
|
125
|
-
count += sub_count
|
126
|
-
success_count += sub_success_count
|
127
|
-
fail_count += sub_fail_count
|
128
|
-
skipped_count += sub_skipped_count
|
129
|
-
|
130
|
-
self.stats = Stats(count, success_count, fail_count, skipped_count)
|
131
|
-
return count, success_count, fail_count, skipped_count
|
132
|
-
|
133
|
-
def render(self):
|
134
|
-
environment = Environment(loader=FileSystemLoader(TEMPLATE_FOLDER))
|
135
|
-
template = RESULT_LIST_LEAF_MD_TEMPLATE if self.is_leaf else RESULT_LIST_MD_TEMPLATE
|
136
|
-
return environment.get_template(template).render(result_list=self.result_list, environment=environment)
|
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 Union
|
26
|
+
from itertools import groupby
|
27
|
+
from jinja2 import Environment, FileSystemLoader
|
28
|
+
from dataclasses import dataclass
|
29
|
+
from enum import Enum
|
30
|
+
from pathlib import Path
|
31
|
+
import os
|
32
|
+
from mustrd.utils import get_mustrd_root
|
33
|
+
|
34
|
+
|
35
|
+
class testType(Enum):
|
36
|
+
MUSTRD = "Mustrd"
|
37
|
+
PYTEST = "Pytest"
|
38
|
+
|
39
|
+
|
40
|
+
class testStatus(Enum):
|
41
|
+
PASSED = "passed"
|
42
|
+
FAILED = "failed"
|
43
|
+
SKIPPED = "skipped"
|
44
|
+
|
45
|
+
|
46
|
+
TEMPLATE_FOLDER = Path(os.path.join(get_mustrd_root(), "templates/"))
|
47
|
+
|
48
|
+
|
49
|
+
RESULT_LIST_MD_TEMPLATE = "md_ResultList_template.jinja"
|
50
|
+
RESULT_LIST_LEAF_MD_TEMPLATE = "md_ResultList_leaf_template.jinja"
|
51
|
+
|
52
|
+
|
53
|
+
@dataclass
|
54
|
+
class TestResult:
|
55
|
+
test_name: str
|
56
|
+
class_name: str
|
57
|
+
module_name: str
|
58
|
+
status: str
|
59
|
+
is_mustrd: bool
|
60
|
+
type: str
|
61
|
+
|
62
|
+
def __init__(self, test_name: str, class_name: str, module_name: str, status: str, is_mustrd: bool):
|
63
|
+
self.test_name = test_name
|
64
|
+
self.class_name = class_name
|
65
|
+
self.module_name = module_name
|
66
|
+
self.status = status
|
67
|
+
self.is_mustrd = is_mustrd
|
68
|
+
self.type = testType.MUSTRD.value if self.is_mustrd else testType.PYTEST.value
|
69
|
+
|
70
|
+
|
71
|
+
@dataclass
|
72
|
+
class Stats:
|
73
|
+
count: int
|
74
|
+
success_count: int
|
75
|
+
fail_count: int
|
76
|
+
skipped_count: int
|
77
|
+
|
78
|
+
def __init__(self, count: int, success_count: int, fail_count: int, skipped_count: int):
|
79
|
+
self.count = count
|
80
|
+
self.success_count = success_count
|
81
|
+
self.fail_count = fail_count
|
82
|
+
self.skipped_count = skipped_count
|
83
|
+
|
84
|
+
|
85
|
+
def get_result_list(test_results: list[TestResult], *group_functions):
|
86
|
+
if len(group_functions) > 0:
|
87
|
+
return list(map(lambda key_group:
|
88
|
+
ResultList(key_group[0],
|
89
|
+
get_result_list(key_group[1],
|
90
|
+
*group_functions[1:]),
|
91
|
+
len(group_functions) == 1),
|
92
|
+
groupby(sorted(test_results, key=group_functions[0]), group_functions[0])))
|
93
|
+
else:
|
94
|
+
return list(test_results)
|
95
|
+
|
96
|
+
|
97
|
+
@dataclass
|
98
|
+
class ResultList:
|
99
|
+
name: str
|
100
|
+
stats: Stats
|
101
|
+
is_leaf: bool
|
102
|
+
# string type to workaround recursive call
|
103
|
+
result_list: Union[list['ResultList'], list[TestResult]]
|
104
|
+
|
105
|
+
def __init__(self, name: str, result_list: Union[list['ResultList'], list[TestResult]], is_leaf: bool = False):
|
106
|
+
self.name = name
|
107
|
+
self.result_list = result_list
|
108
|
+
self.is_leaf = is_leaf
|
109
|
+
self.compute_stats()
|
110
|
+
|
111
|
+
def compute_stats(self):
|
112
|
+
count, success_count, fail_count, skipped_count = 0, 0, 0, 0
|
113
|
+
|
114
|
+
if self.is_leaf:
|
115
|
+
count = len(self.result_list)
|
116
|
+
success_count = len(
|
117
|
+
list(filter(lambda x: x.status == testStatus.PASSED.value, self.result_list)))
|
118
|
+
fail_count = len(
|
119
|
+
list(filter(lambda x: x.status == testStatus.FAILED.value, self.result_list)))
|
120
|
+
skipped_count = len(
|
121
|
+
list(filter(lambda x: x.status == testStatus.SKIPPED.value, self.result_list)))
|
122
|
+
else:
|
123
|
+
for test_results in self.result_list:
|
124
|
+
sub_count, sub_success_count, sub_fail_count, sub_skipped_count = test_results.compute_stats()
|
125
|
+
count += sub_count
|
126
|
+
success_count += sub_success_count
|
127
|
+
fail_count += sub_fail_count
|
128
|
+
skipped_count += sub_skipped_count
|
129
|
+
|
130
|
+
self.stats = Stats(count, success_count, fail_count, skipped_count)
|
131
|
+
return count, success_count, fail_count, skipped_count
|
132
|
+
|
133
|
+
def render(self):
|
134
|
+
environment = Environment(loader=FileSystemLoader(TEMPLATE_FOLDER))
|
135
|
+
template = RESULT_LIST_LEAF_MD_TEMPLATE if self.is_leaf else RESULT_LIST_MD_TEMPLATE
|
136
|
+
return environment.get_template(template).render(result_list=self.result_list, environment=environment)
|
@@ -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()
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
-
<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
|
3
|
-
<uri id="User Entered Import Resolution" name="https://mustrd.com/triplestore/" uri="triplestoreOntology.ttl"/>
|
4
|
-
<group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base=""/>
|
5
|
-
</catalog>
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
2
|
+
<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
|
3
|
+
<uri id="User Entered Import Resolution" name="https://mustrd.com/triplestore/" uri="triplestoreOntology.ttl"/>
|
4
|
+
<group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base=""/>
|
5
|
+
</catalog>
|