Skip to content

Commit

Permalink
Updated emmocheck to ahead to latest formulation of units
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Nov 24, 2024
1 parent 938dbb4 commit 5a7b904
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def test_description(self):
Exceptions include entities from standard w3c vocabularies.
"""
# 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 @@ -313,6 +314,10 @@ def test_unit_dimension(self):
"emmo.SIBaseUnit",
"emmo.SIUnitSymbol",
"emmo.SIUnit",
"emmo.SIDerivedUnit",
"emmo.SIAcceptedPrefixedUnit",
"emmo.SIAcceptedDerivedUnit",
"emmo.SIMetricPrefixedUnit",
)
)
if not hasattr(self.onto, "MeasurementUnit"):
Expand Down Expand Up @@ -431,6 +436,7 @@ def test_quantity_dimension(self):
"metrology.ExactConstant",
"metrology.MeasuredConstant",
"metrology.DerivedQuantity",
"metrology.PhysicalQuantiyByDefinition",
"isq.ISQBaseQuantity",
"isq.InternationalSystemOfQuantity",
"isq.ISQDerivedQuantity",
Expand Down Expand Up @@ -466,6 +472,7 @@ def test_quantity_dimension(self):
"emmo.Intensive",
"emmo.Extensive",
"emmo.Concentration",
"emmo.PhysicalQuantiyByDefinition",
)
)
if not hasattr(self.onto, "PhysicalQuantity"):
Expand Down Expand Up @@ -500,7 +507,7 @@ def test_quantity_dimension(self):
issubclass(cls, self.onto.ISQDimensionlessQuantity)
)

def test_dimensional_unit(self):
def test_dimensional_unit_rc2(self):
"""Check correct syntax of dimension string of dimensional units."""

# This test requires that the ontology has imported SIDimensionalUnit
Expand All @@ -520,6 +527,38 @@ def test_dimensional_unit(self):
self.assertIsInstance(r, owlready2.Restriction)
self.assertRegex(r.value, regex)

def test_dimensional_unit(self):
"""Check correct syntax of dimension string of dimensional units."""

# This test requires that the ontology has imported SIDimensionalUnit
if "SIDimensionalUnit" not in self.onto:
self.skipTest("SIDimensionalUnit is not imported")

# pylint: disable=invalid-name
regex = re.compile(

Check warning on line 538 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L538

Added line #L538 was not covered by tests
"^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)):
dimstr = [

Check warning on line 545 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L543-L545

Added lines #L543 - L545 were not covered by tests
r.value
for r in cls.is_a
if isinstance(r, owlready2.Restriction)
and repr(r.property) == "emmo.hasDimensionString"
]
self.assertEqual(

Check warning on line 551 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L551

Added line #L551 was not covered by tests
len(dimstr),
1,
msg="expect one emmo:hasDimensionString value restriction",
)
self.assertRegex(

Check warning on line 556 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L556

Added line #L556 was not covered by tests
dimstr[0],
regex,
msg=f"invalid dimension string: '{dimstr[0]}'",
)

def test_physical_quantity_dimension(self):
"""Check that all physical quantities have `hasPhysicalDimension`.
Expand Down Expand Up @@ -873,6 +912,7 @@ def main(
"test_physical_quantity_dimension_annotation",
"test_quantity_dimension_beta3",
"test_physical_quantity_dimension",
"test_dimensional_unit_rc2",
]
)
msg = {name: "skipped by default" for name in skipped}
Expand Down

0 comments on commit 5a7b904

Please sign in to comment.