langchain/libs/community/tests/integration_tests/retrievers/test_pubmed.py
Eugene Yurtsev 25fbe356b4
community[patch]: upgrade to recent version of mypy (#21616)
This PR upgrades community to a recent version of mypy. It inserts type:
ignore on all existing failures.
2024-05-13 14:55:07 -04:00

42 lines
1019 B
Python

"""Integration test for PubMed API Wrapper."""
from typing import List
import pytest
from langchain_core.documents import Document
from langchain_community.retrievers import PubMedRetriever
@pytest.fixture
def retriever() -> PubMedRetriever:
return PubMedRetriever() # type: ignore[call-arg]
def assert_docs(docs: List[Document]) -> None:
for doc in docs:
assert doc.metadata
assert set(doc.metadata) == {
"Copyright Information",
"uid",
"Title",
"Published",
}
def test_load_success(retriever: PubMedRetriever) -> None:
docs = retriever.invoke("chatgpt")
assert len(docs) == 3
assert_docs(docs)
def test_load_success_top_k_results(retriever: PubMedRetriever) -> None:
retriever.top_k_results = 2
docs = retriever.invoke("chatgpt")
assert len(docs) == 2
assert_docs(docs)
def test_load_no_result(retriever: PubMedRetriever) -> None:
docs = retriever.invoke("1605.08386WWW")
assert not docs