about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr Prins2026-04-06 04:58:31 -0500
committerPjotr Prins2026-04-06 04:58:31 -0500
commitddac775a9c58f84026f51cfcaa688bb51e70f00c (patch)
treef8862e2d10b4ab58b138905cffb6d8211adda997 /tests
parentd99396ddac97bdea89c4326e5d3a6ba70c894313 (diff)
parent0ede8df7f295604b09a574dcfa587a31483f1583 (diff)
downloadgenecup-ddac775a9c58f84026f51cfcaa688bb51e70f00c.tar.gz
Merge branch 'master' of /home/git/public/genecup
Diffstat (limited to 'tests')
-rw-r--r--tests/test_network_gemini_ontology.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_network_gemini_ontology.py b/tests/test_network_gemini_ontology.py
new file mode 100644
index 0000000..2a84909
--- /dev/null
+++ b/tests/test_network_gemini_ontology.py
@@ -0,0 +1,56 @@
+"""Test Gemini API for generating SUD ontology terms.
+
+Requires a Gemini API key in ~/.config/gemini/credentials and internet access.
+
+Run with: python3 -m unittest tests.test_network_gemini_ontology -v
+"""
+
+import os
+import sys
+import time
+import unittest
+
+sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
+from more_functions import gemini_query
+
+PROMPT = (
+    """
+    Give me a list of terms on substance abuse disorder (SUD) that act
+    as traits and classifiers in scientific literature with a focus on
+    behaviour and brain attributes related to the hippocampus. Avoid
+    aliases and synonyms as well as gene names. Each term should be
+    1-3 words (max).  Give me a list of at least 20, but no more than
+    80, most used terms.  Return only the terms, one per line, no
+    numbering. Add abbreviations and aliases as a list with each term, separated by commas"""
+)
+
+class TestGeminiOntology(unittest.TestCase):
+    def test_1_sud_ontology_terms(self):
+        """Gemini should return 20-50 SUD ontology terms."""
+        t0 = time.time()
+        response = gemini_query(PROMPT)
+        elapsed = time.time() - t0
+        terms = [t.strip() for t in response.strip().split("\n") if t.strip()]
+        print(f"  Got {len(terms)} terms ({elapsed:.2f}s)")
+        for t in terms:
+            print(f"    - {t}")
+        self.assertGreaterEqual(len(terms), 20,
+                                f"Expected at least 20 terms, got {len(terms)}")
+        self.assertLessEqual(len(terms), 80,
+                             f"Expected at most 80 terms, got {len(terms)}")
+        # Each term should be short (1-3 words, allow some slack)
+        long_terms = [t for t in terms if len(t.split()) > 5]
+
+    def test_2_cached_ontology(self):
+        """Second call should use cache and be fast."""
+        # Ensure cache is populated from test_1
+        gemini_query(PROMPT)
+        t0 = time.time()
+        response = gemini_query(PROMPT)
+        elapsed = time.time() - t0
+        terms = [t.strip() for t in response.strip().split("\n") if t.strip()]
+        print(f"  Cached: {len(terms)} terms ({elapsed:.4f}s)")
+        self.assertLess(elapsed, 0.01, f"Cache lookup too slow: {elapsed:.4f}s")
+
+if __name__ == "__main__":
+    unittest.main()