test_runnable_branch_invoke_call_counts() — langchain Function Reference
Architecture documentation for the test_runnable_branch_invoke_call_counts() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 38d73f31_4fab_d6b5_9f26_47973d8974fc["test_runnable_branch_invoke_call_counts()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] 38d73f31_4fab_d6b5_9f26_47973d8974fc -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 fb618d44_c03b_ea8b_385b_2278dfb173d4["invoke()"] 38d73f31_4fab_d6b5_9f26_47973d8974fc -->|calls| fb618d44_c03b_ea8b_385b_2278dfb173d4 style 38d73f31_4fab_d6b5_9f26_47973d8974fc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 4511–4536
def test_runnable_branch_invoke_call_counts(mocker: MockerFixture) -> None:
"""Verify that runnables are invoked only when necessary."""
# Test with single branch
add = RunnableLambda[int, int](lambda x: x + 1)
sub = RunnableLambda[int, int](lambda x: x - 1)
condition = RunnableLambda[int, bool](lambda x: x > 0)
spy = mocker.spy(condition, "invoke")
add_spy = mocker.spy(add, "invoke")
branch = RunnableBranch[int, int]((condition, add), (condition, add), sub)
assert spy.call_count == 0
assert add_spy.call_count == 0
assert branch.invoke(1) == 2
assert add_spy.call_count == 1
assert spy.call_count == 1
assert branch.invoke(2) == 3
assert spy.call_count == 2
assert add_spy.call_count == 2
assert branch.invoke(-3) == -4
# Should fall through to default branch with condition being evaluated twice!
assert spy.call_count == 4
# Add should not be invoked
assert add_spy.call_count == 2
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_runnable_branch_invoke_call_counts() do?
test_runnable_branch_invoke_call_counts() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_runnable_branch_invoke_call_counts() defined?
test_runnable_branch_invoke_call_counts() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 4511.
What does test_runnable_branch_invoke_call_counts() call?
test_runnable_branch_invoke_call_counts() calls 1 function(s): invoke.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free