core[patch[: add exceptions propagation test for astream_events v2 (#23159)

**Description:** `astream_events(version="v2")` didn't propagate
exceptions in `langchain-core<=0.2.6`, fixed in the #22916. This PR adds
a unit test to check that exceptions are propagated upwards.

Co-authored-by: Sergey Kozlov <sergey.kozlov@ludditelabs.io>
This commit is contained in:
Sergey Kozlov 2024-06-19 23:00:25 +06:00 committed by GitHub
parent 50484be330
commit 94452a94b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
import sys import sys
import uuid import uuid
from functools import partial
from itertools import cycle from itertools import cycle
from typing import ( from typing import (
Any, Any,
@ -346,6 +347,22 @@ async def test_event_stream_with_triple_lambda() -> None:
] ]
async def test_event_stream_exception() -> None:
def step(name: str, err: Optional[str], val: str) -> str:
if err:
raise ValueError(err)
return val + name[-1]
chain = (
RunnableLambda(partial(step, "step1", None))
| RunnableLambda(partial(step, "step2", "ERR"))
| RunnableLambda(partial(step, "step3", None))
)
with pytest.raises(ValueError, match="ERR"):
await _collect_events(chain.astream_events("X", version="v2"))
async def test_event_stream_with_triple_lambda_test_filtering() -> None: async def test_event_stream_with_triple_lambda_test_filtering() -> None:
"""Test filtering based on tags / names""" """Test filtering based on tags / names"""