test_with_listeners_async() — langchain Function Reference
Architecture documentation for the test_with_listeners_async() function in test_runnable.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD baec881b_7c5b_52db_af3b_503bec369919["test_with_listeners_async()"] 26df6ad8_0189_51d0_c3c1_6c3248893ff5["test_runnable.py"] baec881b_7c5b_52db_af3b_503bec369919 -->|defined in| 26df6ad8_0189_51d0_c3c1_6c3248893ff5 style baec881b_7c5b_52db_af3b_503bec369919 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/runnables/test_runnable.py lines 1672–1702
async def test_with_listeners_async(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()
await chain.with_listeners(on_start=mock_start, on_end=mock_end).ainvoke(
{"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()
async with atrace_as_chain_group("hello") as manager:
await chain.with_listeners(on_start=mock_start, on_end=mock_end).ainvoke(
{"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
Source
Frequently Asked Questions
What does test_with_listeners_async() do?
test_with_listeners_async() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_with_listeners_async() defined?
test_with_listeners_async() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 1672.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free