Spaces:
Runtime error
Runtime error
Download libs/kotaemon/tests/conftest.py from Leodass1433/RAG-TechXfluence: direct link, hf CLI and curl.
- Browser
- Download file 4.32 kB
-
https://huggingface.co/spaces/Leodass1433/RAG-TechXfluence/resolve/main/libs/kotaemon/tests/conftest.py
- Command line
-
hf download hf://spaces/Leodass1433/RAG-TechXfluence/libs/kotaemon/tests/conftest.py
-
curl -L -o conftest.py https://huggingface.co/spaces/Leodass1433/RAG-TechXfluence/resolve/main/libs/kotaemon/tests/conftest.py
4.32 kB
| import pytest | |
| 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) | |
| 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) | |
| 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" | |
| ) | |