customeragent-api / tests /test_parsers_only.py
anasraza526's picture
Clean deploy to Hugging Face
ac90985
import asyncio
import os
import sys
# Disable tokenizers parallelism
os.environ["TOKENIZERS_PARALLELISM"] = "false"
sys.path.append(os.path.join(os.path.dirname(__file__), '../server'))
from app.services.parsers.medical_parsers import MedQuADParser, HealthTapParser, PubMedParser, WhoParser
def create_mock_files():
base = "server/datasets/raw"
# PubMed
pm_path = os.path.join(base, "pubmedqa", "mock.json")
with open(pm_path, "w") as f:
f.write('''[{"question": "Is X effective?", "ideal_answer": "Yes, X is effective.", "documents": ["doc1"]}]''')
# WHO
who_path = os.path.join(base, "who", "mock.json")
with open(who_path, "w") as f:
f.write('''{"topic": "Flu", "qa_pairs": [{"q": "What is flu?", "a": "Influenza."}]}''')
return pm_path, who_path
def test_parsers():
print("πŸ₯ Testing EXTENDED Parsers...\n")
pm_path, who_path = create_mock_files()
# 1. PubMed
pm = PubMedParser()
res = pm.parse(pm_path)
print(f"βœ… PubMed: {res[0]}")
assert res[0]['source'] == "PubMedQA"
assert "effective" in res[0]['answer']
# 2. WHO
who = WhoParser()
res = who.parse(who_path)
print(f"βœ… WHO: {res[0]}")
assert res[0]['source'] == "WHO/CDC"
assert res[0]['context'] == "Topic: Flu"
print("\nπŸŽ‰ ALL Parsers Verified!")
if __name__ == "__main__":
test_parsers()