Skip to content

Commit

Permalink
multiple: rely on asyncio_mode auto in tests (#27200)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Oct 15, 2024
1 parent 0a3e089 commit 92ae61b
Show file tree
Hide file tree
Showing 32 changed files with 78 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from typing import Any, cast

import pytest
from langchain_core.callbacks import CallbackManager
from langchain_core.messages import (
AIMessage,
Expand Down Expand Up @@ -201,15 +200,13 @@ 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")])
assert isinstance(res, BaseMessage)
assert res.content != ""


@pytest.mark.asyncio
async def test_async_generate() -> None:
"""Tests chat agenerate works."""
chat = QianfanChatEndpoint() # type: ignore[call-arg]
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pytest
from langchain.retrievers.contextual_compression import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import EmbeddingsFilter

Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 0 additions & 4 deletions libs/community/tests/integration_tests/storage/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand All @@ -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

Expand All @@ -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"],
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


@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",
Expand Down
1 change: 0 additions & 1 deletion libs/community/tests/unit_tests/llms/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions libs/community/tests/unit_tests/retrievers/test_you.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import AsyncMock, patch

import pytest
import responses

from langchain_community.retrievers.you import YouRetriever
Expand Down Expand Up @@ -63,7 +62,6 @@ def test_invoke_news(self) -> None:
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")

Expand Down
2 changes: 0 additions & 2 deletions libs/community/tests/unit_tests/tools/test_you.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import AsyncMock, patch

import pytest
import responses

from langchain_community.tools.you import YouSearchTool
Expand Down Expand Up @@ -68,7 +67,6 @@ def test_invoke_news(self) -> None:
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]

Expand Down
4 changes: 0 additions & 4 deletions libs/community/tests/unit_tests/utilities/test_you.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")

Expand All @@ -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")

Expand All @@ -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")

Expand Down
42 changes: 29 additions & 13 deletions libs/core/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = [ "poetry-core>=1.0.0",]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
Expand All @@ -12,10 +12,16 @@ readme = "README.md"
repository = "https://github.com/langchain-ai/langchain"

[tool.mypy]
exclude = [ "notebooks", "examples", "example_data", "langchain_core/pydantic", "tests/unit_tests/utils/test_function_calling.py",]
exclude = [
"notebooks",
"examples",
"example_data",
"langchain_core/pydantic",
"tests/unit_tests/utils/test_function_calling.py",
]
disallow_untyped_defs = "True"
[[tool.mypy.overrides]]
module = [ "numpy", "pytest",]
module = ["numpy", "pytest"]
ignore_missing_imports = true

[tool.ruff]
Expand Down Expand Up @@ -73,22 +79,27 @@ select = [
"TID",
"UP",
"W",
"YTT"
"YTT",
]
ignore = [
"COM812", # Messes with the formatter
"UP007", # Incompatible with pydantic + Python 3.9
"W293", #
"UP007", # Incompatible with pydantic + Python 3.9
"W293", #
]

[tool.coverage.run]
omit = [ "tests/*",]
omit = ["tests/*"]

[tool.pytest.ini_options]
addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5"
markers = [ "requires: mark tests as requiring a specific library", "asyncio: mark tests as requiring asyncio", "compile: mark placeholder test used to compile integration tests without running them",]
markers = [
"requires: mark tests as requiring a specific library",
"compile: mark placeholder test used to compile integration tests without running them",
]
asyncio_mode = "auto"
filterwarnings = [ "ignore::langchain_core._api.beta_decorator.LangChainBetaWarning",]
filterwarnings = [
"ignore::langchain_core._api.beta_decorator.LangChainBetaWarning",
]

[tool.poetry.group.lint]
optional = true
Expand All @@ -106,12 +117,17 @@ optional = true
optional = true

[tool.ruff.lint.pep8-naming]
classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]
classmethod-decorators = [
"classmethod",
"langchain_core.utils.pydantic.pre_init",
"pydantic.field_validator",
"pydantic.v1.root_validator",
]

[tool.ruff.lint.per-file-ignores]
"tests/unit_tests/prompts/test_chat.py" = [ "E501",]
"tests/unit_tests/runnables/test_runnable.py" = [ "E501",]
"tests/unit_tests/runnables/test_graph.py" = [ "E501",]
"tests/unit_tests/prompts/test_chat.py" = ["E501"]
"tests/unit_tests/runnables/test_runnable.py" = ["E501"]
"tests/unit_tests/runnables/test_graph.py" = ["E501"]

[tool.poetry.group.lint.dependencies]
ruff = "^0.5"
Expand Down
2 changes: 0 additions & 2 deletions libs/core/tests/unit_tests/_api/test_beta_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def test_beta_function() -> None:
assert not inspect.iscoroutinefunction(beta_function)


@pytest.mark.asyncio
async def test_beta_async_function() -> None:
"""Test beta async function."""
with warnings.catch_warnings(record=True) as warning_list:
Expand Down Expand Up @@ -159,7 +158,6 @@ def test_beta_method() -> None:
assert not inspect.iscoroutinefunction(obj.beta_method)


@pytest.mark.asyncio
async def test_beta_async_method() -> None:
"""Test beta method."""
with warnings.catch_warnings(record=True) as warning_list:
Expand Down
Loading

0 comments on commit 92ae61b

Please sign in to comment.