Home / File/ test_serializable.py — langchain Source File

test_serializable.py — langchain Source File

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

File python CoreAbstractions Serialization 10 imports 19 functions 11 classes

Entity Profile

Dependency Diagram

graph LR
  301ae64e_25eb_eb56_ab7d_309f2840c7a6["test_serializable.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  6e58aaea_f08e_c099_3cc7_f9567bfb1ae7["pydantic"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 6e58aaea_f08e_c099_3cc7_f9567bfb1ae7
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497
  30d1300e_92bb_90d4_ac5e_1afe56db09d2["langchain_core.load.serializable"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> 30d1300e_92bb_90d4_ac5e_1afe56db09d2
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> d758344f_537f_649e_f467_b9d7442e86df
  ac2a9b92_4484_491e_1b48_ec85e71e1d58["langchain_core.outputs"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> ac2a9b92_4484_491e_1b48_ec85e71e1d58
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  301ae64e_25eb_eb56_ab7d_309f2840c7a6 --> e6b4f61e_7b98_6666_3641_26b069517d4a
  style 301ae64e_25eb_eb56_ab7d_309f2840c7a6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json
from typing import Any

import pytest
from pydantic import BaseModel, ConfigDict, Field, SecretStr

from langchain_core.documents import Document
from langchain_core.load import InitValidator, Serializable, dumpd, dumps, load, loads
from langchain_core.load.serializable import _is_field_useful
from langchain_core.messages import AIMessage
from langchain_core.outputs import ChatGeneration, Generation
from langchain_core.prompts import (
    ChatPromptTemplate,
    HumanMessagePromptTemplate,
    PromptTemplate,
)


class NonBoolObj:
    def __bool__(self) -> bool:
        msg = "Truthiness can't be determined"
        raise ValueError(msg)

    def __eq__(self, other: object) -> bool:
        msg = "Equality can't be determined"
        raise ValueError(msg)

    def __str__(self) -> str:
        return self.__class__.__name__

    def __repr__(self) -> str:
        return self.__class__.__name__

    __hash__ = None  # type: ignore[assignment]


def test_simple_serialization() -> None:
    class Foo(Serializable):
        bar: int
        baz: str

    foo = Foo(bar=1, baz="hello")
    assert dumpd(foo) == {
        "id": ["tests", "unit_tests", "load", "test_serializable", "Foo"],
        "lc": 1,
        "repr": "Foo(bar=1, baz='hello')",
        "type": "not_implemented",
    }


def test_simple_serialization_is_serializable() -> None:
    class Foo(Serializable):
        bar: int
        baz: str

        @classmethod
        def is_lc_serializable(cls) -> bool:
            return True

    foo = Foo(bar=1, baz="hello")
// ... (834 more lines)

Subdomains

Dependencies

  • json
  • langchain_core.documents
  • langchain_core.load
  • langchain_core.load.serializable
  • langchain_core.messages
  • langchain_core.outputs
  • langchain_core.prompts
  • pydantic
  • pytest
  • typing

Frequently Asked Questions

What does test_serializable.py do?
test_serializable.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_serializable.py?
test_serializable.py defines 19 function(s): test__is_field_useful, test_disallowed_deserialization, test_document_normal_metadata_allowed, test_dumps_additional_json_kwargs, test_dumps_basic_serialization, test_dumps_invalid_default_kwarg, test_dumps_mixed_data_structure, test_dumps_non_serializable_object, test_dumps_pretty_formatting, test_repr, and 9 more.
What does test_serializable.py depend on?
test_serializable.py imports 10 module(s): json, langchain_core.documents, langchain_core.load, langchain_core.load.serializable, langchain_core.messages, langchain_core.outputs, langchain_core.prompts, pydantic, and 2 more.
Where is test_serializable.py in the architecture?
test_serializable.py is located at libs/core/tests/unit_tests/load/test_serializable.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/core/tests/unit_tests/load).

Analyze Your Own Codebase

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

Try Supermodel Free