Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cbornet committed Jan 13, 2025
1 parent a57e446 commit 82ce644
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
8 changes: 4 additions & 4 deletions libs/core/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libs/core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 9 additions & 2 deletions libs/core/tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
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"]:
bb.functions[func].can_block_in(
"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


Expand Down
Original file line number Diff line number Diff line change
@@ -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."""

Expand Down
4 changes: 1 addition & 3 deletions libs/core/tests/unit_tests/runnables/test_fallbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion libs/core/tests/unit_tests/tracers/test_memory_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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
Expand Down

0 comments on commit 82ce644

Please sign in to comment.