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 ahead to latest formulation of units #809

Merged
merged 19 commits into from
Feb 4, 2025
Merged
Changes from 3 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
5a7b904
Updated emmocheck to ahead to latest formulation of units
jesper-friis Nov 24, 2024
850ad3d
Also ignore emmo.CGSUnit when checking unit dimension
jesper-friis Nov 24, 2024
692533a
Merge branch 'master' into update-emmocheck2
francescalb Dec 4, 2024
a7fe590
Merge branch 'master' into update-emmocheck2
jesper-friis Dec 4, 2024
f30a66b
Merge branch 'master' into update-emmocheck2
jesper-friis Dec 4, 2024
64d5073
Merge branch 'master' into update-emmocheck2
jesper-friis Dec 10, 2024
8fcc5d8
Fixing two new pylint issues
jesper-friis Dec 10, 2024
91794d5
Added some exceptions for EMMO unit dimension classes
jesper-friis Dec 12, 2024
5c642a9
Merge branch 'master' into update-emmocheck2
jesper-friis Dec 12, 2024
d314b2a
Merge branch 'emmocheck-unit-dimension' into update-emmocheck2
jesper-friis Dec 12, 2024
8ea482c
Also ignore CGSUnit
jesper-friis Dec 12, 2024
9ea1c8f
Merge branch 'master' into update-emmocheck2
jesper-friis Feb 2, 2025
9560af8
Removed Python 3.7 from CI Tests, but added Python 3.12 and 3.13 instead
jesper-friis Feb 2, 2025
eeff32b
Merge branch 'update-emmocheck2' of github.com:emmo-repo/EMMO-python …
jesper-friis Feb 2, 2025
f13883e
Removed test for Python 3.13
jesper-friis Feb 2, 2025
06463a4
Removed Python 3.7 and added Python 3.12 to setup.py
jesper-friis Feb 2, 2025
983c116
Allow missing elucidation for unit subclasses with a physical dimension
jesper-friis Feb 2, 2025
99e8ada
Trying to fix failing test
jesper-friis Feb 3, 2025
ed28f35
Added configuration to skip modules
jesper-friis Feb 3, 2025
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
43 changes: 42 additions & 1 deletion emmopy/emmocheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
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,11 @@
"emmo.SIBaseUnit",
"emmo.SIUnitSymbol",
"emmo.SIUnit",
"emmo.SIDerivedUnit",
"emmo.SIAcceptedPrefixedUnit",
"emmo.SIAcceptedDerivedUnit",
"emmo.SIMetricPrefixedUnit",
"emmo.CGSUnit",
)
)
if not hasattr(self.onto, "MeasurementUnit"):
Expand Down Expand Up @@ -431,6 +437,7 @@
"metrology.ExactConstant",
"metrology.MeasuredConstant",
"metrology.DerivedQuantity",
"metrology.PhysicalQuantiyByDefinition",
"isq.ISQBaseQuantity",
"isq.InternationalSystemOfQuantity",
"isq.ISQDerivedQuantity",
Expand Down Expand Up @@ -466,6 +473,7 @@
"emmo.Intensive",
"emmo.Extensive",
"emmo.Concentration",
"emmo.PhysicalQuantiyByDefinition",
)
)
if not hasattr(self.onto, "PhysicalQuantity"):
Expand Down Expand Up @@ -500,7 +508,7 @@
issubclass(cls, self.onto.ISQDimensionlessQuantity)
)

def test_dimensional_unit(self):
def test_dimensional_unit_rc2(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have two tests? Shuold we not just stick to one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because EMMO changed since 1.0.0-rc2.

test_dimensional_unit() works for current version of EMMO.
test_dimensional_unit_rc2() works for previous version of EMMO.

Copy link
Collaborator Author

@jesper-friis jesper-friis Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The common way for software to handle changes in their dependencies is to keep the latest version in sync with the latest version of the dependencies. That is why test_dimensional_unit() is updated to the latest version of EMMO. In addition we kept a renamed copy of the test that works with EMMO up to 1.0.0-rc2.

To make the latest version of EMMOntoPy handle multiple versions of EMMO, it is not sufficient to rename the tests differently, we need a whole new formalisation to (preferably in a declarative way) specify what versions of EMMO each test is valid for. I added issue #821 for that.

"""Check correct syntax of dimension string of dimensional units."""

# This test requires that the ontology has imported SIDimensionalUnit
Expand All @@ -520,6 +528,38 @@
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 539 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L539

Added line #L539 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 546 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L544-L546

Added lines #L544 - L546 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 552 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L552

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

Check warning on line 557 in emmopy/emmocheck.py

View check run for this annotation

Codecov / codecov/patch

emmopy/emmocheck.py#L557

Added line #L557 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 +913,7 @@
"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
Loading