Home / File/ test_dispatch_custom_event.py — langchain Source File

test_dispatch_custom_event.py — langchain Source File

Architecture documentation for test_dispatch_custom_event.py, a python file in the langchain codebase. 8 imports, 0 dependents.

File python CoreAbstractions RunnableInterface 8 imports 5 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  f4cde4a2_4706_d7d1_26f9_82085d97a270["test_dispatch_custom_event.py"]
  d76a28c2_c3ab_00a8_5208_77807a49449d["sys"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> d76a28c2_c3ab_00a8_5208_77807a49449d
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> f3bc7443_c889_119d_0744_aacc3620d8d2
  e8ec017e_6c91_4b34_675f_2a96c5aa9be6["langchain_core.callbacks.manager"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> e8ec017e_6c91_4b34_675f_2a96c5aa9be6
  2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c["langchain_core.runnables"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> 2ceb1686_0f8c_8ae0_36d1_7c0b702fda1c
  2971f9da_6393_a3e3_610e_ace3d35ee978["langchain_core.runnables.config"]
  f4cde4a2_4706_d7d1_26f9_82085d97a270 --> 2971f9da_6393_a3e3_610e_ace3d35ee978
  style f4cde4a2_4706_d7d1_26f9_82085d97a270 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import sys
import uuid
from typing import Any
from uuid import UUID

import pytest

from langchain_core.callbacks import AsyncCallbackHandler, BaseCallbackHandler
from langchain_core.callbacks.manager import (
    adispatch_custom_event,
    dispatch_custom_event,
)
from langchain_core.runnables import RunnableLambda
from langchain_core.runnables.config import RunnableConfig


class AsyncCustomCallbackHandler(AsyncCallbackHandler):
    def __init__(self) -> None:
        self.events: list[Any] = []

    async def on_custom_event(
        self,
        name: str,
        data: Any,
        *,
        run_id: UUID,
        tags: list[str] | None = None,
        metadata: dict[str, Any] | None = None,
        **kwargs: Any,
    ) -> None:
        assert kwargs == {}
        self.events.append(
            (
                name,
                data,
                run_id,
                tags,
                metadata,
            )
        )


def test_custom_event_root_dispatch() -> None:
    """Test adhoc event in a nested chain."""
    # This just tests that nothing breaks on the path.
    # It shouldn't do anything at the moment, since the tracer isn't configured
    # to handle adhoc events.
    # Expected behavior is that the event cannot be dispatched
    with pytest.raises(RuntimeError):
        dispatch_custom_event("event1", {"x": 1})


async def test_async_custom_event_root_dispatch() -> None:
    """Test adhoc event in a nested chain."""
    # This just tests that nothing breaks on the path.
    # It shouldn't do anything at the moment, since the tracer isn't configured
    # to handle adhoc events.
    # Expected behavior is that the event cannot be dispatched
    with pytest.raises(RuntimeError):
        await adispatch_custom_event("event1", {"x": 1})
// ... (98 more lines)

Subdomains

Dependencies

  • langchain_core.callbacks
  • langchain_core.callbacks.manager
  • langchain_core.runnables
  • langchain_core.runnables.config
  • pytest
  • sys
  • typing
  • uuid

Frequently Asked Questions

What does test_dispatch_custom_event.py do?
test_dispatch_custom_event.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_dispatch_custom_event.py?
test_dispatch_custom_event.py defines 5 function(s): test_async_callback_manager, test_async_custom_event_implicit_config, test_async_custom_event_root_dispatch, test_custom_event_root_dispatch, test_sync_callback_manager.
What does test_dispatch_custom_event.py depend on?
test_dispatch_custom_event.py imports 8 module(s): langchain_core.callbacks, langchain_core.callbacks.manager, langchain_core.runnables, langchain_core.runnables.config, pytest, sys, typing, uuid.
Where is test_dispatch_custom_event.py in the architecture?
test_dispatch_custom_event.py is located at libs/core/tests/unit_tests/callbacks/test_dispatch_custom_event.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/callbacks).

Analyze Your Own Codebase

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

Try Supermodel Free