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

Added fix for adding annotations that are not strings in ontodoc #512

Merged
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
1 change: 1 addition & 0 deletions ontopy/ontodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def itemdoc(
annotations.keys(), key=lambda key: order.get(key, key)
):
for value in annotations[key]:
value = str(value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could fail, I suppose, if the type of value cannot be cast to a str type.
You could instead wrap it in a try/except block, where you're catching TypeError and ValueError exceptions, re-raising them with an appropriate custom message?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I discussed this with @jesper-friis , and we can't really see a situation in which this not enough. I think it is better to leave it as is, and update this if and when we find examples of situations in which a different handling is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As you wish. Casting to str is in general quite generous in this case, so it's fine I suppose. However, I'd argue it's good convention to consider possible edge cases and try to catch them if possible so exception messages are clear and helpful.

if self.url_regex.match(value):
doc.append(
annotation_style.format(
Expand Down
2 changes: 1 addition & 1 deletion tests/ontopy_tests/test_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def test_prefix(testonto: "Ontology", emmo: "Ontology") -> None:
"""Test prefix in ontology"""

assert len(testonto.get_by_label_all("*")) == 2
assert len(testonto.get_by_label_all("*")) == 3
assert testonto.get_by_label_all("*", prefix="testonto") == [
testonto.TestClass
]
Expand Down
3 changes: 2 additions & 1 deletion tests/testonto/models.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ skos:altLabel rdf:type owl:AnnotationProperty .

:testclass rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
skos:prefLabel "TestClass"@en .
skos:prefLabel "TestClass"@en ;
skos:altLabel 25517 . # Test that values given as integers are accepted by ontodoc
4 changes: 3 additions & 1 deletion tests/tools/test_ontodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest


@pytest.mark.skip("ontodoc is tested in other ways")
@pytest.mark.parametrize("tool", ["ontodoc"], indirect=True)
def test_run(tool, tmpdir: Path) -> None:
"""Check that running `ontodoc` works."""
Expand All @@ -13,3 +12,6 @@ def test_run(tool, tmpdir: Path) -> None:
)

tool.main([str(test_file), str(tmpdir / "test.md")])
tool.main(
[str(test_file), "--format=simple-html", str(tmpdir / "test.html")]
)