test_with_listeners() — langchain Function Reference
Architecture documentation for the test_with_listeners() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 726d1e44_659b_e411_088b_3b34eb2faba1["test_with_listeners()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] 726d1e44_659b_e411_088b_3b34eb2faba1 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 a3895c50_dab4_0c36_2d24_f63121e198a0["invoke()"] 726d1e44_659b_e411_088b_3b34eb2faba1 -->|calls| a3895c50_dab4_0c36_2d24_f63121e198a0 style 726d1e44_659b_e411_088b_3b34eb2faba1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 1639–1669
def test_with_listeners(mocker: MockerFixture) -> None:
prompt = (
SystemMessagePromptTemplate.from_template("You are a nice assistant.")
+ "{question}"
)
chat = FakeListChatModel(responses=["foo"])
chain = prompt | chat
mock_start = mocker.Mock()
mock_end = mocker.Mock()
chain.with_listeners(on_start=mock_start, on_end=mock_end).invoke(
{"question": "Who are you?"}
)
assert mock_start.call_count == 1
assert mock_start.call_args[0][0].name == "RunnableSequence"
assert mock_end.call_count == 1
mock_start.reset_mock()
mock_end.reset_mock()
with trace_as_chain_group("hello") as manager:
chain.with_listeners(on_start=mock_start, on_end=mock_end).invoke(
{"question": "Who are you?"}, {"callbacks": manager}
)
assert mock_start.call_count == 1
assert mock_start.call_args[0][0].name == "RunnableSequence"
assert mock_end.call_count == 1
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does test_with_listeners() do?
test_with_listeners() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_with_listeners() defined?
test_with_listeners() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 1639.
What does test_with_listeners() call?
test_with_listeners() 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