multiple: rely on asyncio_mode auto in tests (#27200)

This commit is contained in:
Erick Friis
2024-10-15 09:26:38 -07:00
committed by GitHub
parent 0a3e089827
commit 92ae61bcc8
32 changed files with 78 additions and 91 deletions

View File

@@ -266,7 +266,6 @@ def test_litellm_router_streaming_callback(
fake_completion.check_inputs(expected_num_calls=1)
@pytest.mark.asyncio
@pytest.mark.scheduled
async def test_async_litellm_router(
fake_completion: FakeCompletion, litellm_router: Any
@@ -295,7 +294,6 @@ async def test_async_litellm_router(
fake_completion.check_inputs(expected_num_calls=2)
@pytest.mark.asyncio
@pytest.mark.scheduled
async def test_async_litellm_router_streaming(
fake_completion: FakeCompletion, litellm_router: Any

View File

@@ -2,7 +2,6 @@
from typing import Any, cast
import pytest
from langchain_core.callbacks import CallbackManager
from langchain_core.messages import (
AIMessage,
@@ -201,7 +200,6 @@ def test_stream() -> None:
assert len(list(res)) >= 1
@pytest.mark.asyncio
async def test_async_invoke() -> None:
chat = QianfanChatEndpoint() # type: ignore[call-arg]
res = await chat.ainvoke([HumanMessage(content="Hello")])
@@ -209,7 +207,6 @@ async def test_async_invoke() -> None:
assert res.content != ""
@pytest.mark.asyncio
async def test_async_generate() -> None:
"""Tests chat agenerate works."""
chat = QianfanChatEndpoint() # type: ignore[call-arg]
@@ -229,7 +226,6 @@ async def test_async_generate() -> None:
assert isinstance(generation.text, str)
@pytest.mark.asyncio
async def test_async_stream() -> None:
chat = QianfanChatEndpoint(streaming=True) # type: ignore[call-arg]
async for token in chat.astream(

View File

@@ -100,7 +100,6 @@ def test_chat_yuan2_streaming() -> None:
assert isinstance(response, BaseMessage)
@pytest.mark.asyncio
async def test_async_chat_yuan2() -> None:
"""Test async generation."""
chat = ChatYuan2( # type: ignore[call-arg]
@@ -124,7 +123,6 @@ async def test_async_chat_yuan2() -> None:
assert generation.text == generation.message.content
@pytest.mark.asyncio
async def test_async_chat_yuan2_streaming() -> None:
"""Test that streaming correctly invokes on_llm_new_token callback."""
callback_handler = FakeCallbackHandler()

View File

@@ -43,7 +43,6 @@ def test_update(manager: MongoDocumentManager) -> None:
assert sorted(all_keys) == sorted(read_keys + updated_keys)
@pytest.mark.asyncio
@pytest.mark.requires("motor")
async def test_aupdate(amanager: MongoDocumentManager) -> None:
"""Test updating records in the MongoDB."""

View File

@@ -150,7 +150,6 @@ def test_model_garden_generate(
assert len(output.generations) == 2
@pytest.mark.asyncio
@pytest.mark.parametrize(
"endpoint_os_variable_name,result_arg",
[("FALCON_ENDPOINT_ID", "generated_text"), ("LLAMA_ENDPOINT_ID", None)],

View File

@@ -1,4 +1,3 @@
import pytest
from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import EmbeddingsFilter
@@ -27,7 +26,6 @@ def test_contextual_compression_retriever_get_relevant_docs() -> None:
assert texts[-1] not in [d.page_content for d in actual]
@pytest.mark.asyncio
async def test_acontextual_compression_retriever_get_relevant_docs() -> None:
"""Test get_relevant_docs."""
texts = [

View File

@@ -45,7 +45,6 @@ def test_mget(sql_engine: Engine) -> None:
assert result == [b"value1", b"value2"]
@pytest.mark.asyncio
async def test_amget(sql_aengine: AsyncEngine) -> None:
"""Test mget method."""
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -85,7 +84,6 @@ def test_mset(sql_engine: Engine) -> None:
session.commit()
@pytest.mark.asyncio
async def test_amset(sql_aengine: AsyncEngine) -> None:
"""Test that multiple keys can be set."""
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -131,7 +129,6 @@ def test_mdelete(sql_engine: Engine) -> None:
session.commit()
@pytest.mark.asyncio
async def test_amdelete(sql_aengine: AsyncEngine) -> None:
"""Test that deletion works as expected."""
store = SQLStore(engine=sql_aengine, namespace="test")
@@ -172,7 +169,6 @@ def test_yield_keys(sql_engine: Engine) -> None:
assert sorted(store.yield_keys(prefix="lang")) == []
@pytest.mark.asyncio
async def test_ayield_keys(sql_aengine: AsyncEngine) -> None:
store = SQLStore(engine=sql_aengine, namespace="test")
await store.acreate_schema()

View File

@@ -68,7 +68,6 @@ def test_upstash_simple_insert() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_simple_insert_async() -> None:
"""Test end to end construction and search."""
texts = ["foo", "bar", "baz"]
@@ -94,7 +93,6 @@ def test_upstash_with_metadatas() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_with_metadatas_async() -> None:
"""Test end to end construction and search."""
texts = ["foo", "bar", "baz"]
@@ -125,7 +123,6 @@ def test_upstash_with_metadatas_with_scores() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_with_metadatas_with_scores_async() -> None:
"""Test end to end construction and scored search."""
texts = ["foo", "bar", "baz"]
@@ -159,7 +156,6 @@ def test_upstash_with_metadatas_with_scores_using_vector() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_with_metadatas_with_scores_using_vector_async() -> None:
"""Test end to end construction and scored search, using embedding vector."""
texts = ["foo", "bar", "baz"]
@@ -190,7 +186,6 @@ def test_upstash_mmr() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_mmr_async() -> None:
"""Test end to end construction and search."""
texts = ["foo", "bar", "baz"]
@@ -213,7 +208,6 @@ def test_upstash_mmr_by_vector() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_mmr_by_vector_async() -> None:
"""Test end to end construction and search."""
texts = ["foo", "bar", "baz"]
@@ -237,7 +231,6 @@ def test_init_from_index() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_init_from_async_index() -> None:
from upstash_vector import AsyncIndex
@@ -259,7 +252,6 @@ def test_init_from_credentials() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_init_from_credentials_async() -> None:
store = UpstashVectorStore(
index_url=os.environ["UPSTASH_VECTOR_REST_URL"],
@@ -326,7 +318,6 @@ def test_upstash_similarity_search_with_metadata() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_similarity_search_with_metadata_async() -> None:
store = UpstashVectorStore(embedding=FakeEmbeddings())
docs = [
@@ -384,7 +375,6 @@ def test_upstash_similarity_search_by_vector_with_metadata() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_similarity_search_by_vector_with_metadata_async() -> None:
store = UpstashVectorStore(embedding=FakeEmbeddings())
docs = [
@@ -434,7 +424,6 @@ def test_upstash_max_marginal_relevance_search_with_metadata() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_upstash_max_marginal_relevance_search_with_metadata_async() -> None:
store = UpstashVectorStore(embedding=FakeEmbeddings())
docs = [
@@ -539,7 +528,6 @@ def test_embedding_index() -> None:
@pytest.mark.vcr()
@pytest.mark.asyncio
async def test_embedding_index_async() -> None:
store = UpstashVectorStore(
index_url=os.environ["UPSTASH_VECTOR_URL_EMBEDDING"],

View File

@@ -13,7 +13,6 @@ except ImportError:
@pytest.mark.skipif(not IMPORTED_TORCH, reason="torch not installed")
@pytest.mark.asyncio
async def test_local_infinity_embeddings() -> None:
embedder = InfinityEmbeddingsLocal(
model="TaylorAI/bge-micro-v2",

View File

@@ -273,7 +273,6 @@ async def async_gen_mock_streaming_response() -> AsyncGenerator[Dict, None]:
yield item
@pytest.mark.asyncio
async def test_bedrock_async_streaming_call() -> None:
# Mock boto3 import
mock_boto3 = MagicMock()

View File

@@ -1,6 +1,5 @@
from unittest.mock import AsyncMock, patch
import pytest
import responses
from langchain_community.retrievers.you import YouRetriever
@@ -63,7 +62,6 @@ class TestYouRetriever:
expected_result = NEWS_RESPONSE_PARSED
assert results == expected_result
@pytest.mark.asyncio
async def test_ainvoke(self) -> None:
instance = YouRetriever(ydc_api_key="test_api_key")

View File

@@ -1,6 +1,5 @@
from unittest.mock import AsyncMock, patch
import pytest
import responses
from langchain_community.tools.you import YouSearchTool
@@ -68,7 +67,6 @@ class TestYouSearchTool:
expected_result = NEWS_RESPONSE_PARSED
assert results == expected_result
@pytest.mark.asyncio
async def test_ainvoke(self) -> None:
you_tool = YouSearchTool(api_wrapper=YouSearchAPIWrapper(ydc_api_key="test")) # type: ignore[call-arg]

View File

@@ -1,7 +1,6 @@
from typing import Any, Dict, List, Optional, Union
from unittest.mock import AsyncMock, patch
import pytest
import responses
from langchain_core.documents import Document
@@ -189,7 +188,6 @@ def test_results_news() -> None:
assert raw_results == expected_result
@pytest.mark.asyncio
async def test_raw_results_async() -> None:
instance = YouSearchAPIWrapper(ydc_api_key="test_api_key")
@@ -208,7 +206,6 @@ async def test_raw_results_async() -> None:
assert results == MOCK_RESPONSE_RAW
@pytest.mark.asyncio
async def test_results_async() -> None:
instance = YouSearchAPIWrapper(ydc_api_key="test_api_key")
@@ -227,7 +224,6 @@ async def test_results_async() -> None:
assert results == MOCK_PARSED_OUTPUT
@pytest.mark.asyncio
async def test_results_news_async() -> None:
instance = YouSearchAPIWrapper(endpoint_type="news", ydc_api_key="test_api_key")