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>
pull/23057/head
Sergey Kozlov 2 months ago committed by GitHub
parent 50484be330
commit 94452a94b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,6 +2,7 @@
import asyncio
import sys
import uuid
from functools import partial
from itertools import cycle
from typing import (
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:
"""Test filtering based on tags / names"""

Loading…
Cancel
Save