Home / Function/ test_runnable_branch_stream_with_callbacks() — langchain Function Reference

test_runnable_branch_stream_with_callbacks() — langchain Function Reference

Architecture documentation for the test_runnable_branch_stream_with_callbacks() function in test_runnable.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  ce37989c_5066_128b_a8ce_ca2b9a256766["test_runnable_branch_stream_with_callbacks()"]
  26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"]
  ce37989c_5066_128b_a8ce_ca2b9a256766 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5
  style ce37989c_5066_128b_a8ce_ca2b9a256766 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 4684–4722

def test_runnable_branch_stream_with_callbacks() -> None:
    """Verify that stream works for RunnableBranch when using callbacks."""
    tracer = FakeTracer()

    def raise_value_error(x: str) -> Any:
        """Raise a value error."""
        msg = f"x is {x}"
        raise ValueError(msg)

    llm_res = "i'm a textbot"
    # sleep to better simulate a real stream
    llm = FakeStreamingListLLM(responses=[llm_res], sleep=0.01)

    branch = RunnableBranch[str, Any](
        (lambda x: x == "error", raise_value_error),
        (lambda x: x == "hello", llm),
        lambda x: x,
    )
    config: RunnableConfig = {"callbacks": [tracer]}

    assert list(branch.stream("hello", config=config)) == list(llm_res)

    assert len(tracer.runs) == 1
    assert tracer.runs[0].error is None
    assert tracer.runs[0].outputs == {"output": llm_res}

    # Verify that the chain on error is invoked
    with pytest.raises(ValueError, match="x is error"):
        _ = list(branch.stream("error", config=config))

    assert len(tracer.runs) == 2
    assert "ValueError('x is error')" in str(tracer.runs[1].error)
    assert not tracer.runs[1].outputs

    assert list(branch.stream("bye", config=config)) == ["bye"]

    assert len(tracer.runs) == 3
    assert tracer.runs[2].error is None
    assert tracer.runs[2].outputs == {"output": "bye"}

Domain

Subdomains

Frequently Asked Questions

What does test_runnable_branch_stream_with_callbacks() do?
test_runnable_branch_stream_with_callbacks() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_runnable_branch_stream_with_callbacks() defined?
test_runnable_branch_stream_with_callbacks() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 4684.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free