Home / Function/ test_runnable_branch_ainvoke() — langchain Function Reference

test_runnable_branch_ainvoke() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 4574–4599

async def test_runnable_branch_ainvoke() -> None:
    """Test async variant of invoke."""
    branch = RunnableBranch[int, int](
        (lambda x: x > 0 and x < 5, lambda x: x + 1),
        (lambda x: x > 5, lambda x: x * 10),
        lambda x: x - 1,
    )

    assert await branch.ainvoke(1) == 2
    assert await branch.ainvoke(10) == 100
    assert await branch.ainvoke(0) == -1

    # Verify that the async variant is used if available
    async def condition(x: int) -> bool:
        return x > 0

    async def add(x: int) -> int:
        return x + 1

    async def sub(x: int) -> int:
        return x - 1

    branch = RunnableBranch[int, int]((condition, add), sub)

    assert await branch.ainvoke(1) == 2
    assert await branch.ainvoke(-10) == -11

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free