Home / Function/ test_with_listener_propagation() — langchain Function Reference

test_with_listener_propagation() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable.py lines 1705–1768

def test_with_listener_propagation(mocker: MockerFixture) -> None:
    prompt = (
        SystemMessagePromptTemplate.from_template("You are a nice assistant.")
        + "{question}"
    )
    chat = FakeListChatModel(responses=["foo"])
    chain: Runnable = prompt | chat
    mock_start = mocker.Mock()
    mock_end = mocker.Mock()
    chain_with_listeners = chain.with_listeners(on_start=mock_start, on_end=mock_end)

    chain_with_listeners.with_retry().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()

    chain_with_listeners.with_types(output_type=str).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()

    chain_with_listeners.with_config({"tags": ["foo"]}).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()

    chain_with_listeners.bind(stop=["foo"]).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()

    mock_start_inner = mocker.Mock()
    mock_end_inner = mocker.Mock()

    chain_with_listeners.with_listeners(
        on_start=mock_start_inner, on_end=mock_end_inner
    ).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
    assert mock_start_inner.call_count == 1
    assert mock_start_inner.call_args[0][0].name == "RunnableSequence"
    assert mock_end_inner.call_count == 1

Domain

Subdomains

Calls

Frequently Asked Questions

What does test_with_listener_propagation() do?
test_with_listener_propagation() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable.py.
Where is test_with_listener_propagation() defined?
test_with_listener_propagation() is defined in libs/core/tests/unit_tests/runnables/test_runnable.py at line 1705.
What does test_with_listener_propagation() call?
test_with_listener_propagation() 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