Home / File/ test_llms.py — langchain Source File

test_llms.py — langchain Source File

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

File python LangChainCore LanguageModelBase 6 imports 7 functions

Entity Profile

Dependency Diagram

graph LR
  c4009766_f7e3_5acb_b9c7_0d2d714545e2["test_llms.py"]
  2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> 2bf6d401_816d_d011_3b05_a6114f55ff58
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  17a62cb3_fefd_6320_b757_b53bb4a1c661["langchain_core.callbacks"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> 17a62cb3_fefd_6320_b757_b53bb4a1c661
  4382dc25_6fba_324a_49e2_e9742d579385["langchain_core.outputs"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> 4382dc25_6fba_324a_49e2_e9742d579385
  a270c900_ac1e_6518_f720_875b8b52a3a0["langchain_anthropic"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> a270c900_ac1e_6518_f720_875b8b52a3a0
  96cb0233_4a12_7c16_ea94_ffebef0b0c34["tests.unit_tests._utils"]
  c4009766_f7e3_5acb_b9c7_0d2d714545e2 --> 96cb0233_4a12_7c16_ea94_ffebef0b0c34
  style c4009766_f7e3_5acb_b9c7_0d2d714545e2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test Anthropic API wrapper."""

from collections.abc import Generator

import pytest
from langchain_core.callbacks import CallbackManager
from langchain_core.outputs import LLMResult

from langchain_anthropic import AnthropicLLM
from tests.unit_tests._utils import FakeCallbackHandler

MODEL = "claude-sonnet-4-5-20250929"


@pytest.mark.requires("anthropic")
def test_anthropic_model_name_param() -> None:
    llm = AnthropicLLM(model_name="foo")
    assert llm.model == "foo"


@pytest.mark.requires("anthropic")
def test_anthropic_model_param() -> None:
    llm = AnthropicLLM(model="foo")  # type: ignore[call-arg]
    assert llm.model == "foo"


def test_anthropic_call() -> None:
    """Test valid call to anthropic."""
    llm = AnthropicLLM(model=MODEL)  # type: ignore[call-arg]
    output = llm.invoke("Say foo:")
    assert isinstance(output, str)


def test_anthropic_streaming() -> None:
    """Test streaming tokens from anthropic."""
    llm = AnthropicLLM(model=MODEL)  # type: ignore[call-arg]
    generator = llm.stream("I'm Pickle Rick")

    assert isinstance(generator, Generator)

    for token in generator:
        assert isinstance(token, str)


def test_anthropic_streaming_callback() -> None:
    """Test that streaming correctly invokes on_llm_new_token callback."""
    callback_handler = FakeCallbackHandler()
    callback_manager = CallbackManager([callback_handler])
    llm = AnthropicLLM(
        model=MODEL,  # type: ignore[call-arg]
        streaming=True,
        callbacks=callback_manager,
        verbose=True,
    )
    llm.invoke("Write me a sentence with 100 words.")
    assert callback_handler.llm_streams > 1


async def test_anthropic_async_generate() -> None:
    """Test async generate."""
    llm = AnthropicLLM(model=MODEL)  # type: ignore[call-arg]
    output = await llm.agenerate(["How many toes do dogs have?"])
    assert isinstance(output, LLMResult)


async def test_anthropic_async_streaming_callback() -> None:
    """Test that streaming correctly invokes on_llm_new_token callback."""
    callback_handler = FakeCallbackHandler()
    callback_manager = CallbackManager([callback_handler])
    llm = AnthropicLLM(
        model=MODEL,  # type: ignore[call-arg]
        streaming=True,
        callbacks=callback_manager,
        verbose=True,
    )
    result = await llm.agenerate(["How many toes do dogs have?"])
    assert callback_handler.llm_streams > 1
    assert isinstance(result, LLMResult)

Domain

Subdomains

Dependencies

  • collections.abc
  • langchain_anthropic
  • langchain_core.callbacks
  • langchain_core.outputs
  • pytest
  • tests.unit_tests._utils

Frequently Asked Questions

What does test_llms.py do?
test_llms.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What functions are defined in test_llms.py?
test_llms.py defines 7 function(s): test_anthropic_async_generate, test_anthropic_async_streaming_callback, test_anthropic_call, test_anthropic_model_name_param, test_anthropic_model_param, test_anthropic_streaming, test_anthropic_streaming_callback.
What does test_llms.py depend on?
test_llms.py imports 6 module(s): collections.abc, langchain_anthropic, langchain_core.callbacks, langchain_core.outputs, pytest, tests.unit_tests._utils.
Where is test_llms.py in the architecture?
test_llms.py is located at libs/partners/anthropic/tests/integration_tests/test_llms.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/partners/anthropic/tests/integration_tests).

Analyze Your Own Codebase

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

Try Supermodel Free