From d0876ab1f89c107db906be6c82a413308cb54c19 Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 5 Apr 2026 11:58:36 +0200 Subject: Add local search test --- guix.scm | 1 + tests/test_local_xfetch.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/test_local_xfetch.py diff --git a/guix.scm b/guix.scm index a95b418..77551cd 100644 --- a/guix.scm +++ b/guix.scm @@ -12,6 +12,7 @@ ;; In a shell you can run ;; ;; python3 -m unittest tests.test_network_esearch +;; env EDIRECT_LOCAL_ARCHIVE=/export3/PubMed/Source python3 -m unittest tests.test_local_xfetch -v ;; ;; Note: API key is read from ~/.config/gemini/credentials ;; diff --git a/tests/test_local_xfetch.py b/tests/test_local_xfetch.py new file mode 100644 index 0000000..7b7bc8f --- /dev/null +++ b/tests/test_local_xfetch.py @@ -0,0 +1,38 @@ +"""Test local xsearch + xfetch against a local PubMed archive. + +Requires EDIRECT_LOCAL_ARCHIVE to point to a PubMed archive directory +(e.g. /export3/PubMed/Source) and edirect tools on PATH. + +Run with: EDIRECT_LOCAL_ARCHIVE=/export3/PubMed/Source python3 -m unittest tests.test_local_xfetch -v +""" + +import os +import subprocess +import unittest + +ARCHIVE = os.environ.get("EDIRECT_LOCAL_ARCHIVE", "/export3/PubMed/Source") + +@unittest.skipUnless(os.path.isdir(ARCHIVE), + f"EDIRECT_LOCAL_ARCHIVE not found: {ARCHIVE}") +class TestLocalXfetch(unittest.TestCase): + def test_xsearch_xfetch_penk_stress(self): + """Local xsearch + xfetch for Penk + stress, expect PMIDs.""" + env = os.environ.copy() + env["EDIRECT_LOCAL_ARCHIVE"] = ARCHIVE + result = subprocess.run( + ["sh", "-c", + 'xsearch -db pubmed -query "(stress) AND (Penk [tiab])" ' + '| xfetch -db pubmed'], + capture_output=True, text=True, timeout=120, env=env) + self.assertEqual(result.returncode, 0, result.stderr) + output = result.stdout.strip() + self.assertGreater(len(output), 0, "Expected non-empty XML output") + self.assertIn("PubmedArticle", output, + "Expected PubmedArticle XML elements") + # Count articles + count = output.count("") + print(f" Found {count} PubmedArticle records for Penk+stress (local)") + self.assertGreater(count, 10, "Expected at least 10 PubmedArticles") + +if __name__ == "__main__": + unittest.main() -- cgit 1.4.1