Home / Function/ test_custom_event() — langchain Function Reference

test_custom_event() — langchain Function Reference

Architecture documentation for the test_custom_event() function in test_runnable_events_v2.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  84877149_9b7a_ffe8_5cce_2563d40d57c8["test_custom_event()"]
  33c02978_2077_5819_7048_bc2a81e80625["test_runnable_events_v2.py"]
  84877149_9b7a_ffe8_5cce_2563d40d57c8 -->|defined in| 33c02978_2077_5819_7048_bc2a81e80625
  716d2a5e_dc8e_3cae_e044_b56b06bee655["_collect_events()"]
  84877149_9b7a_ffe8_5cce_2563d40d57c8 -->|calls| 716d2a5e_dc8e_3cae_e044_b56b06bee655
  style 84877149_9b7a_ffe8_5cce_2563d40d57c8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py lines 2599–2670

async def test_custom_event() -> None:
    """Test adhoc event."""

    @RunnableLambda
    async def foo(x: int, config: RunnableConfig) -> int:
        """Simple function that emits some adhoc events."""
        await adispatch_custom_event("event1", {"x": x}, config=config)
        await adispatch_custom_event("event2", "foo", config=config)
        return x + 1

    uuid1 = uuid.UUID(int=7)

    events = await _collect_events(
        foo.astream_events(
            1,
            version="v2",
            config={"run_id": uuid1},
        ),
        with_nulled_ids=False,
    )

    run_id = str(uuid1)
    _assert_events_equal_allow_superset_metadata(
        events,
        [
            {
                "data": {"input": 1},
                "event": "on_chain_start",
                "metadata": {},
                "name": "foo",
                "parent_ids": [],
                "run_id": run_id,
                "tags": [],
            },
            {
                "data": {"x": 1},
                "event": "on_custom_event",
                "metadata": {},
                "name": "event1",
                "parent_ids": [],
                "run_id": run_id,
                "tags": [],
            },
            {
                "data": "foo",
                "event": "on_custom_event",
                "metadata": {},
                "name": "event2",
                "parent_ids": [],
                "run_id": run_id,
                "tags": [],
            },
            {
                "data": {"chunk": 2},
                "event": "on_chain_stream",
                "metadata": {},
                "name": "foo",
                "parent_ids": [],
                "run_id": run_id,
                "tags": [],
            },
            {
                "data": {"output": 2},
                "event": "on_chain_end",
                "metadata": {},
                "name": "foo",
                "parent_ids": [],
                "run_id": run_id,
                "tags": [],
            },
        ],
    )

Domain

Subdomains

Frequently Asked Questions

What does test_custom_event() do?
test_custom_event() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py.
Where is test_custom_event() defined?
test_custom_event() is defined in libs/core/tests/unit_tests/runnables/test_runnable_events_v2.py at line 2599.
What does test_custom_event() call?
test_custom_event() calls 1 function(s): _collect_events.

Analyze Your Own Codebase

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

Try Supermodel Free