Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated emmocheck to new EMMO quantities and units #658

Merged
merged 6 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 111 additions & 1 deletion emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
"2-manifold",
"3-manifold",
"C++",
"3DPrinting",
)
)
exceptions.update(self.get_config("test_class_label.exceptions", ()))
Expand Down Expand Up @@ -236,7 +237,7 @@
msg=cls,
)

def test_quantity_dimension(self):
def test_quantity_dimension_beta3(self):
"""Check that all quantities have a physicalDimension annotation.

Note: this test will be deprecated when isq is moved to emmo/domain.
Expand Down Expand Up @@ -310,6 +311,113 @@
physdim = anno["physicalDimension"].first()
self.assertRegex(physdim, regex, msg=cls)

def test_quantity_dimension(self):
"""Check that all quantities have a physicalDimension.

Note: this test will be deprecated when isq is moved to emmo/domain.

Configurations:
exceptions - full class names of classes to ignore.
"""
# pylint: disable=invalid-name
exceptions = set(
(
"properties.ModelledQuantitativeProperty",
"properties.MeasuredQuantitativeProperty",
"properties.ConventionalQuantitativeProperty",
"metrology.QuantitativeProperty",
"metrology.Quantity",
"metrology.OrdinalQuantity",
"metrology.BaseQuantity",
"metrology.PhysicalConstant",
"metrology.PhysicalQuantity",
"metrology.ExactConstant",
"metrology.MeasuredConstant",
"metrology.DerivedQuantity",
"isq.ISQBaseQuantity",
"isq.InternationalSystemOfQuantity",
"isq.ISQDerivedQuantity",
"isq.SIExactConstant",
"emmo.ModelledQuantitativeProperty",
"emmo.MeasuredQuantitativeProperty",
"emmo.ConventionalQuantitativeProperty",
"emmo.QuantitativeProperty",
"emmo.Quantity",
"emmo.OrdinalQuantity",
"emmo.BaseQuantity",
"emmo.PhysicalConstant",
"emmo.PhysicalQuantity",
"emmo.ExactConstant",
"emmo.MeasuredConstant",
"emmo.DerivedQuantity",
"emmo.ISQBaseQuantity",
"emmo.InternationalSystemOfQuantity",
"emmo.ISQDerivedQuantity",
"emmo.SIExactConstant",
"emmo.NonSIUnits",
"emmo.StandardizedPhysicalQuantity",
"emmo.CategorizedPhysicalQuantity",
"emmo.ISO80000Categorised",
"emmo.AtomicAndNuclear",
"emmo.Defined",
"emmo.Electromagnetic",
"emmo.FrequentlyUsed",
"emmo.ChemicalCompositionQuantity",
"emmo.EquilibriumConstant", # physical dimension may change
"emmo.Solubility",
"emmo.Universal",
"emmo.Intensive",
"emmo.Extensive",
"emmo.Concentration",
)
)
if not hasattr(self.onto, "PhysicalQuantity"):
return
exceptions.update(
self.get_config("test_quantity_dimension.exceptions", ())
)
classes = set(self.onto.classes(self.check_imported))
for cls in self.onto.PhysicalQuantity.descendants():
if not self.check_imported and cls not in classes:
continue
if issubclass(cls, self.onto.ISO80000Categorised):
continue
if repr(cls) not in exceptions:
with self.subTest(cls=cls, label=get_label(cls)):
for r in cls.get_indirect_is_a():
if isinstance(r, owlready2.Restriction) and repr(

Check warning on line 388 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L383-L388

Added lines #L383 - L388 were not covered by tests
r
).startswith("emmo.hasMeasurementUnit.some"):
self.assertTrue(

Check warning on line 391 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L391

Added line #L391 was not covered by tests
issubclass(
r.value,
(
self.onto.DimensionalUnit,
self.onto.DimensionlessUnit,
),
)
)
break

Check warning on line 400 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L400

Added line #L400 was not covered by tests
else:
self.assertTrue(

Check warning on line 402 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L402

Added line #L402 was not covered by tests
issubclass(cls, self.onto.ISQDimensionlessQuantity)
)

def test_dimensional_unit(self):
"""Check correct syntax of dimension string of dimensional units."""
# pylint: disable=invalid-name
regex = re.compile(
"^T([+-][1-9][0-9]*|0) L([+-][1-9]|0) M([+-][1-9]|0) "
"I([+-][1-9]|0) (H|Θ)([+-][1-9]|0) N([+-][1-9]|0) "
"J([+-][1-9]|0)$"
)
for cls in self.onto.SIDimensionalUnit.__subclasses__():
with self.subTest(cls=cls, label=get_label(cls)):
self.assertEqual(len(cls.equivalent_to), 1)
r = cls.equivalent_to[0]
self.assertIsInstance(r, owlready2.Restriction)
self.assertRegex(r.value, regex)

Check warning on line 419 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L415-L419

Added lines #L415 - L419 were not covered by tests

def test_physical_quantity_dimension(self):
"""Check that all physical quantities have `hasPhysicalDimension`.

Expand Down Expand Up @@ -660,6 +768,8 @@
skipped = set( # skipped by default
[
"test_namespace",
"test_physical_quantity_dimension_annotation",
"test_quantity_dimension_beta3",
"test_physical_quantity_dimension",
]
)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_emmocheck_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from emmopy.emmocheck import main


main(
argv=[
"--url-from-catalog",
# Test against a specific commit of EMMO 1.0.0-beta5
"https://raw.githubusercontent.com/emmo-repo/EMMO/3b93e2c9c45ab8d9882d2d6385276ff905095798/emmo.ttl",
]
)