From a2fa7a650f14d96e4d3507bf319ba7410521e732 Mon Sep 17 00:00:00 2001 From: Charles Tapley Hoyt <cthoyt@gmail.com> Date: Mon, 5 Feb 2024 14:39:37 +0100 Subject: [PATCH] Add tests --- gilda/tests/test_grounder.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/gilda/tests/test_grounder.py b/gilda/tests/test_grounder.py index 6f0a536..3e0359f 100644 --- a/gilda/tests/test_grounder.py +++ b/gilda/tests/test_grounder.py @@ -1,5 +1,6 @@ from gilda.term import Term from gilda.grounder import Grounder, filter_for_organism +import pytest from . import appreq @@ -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)