Skip to content

Commit

Permalink
Added configuration to skip modules
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Feb 3, 2025
1 parent 99e8ada commit ed28f35
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
29 changes: 27 additions & 2 deletions docs/tools-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,40 @@ optional arguments:
```
<!-- (Missing example with local and path) -->

### Example configuration file

Example of YAML configuration file provided with the `--configfile` option that will omit `myunits.MyUnitCategory1` and `myunits.MyUnitCategory1` from the *unit dimensions test*.
### Configuration file
The `--configfile` options expects a YAML configuration file that specifies what tests to skip or enable.

The following keywords are recognised in the YAML file:

- `skip`: List of tests to skip
- `enable`: List of tests to enable
- `<test_name>`: A name of a test. Recognised nested keywords are:
- `exceptions`: List of entities in the ontology to skip. Should be written
as `<ns0>.<name>`, where `<ns0>` is the last component of the base IRI
and `<name>` is the name of the entity.
- `skipmodules`: List of module names to skip the test for. The module
names may be written either as the full module IRI or as the last
component of the module IRI.

Example configuration file:

```console
test_description:
skipmodules:
- manufacturing
- conformityassessment

test_unit_dimensions:
exceptions:
- myunits.MyUnitCategory1
- myunits.MyUnitCategory2

skip:
- name_of_test_to_skip

enable:
- name_of_test_to_enable
```

---
Expand Down
49 changes: 48 additions & 1 deletion emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@
A YAML file can be provided with additional test configurations.
Toplevel keywords in the YAML file:
- `skip`: List of tests to skip
- `enable`: List of tests to enable
- `<test_name>`: A name of a test. Recognised nested keywords are:
- `exceptions`: List of entities in the ontology to skip. Should be written
as `<ns0>.<name>`, where `<ns0>` is the last component of the base IRI
and `<name>` is the name of the entity.
- `skipmodules`: List of module names to skip the test for. The module
names may be written either as the full module IRI or as the last
component of the module IRI.
Example configuration file:
test_description:
skipmodules:
- manufacturing
- conformityassessment
test_unit_dimensions:
exceptions:
- myunits.MyUnitCategory1
Expand Down Expand Up @@ -195,12 +212,12 @@ def test_description(self):
Exceptions include entities from standard w3c vocabularies.
"""
# pylint: disable=invalid-name
MeasurementUnit = (
self.onto.MeasurementUnit
if "MeasurementUnit" in self.onto
else None
)
# pylint: disable=invalid-name
exceptions = set()
exceptions.update(self.get_config("test_description.exceptions", ()))
props = self.onto.world._props # pylint: disable=protected-access
Expand Down Expand Up @@ -234,6 +251,10 @@ def test_description(self):
):
continue

Check warning on line 252 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L252

Added line #L252 was not covered by tests

# Check skipmodules
if skipmodule(self, "test_description", entity):
continue

Check warning on line 256 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L255-L256

Added lines #L255 - L256 were not covered by tests

label = str(get_label(entity))
with self.subTest(entity=entity, label=label):
self.assertTrue(
Expand Down Expand Up @@ -797,6 +818,32 @@ def checker(onto, ignore_namespace):
checker(self.onto, self.ignore_namespace)


def skipmodule(testobj, testname, entity):
"""Return true if `entity` is in a module that should be skipped."""
skipmodules = testobj.get_config(f"{testname}.skipmodules")

Check warning on line 823 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L823

Added line #L823 was not covered by tests

if not skipmodules:
return False

Check warning on line 826 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L825-L826

Added lines #L825 - L826 were not covered by tests

# Infer base iri
if entity.namespace.ontology.base_iri != "https://w3id.org/emmo#":
base_iri = entity.namespace.ontology.base_iri.rstrip("/#")
elif hasattr(entity, "isDefinedBy") and entity.isDefinedBy:
base_iri = entity.isDefinedBy.first().rstrip("/#")

Check warning on line 832 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L829-L832

Added lines #L829 - L832 were not covered by tests
else:
base_iri = entity.namespace.ontology.base_iri.rstrip("/#")

Check warning on line 834 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L834

Added line #L834 was not covered by tests

for module in skipmodules:
module = module.rstrip("/#")
if "/" in module:
if module == base_iri:
return True
elif module == base_iri.rsplit("/", 1)[-1]:
return True

Check warning on line 842 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L836-L842

Added lines #L836 - L842 were not covered by tests

return False

Check warning on line 844 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L844

Added line #L844 was not covered by tests


def main(
argv: list = None,
): # pylint: disable=too-many-locals,too-many-branches,too-many-statements
Expand Down

0 comments on commit ed28f35

Please sign in to comment.