Skip to content

Commit

Permalink
Update test_struct.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Nov 20, 2024
1 parent b2de990 commit 8b29ec1
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion tests/test_struct.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Tests for the OBO data structures."""

import unittest
from collections.abc import Iterable
from textwrap import dedent

from pyobo import Obo, Reference
from pyobo.struct.struct import BioregistryError, SynonymTypeDef
from pyobo.struct.struct import BioregistryError, SynonymTypeDef, Term, TypeDef


class Nope(Obo):
Expand Down Expand Up @@ -66,3 +68,56 @@ def test_synonym_typedef(self) -> None:

s4 = SynonymTypeDef(reference=r2, specificity="EXACT")
self.assertEqual("synonymtypedef: OMO:0003012 EXACT", s4.to_obo())

def assert_lines(self, text: str, lines: Iterable[str]) -> None:
"""Assert the lines are equal."""
self.assertEqual(dedent(text).strip(), "\n".join(lines).strip())

def test_term(self):
"""Test emitting properties."""
term = Term(
reference=Reference(prefix="GO", identifier="0050069", name="lysine dehydrogenase activity"),
)
self.assert_lines(
"""\
[Term]
id: GO:0050069
name: lysine dehydrogenase activity
""",
term.iterate_obo_lines(ontology="GO", typedefs={})
)

term = Term(
reference=Reference(prefix="GO", identifier="0050069", name="lysine dehydrogenase activity"),
properties={
"key": ["value"],
}
)
self.assert_lines(
"""\
[Term]
id: GO:0050069
name: lysine dehydrogenase activity
property_value: key "value" xsd:string
""",
term.iterate_obo_lines(ontology="GO", typedefs={})
)

typedef = TypeDef(
reference=Reference.from_curie("RO:1234567")
)
term = Term(
reference=Reference(prefix="GO", identifier="0050069", name="lysine dehydrogenase activity"),
relationships={
typedef: [Reference.from_curie("EC:1.1.1.1")],
}
)
self.assert_lines(
"""\
[Term]
id: GO:0050069
name: lysine dehydrogenase activity
relationship: RO:1234567 eccode:1.1.1.1
""",
term.iterate_obo_lines(ontology="GO", typedefs={typedef.pair: typedef})
)

0 comments on commit 8b29ec1

Please sign in to comment.