Home / File/ test_pydantic.py — langchain Source File

test_pydantic.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 7 imports 9 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  fa377536_4fc6_5b03_c28b_73c2f6c77447["test_pydantic.py"]
  d76a28c2_c3ab_00a8_5208_77807a49449d["sys"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> d76a28c2_c3ab_00a8_5208_77807a49449d
  0c635125_6987_b8b3_7ff7_d60249aecde7["warnings"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 0c635125_6987_b8b3_7ff7_d60249aecde7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  63ae09a2_4a67_3eaf_7888_b0fd11776a0e["pydantic.v1"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 63ae09a2_4a67_3eaf_7888_b0fd11776a0e
  1014fe78_cb2c_fde4_a624_ae899aa7ca8e["langchain_core.utils.pydantic"]
  fa377536_4fc6_5b03_c28b_73c2f6c77447 --> 1014fe78_cb2c_fde4_a624_ae899aa7ca8e
  style fa377536_4fc6_5b03_c28b_73c2f6c77447 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test for some custom pydantic decorators."""

import sys
import warnings
from typing import Any

import pytest
from pydantic import BaseModel, ConfigDict, Field
from pydantic.v1 import BaseModel as BaseModelV1

from langchain_core.utils.pydantic import (
    _create_subset_model_v2,
    create_model_v2,
    get_fields,
    is_basemodel_instance,
    is_basemodel_subclass,
    pre_init,
)


def test_pre_init_decorator() -> None:
    class Foo(BaseModel):
        x: int = 5
        y: int

        @pre_init
        def validator(cls, v: dict[str, Any]) -> dict[str, Any]:
            v["y"] = v["x"] + 1
            return v

    # Type ignore initialization b/c y is marked as required
    foo = Foo()  # type: ignore[call-arg]
    assert foo.y == 6
    foo = Foo(x=10)  # type: ignore[call-arg]
    assert foo.y == 11


def test_pre_init_decorator_with_more_defaults() -> None:
    class Foo(BaseModel):
        a: int = 1
        b: int | None = None
        c: int = Field(default=2)
        d: int = Field(default_factory=lambda: 3)

        @pre_init
        def validator(cls, v: dict[str, Any]) -> dict[str, Any]:
            assert v["a"] == 1
            assert v["b"] is None
            assert v["c"] == 2
            assert v["d"] == 3
            return v

    # Try to create an instance of Foo
    Foo()


def test_with_aliases() -> None:
    class Foo(BaseModel):
        x: int = Field(default=1, alias="y")
        z: int
// ... (129 more lines)

Subdomains

Classes

Dependencies

  • langchain_core.utils.pydantic
  • pydantic
  • pydantic.v1
  • pytest
  • sys
  • typing
  • warnings

Frequently Asked Questions

What does test_pydantic.py do?
test_pydantic.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_pydantic.py?
test_pydantic.py defines 9 function(s): test_create_model_v2, test_fields_pydantic_v1_from_2, test_fields_pydantic_v2_proper, test_is_basemodel_instance, test_is_basemodel_subclass, test_pre_init_decorator, test_pre_init_decorator_with_more_defaults, test_with_aliases, test_with_field_metadata.
What does test_pydantic.py depend on?
test_pydantic.py imports 7 module(s): langchain_core.utils.pydantic, pydantic, pydantic.v1, pytest, sys, typing, warnings.
Where is test_pydantic.py in the architecture?
test_pydantic.py is located at libs/core/tests/unit_tests/utils/test_pydantic.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/utils).

Analyze Your Own Codebase

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

Try Supermodel Free