Files
wehub-resource-sync da6a09ff09
Auto Bump and Release / auto-bump-and-release (push) Has been cancelled
style-check / pre-commit (push) Has been cancelled
unit-test / unit testing with python (push) Has been cancelled
unit-test / unit testing with python 3.10 (push) Has been cancelled
unit-test / unit testing with python 3.11 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:49 +08:00

165 lines
4.1 KiB
Python

import pytest
@pytest.fixture(scope="function")
def mock_google_search(monkeypatch):
import googlesearch
def result(*args, **kwargs):
yield googlesearch.SearchResult(
url="https://www.cinnamon.is/en/",
title="Cinnamon AI",
description="Cinnamon AI is an enterprise AI company.",
)
monkeypatch.setattr(googlesearch, "search", result)
@pytest.fixture(scope="function")
def mock_wikipedia(monkeypatch):
"""Avoid live Wikipedia/MediaWiki calls in unit tests."""
class _FakePage:
content = "Cinnamon AI is an enterprise AI company."
url = "https://en.wikipedia.org/wiki/Cinnamon"
def _page(_title: str) -> _FakePage:
return _FakePage()
def _search(_query: str) -> list[str]:
return ["Cinnamon"]
monkeypatch.setattr("wikipedia.page", _page)
monkeypatch.setattr("wikipedia.search", _search)
@pytest.fixture(scope="function")
def mock_langchain_search_tools(monkeypatch):
"""Stub LangChain community search tools used in agent tests."""
def _wikipedia_run(_query: str) -> str:
return "Cinnamon AI is an enterprise AI company."
def _duckduckgo_run(_query: str) -> str:
return "Cinnamon AI is an enterprise AI company."
monkeypatch.setattr(
"langchain_community.tools.wikipedia.tool.WikipediaQueryRun._run",
lambda self, query: _wikipedia_run(query),
)
monkeypatch.setattr(
"langchain_community.tools.ddg_search.tool.DuckDuckGoSearchRun._run",
lambda self, query: _duckduckgo_run(query),
)
def if_haystack_not_installed():
try:
import haystack # noqa: F401
except ImportError:
return True
else:
return False
def if_sentence_bert_not_installed():
try:
import sentence_transformers # noqa: F401
except ImportError:
return True
else:
return False
def if_sentence_fastembed_not_installed():
try:
import fastembed # noqa: F401
except ImportError:
return True
else:
return False
def if_unstructured_pdf_not_installed():
try:
import unstructured # noqa: F401
from unstructured.partition.pdf import partition_pdf # noqa: F401
except ImportError:
return True
else:
return False
def if_cohere_not_installed():
try:
import cohere # noqa: F401
except ImportError:
return True
else:
return False
def if_llama_cpp_not_installed():
try:
import llama_cpp # noqa: F401
except ImportError:
return True
else:
return False
def if_voyageai_not_installed():
try:
import voyageai # noqa: F401
except ImportError:
return True
else:
return False
def if_paddleocr_not_installed():
try:
import paddle # noqa: F401
import paddleocr # noqa: F401
except ImportError:
return True
else:
return False
skip_when_haystack_not_installed = pytest.mark.skipif(
if_haystack_not_installed(), reason="Haystack is not installed"
)
skip_when_sentence_bert_not_installed = pytest.mark.skipif(
if_sentence_bert_not_installed(), reason="SBert is not installed"
)
skip_when_fastembed_not_installed = pytest.mark.skipif(
if_sentence_fastembed_not_installed(), reason="fastembed is not installed"
)
skip_when_unstructured_pdf_not_installed = pytest.mark.skipif(
if_unstructured_pdf_not_installed(), reason="unstructured is not installed"
)
skip_when_cohere_not_installed = pytest.mark.skipif(
if_cohere_not_installed(), reason="cohere is not installed"
)
skip_openai_lc_wrapper_test = pytest.mark.skipif(
True, reason="OpenAI LC wrapper test is skipped"
)
skip_llama_cpp_not_installed = pytest.mark.skipif(
if_llama_cpp_not_installed(), reason="llama_cpp is not installed"
)
skip_when_voyageai_not_installed = pytest.mark.skipif(
if_voyageai_not_installed(), reason="voyageai is not installed"
)
skip_when_paddleocr_not_installed = pytest.mark.skipif(
if_paddleocr_not_installed(), reason="paddle/paddleocr is not installed"
)