Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Feb 5, 2024
1 parent e8ef578 commit a2fa7a6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions gilda/tests/test_grounder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from gilda.term import Term
from gilda.grounder import Grounder, filter_for_organism
import pytest
from . import appreq


Expand Down Expand Up @@ -237,3 +238,42 @@ def test_sqlite():
def test_strip_whitespace():
matches = gr.ground(' inflammatory response ')
assert matches


def test_instantiate():
"""Test instantiating the grounder with different data structures."""
term = Term(
"mitochondria",
"Mitochondria",
"GO",
"GO:0005739",
"mitochondrion",
"synonym",
"mesh",
None,
"MESH",
"D008928",
)

# test instantiating with list
gr = Grounder([term])
assert len(gr.ground("mitochondria")) == 1

# test instantiating with set
gr = Grounder({term})
assert len(gr.ground("mitochondria")) == 1

# test instantiating with tuple
gr = Grounder((term,))
assert len(gr.ground("mitochondria")) == 1

# test instantiating with iterable
gr = Grounder(iter([term]))
assert len(gr.ground("mitochondria")) == 1

# test instantiating with dict
gr = Grounder({term.norm_text: [term]})
assert len(gr.ground("mitochondria")) == 1

with pytest.raises(TypeError):
Grounder(5)

0 comments on commit a2fa7a6

Please sign in to comment.