From 82ce644a3d41cca4546422ea0b92f76bcd055a82 Mon Sep 17 00:00:00 2001 From: Christophe Bornet Date: Mon, 13 Jan 2025 16:22:00 +0100 Subject: [PATCH] Fix tests --- libs/core/poetry.lock | 8 ++++---- libs/core/pyproject.toml | 2 +- libs/core/tests/unit_tests/conftest.py | 11 +++++++++-- .../language_models/chat_models/test_rate_limiting.py | 9 +++++++++ .../core/tests/unit_tests/runnables/test_fallbacks.py | 4 +--- .../tests/unit_tests/tracers/test_memory_stream.py | 4 +++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/libs/core/poetry.lock b/libs/core/poetry.lock index 2bdc229af92b0..d9c6ca4a8ac9f 100644 --- a/libs/core/poetry.lock +++ b/libs/core/poetry.lock @@ -222,13 +222,13 @@ css = ["tinycss2 (>=1.1.0,<1.5)"] [[package]] name = "blockbuster" -version = "1.5.8" +version = "1.5.9" description = "Utility to detect blocking calls in the async event loop" optional = false python-versions = ">=3.8" files = [ - {file = "blockbuster-1.5.8-py3-none-any.whl", hash = "sha256:ea0352823acbd837872785a96ec87701f1c7938410d66c6a8857ae11646d9744"}, - {file = "blockbuster-1.5.8.tar.gz", hash = "sha256:0018080fd735e84f0b138f15ff0a339f99444ecdc0045f16056c7b23db92706b"}, + {file = "blockbuster-1.5.9-py3-none-any.whl", hash = "sha256:1a3c43f1682866a8a9464c0850341ca72ab91c6e6a5fad1e8e1ce58590a7c98a"}, + {file = "blockbuster-1.5.9.tar.gz", hash = "sha256:72d5696425cf86a6413043c5da73b8f436b7ea442606c47cd724329ef2fa4a91"}, ] [package.dependencies] @@ -3162,4 +3162,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0" -content-hash = "356040a2decb213bfe3a35a0f79cad3c9b10e7e941d43e309ab5e41e45b40093" +content-hash = "4ade2f7e47a95220acad02edcc7a7c7237d4b726e32632c7a30a2ceb8d369d4d" diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml index a23fdc495e2d9..ffd1ab4574a71 100644 --- a/libs/core/pyproject.toml +++ b/libs/core/pyproject.toml @@ -109,7 +109,7 @@ grandalf = "^0.8" responses = "^0.25.0" pytest-socket = "^0.7.0" pytest-xdist = "^3.6.1" -blockbuster = "~1.5.8" +blockbuster = "~1.5.9" [[tool.poetry.group.test.dependencies.numpy]] version = "^1.24.0" python = "<3.12" diff --git a/libs/core/tests/unit_tests/conftest.py b/libs/core/tests/unit_tests/conftest.py index c1b8d3c43f978..f17adfa0c1e20 100644 --- a/libs/core/tests/unit_tests/conftest.py +++ b/libs/core/tests/unit_tests/conftest.py @@ -14,8 +14,10 @@ def blockbuster() -> Iterator[BlockBuster]: with blockbuster_ctx() as bb: for func in ["os.stat", "os.path.abspath"]: - bb.functions[func].can_block_in( - "langchain_core/_api/internal.py", "is_caller_internal" + ( + bb.functions[func] + .can_block_in("langchain_core/_api/internal.py", "is_caller_internal") + .can_block_in("langchain_core/runnables/base.py", "__repr__") ) for func in ["os.stat", "io.TextIOWrapper.read"]: @@ -23,6 +25,11 @@ def blockbuster() -> Iterator[BlockBuster]: "langsmith/client.py", "_default_retry_config" ) + for bb_function in bb.functions.values(): + bb_function.can_block_in( + "freezegun/api.py", "_get_cached_module_attributes" + ) + yield bb diff --git a/libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py b/libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py index 3547cc8af6b59..d0546736b288e 100644 --- a/libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py +++ b/libs/core/tests/unit_tests/language_models/chat_models/test_rate_limiting.py @@ -1,11 +1,20 @@ import time from typing import Optional as Optional +import pytest +from blockbuster import BlockBuster + from langchain_core.caches import InMemoryCache from langchain_core.language_models import GenericFakeChatModel from langchain_core.rate_limiters import InMemoryRateLimiter +@pytest.fixture(autouse=True) +def deactivate_blockbuster(blockbuster: BlockBuster) -> None: + # Deactivate BlockBuster to not disturb the rate limiter timings + blockbuster.deactivate() + + def test_rate_limit_invoke() -> None: """Add rate limiter.""" diff --git a/libs/core/tests/unit_tests/runnables/test_fallbacks.py b/libs/core/tests/unit_tests/runnables/test_fallbacks.py index 13f500d17dcbc..6dd6b6eb226c6 100644 --- a/libs/core/tests/unit_tests/runnables/test_fallbacks.py +++ b/libs/core/tests/unit_tests/runnables/test_fallbacks.py @@ -96,9 +96,7 @@ def test_fallbacks( "runnable", ["llm", "llm_multi", "chain", "chain_pass_exceptions"], ) -async def test_fallbacks_async( - runnable: RunnableWithFallbacks, request: Any, snapshot: SnapshotAssertion -) -> None: +async def test_fallbacks_async(runnable: RunnableWithFallbacks, request: Any) -> None: runnable = request.getfixturevalue(runnable) assert await runnable.ainvoke("hello") == "bar" assert await runnable.abatch(["hi", "hey", "bye"]) == ["bar"] * 3 diff --git a/libs/core/tests/unit_tests/tracers/test_memory_stream.py b/libs/core/tests/unit_tests/tracers/test_memory_stream.py index d49a619f12ff6..fd4a12e209efd 100644 --- a/libs/core/tests/unit_tests/tracers/test_memory_stream.py +++ b/libs/core/tests/unit_tests/tracers/test_memory_stream.py @@ -69,7 +69,7 @@ async def producer() -> None: """Produce items with slight delay.""" tic = time.time() for i in range(3): - await asyncio.sleep(0.10) + await asyncio.sleep(0.2) toc = time.time() await writer.send( { @@ -96,6 +96,8 @@ async def consumer() -> AsyncIterator[dict]: items = [item async for item in consumer()] await task + assert len(items) == 3 + for item in items: delta_time = item["receive_time"] - item["produce_time"] # Allow a generous 10ms of delay