Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Nov 23, 2024
1 parent 16a44c3 commit 618804a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/pyobo/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,8 @@ def _handle_prop(
datatype, strict=strict, ontology_prefix=ontology_prefix, node=node
)
if datatype_reference is None:
raise ValueError
logger.warning("[%s] had unparsable datatype %s", node.curie, prop_value_type)
return None
return LiteralProperty(prop_reference, value, datatype_reference)


Expand Down
40 changes: 29 additions & 11 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,22 @@ def test_property_literal_typed(self) -> None:
self.assertEqual("121.323", row["value"])
self.assertEqual("xsd:decimal", row["datatype"])

def test_property_bad_datatype(self) -> None:
"""Test parsing a property with an unparsable datatype."""
text = """\
ontology: chebi
[Term]
id: CHEBI:1234
property_value: mass "121.323" NOPE:NOPE
"""
with self.assertRaises(ValueError):
_read(text)
ontology = _read(text, strict=False)
term = self.get_only_term(ontology)
self.assertEqual(0, len(term.annotations_literal))
self.assertEqual(0, len(term.annotations_object))

def test_property_literal_url_questionable(self) -> None:
"""Test parsing a property with a literal object."""
ontology = _read("""\
Expand Down Expand Up @@ -342,16 +358,18 @@ def test_property_literal_url(self) -> None:

def test_property_unparsable_object(self) -> None:
"""Test when an object can't be parsed."""
ontology = _read(
"""\
text = """\
ontology: chebi
[Term]
id: CHEBI:1234
property_value: https://w3id.org/biolink/vocab/something NOPE:NOPE
""",
strict=False,
)
"""

with self.assertRaises(ValueError):
_read(text)

ontology = _read(text, strict=False)
term = self.get_only_term(ontology)
self.assertEqual(0, len(list(term.annotations_literal)))
self.assertEqual(0, len(list(term.annotations_object)))
Expand Down Expand Up @@ -384,16 +402,16 @@ def test_property_literal_object(self) -> None:
self.assertEqual("hgnc:1234", term.get_property(see_also))

def test_node_unparsable(self) -> None:
"""Test loading an ontology with unparsable nodes.."""
ontology = _read(
"""\
"""Test loading an ontology with unparsable nodes."""
text = """\
ontology: chebi
[Term]
id: nope:1234
""",
strict=False,
)
"""
with self.assertRaises(ValueError):
_read(text)
ontology = _read(text, strict=False)
self.assertEqual(0, len(list(ontology.iter_terms())))

def test_malformed_typedef(self) -> None:
Expand Down

0 comments on commit 618804a

Please sign in to comment.