Home / File/ test_logging.py — langchain Source File

test_logging.py — langchain Source File

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

File python LangChainCore Runnables 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  921d9b36_02e3_7d6e_0430_9c870f589460["test_logging.py"]
  e27da29f_a1f7_49f3_84d5_6be4cb4125c8["logging"]
  921d9b36_02e3_7d6e_0430_9c870f589460 --> e27da29f_a1f7_49f3_84d5_6be4cb4125c8
  02625e10_fb78_7ecd_1ee2_105ee470faf5["sys"]
  921d9b36_02e3_7d6e_0430_9c870f589460 --> 02625e10_fb78_7ecd_1ee2_105ee470faf5
  02f66451_d2a9_e7c3_9765_c3a7594721ad["uuid"]
  921d9b36_02e3_7d6e_0430_9c870f589460 --> 02f66451_d2a9_e7c3_9765_c3a7594721ad
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  921d9b36_02e3_7d6e_0430_9c870f589460 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  c839b4c7_6abe_f680_b063_d14f317e2e6b["langchain_classic.callbacks.tracers"]
  921d9b36_02e3_7d6e_0430_9c870f589460 --> c839b4c7_6abe_f680_b063_d14f317e2e6b
  style 921d9b36_02e3_7d6e_0430_9c870f589460 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import logging
import sys
import uuid

import pytest

from langchain_classic.callbacks.tracers import LoggingCallbackHandler


def test_logging(
    caplog: pytest.LogCaptureFixture,
    capsys: pytest.CaptureFixture[str],
) -> None:
    # Set up a Logger and a handler so we can check the Logger's handlers work too
    logger = logging.getLogger("test_logging")
    logger.setLevel(logging.INFO)
    logger.addHandler(logging.StreamHandler(sys.stdout))

    handler = LoggingCallbackHandler(logger, extra={"test": "test_extra"})
    handler.on_text("test", run_id=uuid.uuid4())

    # Assert logging actually took place
    assert len(caplog.record_tuples) == 1
    record = caplog.records[0]
    assert record.name == logger.name
    assert record.levelno == logging.INFO
    assert (
        record.msg == "\x1b[36;1m\x1b[1;3m[text]\x1b[0m \x1b[1mNew text:\x1b[0m\ntest"
    )
    # Check the extra shows up
    assert record.test == "test_extra"  # type: ignore[attr-defined]

    # Assert log handlers worked
    cap_result = capsys.readouterr()
    assert (
        cap_result.out
        == "\x1b[36;1m\x1b[1;3m[text]\x1b[0m \x1b[1mNew text:\x1b[0m\ntest\n"
    )

Domain

Subdomains

Functions

Dependencies

  • langchain_classic.callbacks.tracers
  • logging
  • pytest
  • sys
  • uuid

Frequently Asked Questions

What does test_logging.py do?
test_logging.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, Runnables subdomain.
What functions are defined in test_logging.py?
test_logging.py defines 1 function(s): test_logging.
What does test_logging.py depend on?
test_logging.py imports 5 module(s): langchain_classic.callbacks.tracers, logging, pytest, sys, uuid.
Where is test_logging.py in the architecture?
test_logging.py is located at libs/langchain/tests/unit_tests/callbacks/tracers/test_logging.py (domain: LangChainCore, subdomain: Runnables, directory: libs/langchain/tests/unit_tests/callbacks/tracers).

Analyze Your Own Codebase

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

Try Supermodel Free