Home / File/ test_langsmith.py — langchain Source File

test_langsmith.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  96709919_9cd9_963f_bfc5_49d6081b92d8["test_langsmith.py"]
  af34f08b_0ede_2b87_0db6_983d74ed0249["datetime"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> af34f08b_0ede_2b87_0db6_983d74ed0249
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  525a7d6f_f455_56e3_854a_c8a7da4a1417["unittest.mock"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> 525a7d6f_f455_56e3_854a_c8a7da4a1417
  ee1d35f7_eb2d_f3ba_5b09_7f4815d92b12["langsmith.schemas"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> ee1d35f7_eb2d_f3ba_5b09_7f4815d92b12
  2a596110_eecb_6975_0f38_02fb4494758e["langchain_core.document_loaders"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> 2a596110_eecb_6975_0f38_02fb4494758e
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  707209ca_c3d6_f9c6_7ec7_2b2df92c9aa3["langchain_core.tracers._compat"]
  96709919_9cd9_963f_bfc5_49d6081b92d8 --> 707209ca_c3d6_f9c6_7ec7_2b2df92c9aa3
  style 96709919_9cd9_963f_bfc5_49d6081b92d8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import datetime
import uuid
from unittest.mock import MagicMock, patch

from langsmith.schemas import Example

from langchain_core.document_loaders import LangSmithLoader
from langchain_core.documents import Document
from langchain_core.tracers._compat import pydantic_to_dict


def test_init() -> None:
    LangSmithLoader(api_key="secret")


EXAMPLES = [
    Example(
        inputs={"first": {"second": "foo"}},
        outputs={"res": "a"},
        dataset_id=uuid.uuid4(),
        id=uuid.uuid4(),
        created_at=datetime.datetime.now(datetime.timezone.utc),
    ),
    Example(
        inputs={"first": {"second": "bar"}},
        outputs={"res": "b"},
        dataset_id=uuid.uuid4(),
        id=uuid.uuid4(),
        created_at=datetime.datetime.now(datetime.timezone.utc),
    ),
    Example(
        inputs={"first": {"second": "baz"}},
        outputs={"res": "c"},
        dataset_id=uuid.uuid4(),
        id=uuid.uuid4(),
        created_at=datetime.datetime.now(datetime.timezone.utc),
    ),
]


@patch("langsmith.Client.list_examples", MagicMock(return_value=iter(EXAMPLES)))
def test_lazy_load() -> None:
    loader = LangSmithLoader(
        api_key="dummy",
        dataset_id="mock",
        content_key="first.second",
        format_content=(lambda x: x.upper()),
    )
    expected = []
    for example in EXAMPLES:
        example_dict = pydantic_to_dict(example)
        metadata = {
            k: v if not v or isinstance(v, dict) else str(v)
            for k, v in example_dict.items()
        }
        expected.append(
            Document(example.inputs["first"]["second"].upper(), metadata=metadata)
            if example.inputs
            else None
        )
    actual = list(loader.lazy_load())
    assert expected == actual

Subdomains

Dependencies

  • datetime
  • langchain_core.document_loaders
  • langchain_core.documents
  • langchain_core.tracers._compat
  • langsmith.schemas
  • unittest.mock
  • uuid

Frequently Asked Questions

What does test_langsmith.py do?
test_langsmith.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_langsmith.py?
test_langsmith.py defines 2 function(s): test_init, test_lazy_load.
What does test_langsmith.py depend on?
test_langsmith.py imports 7 module(s): datetime, langchain_core.document_loaders, langchain_core.documents, langchain_core.tracers._compat, langsmith.schemas, unittest.mock, uuid.
Where is test_langsmith.py in the architecture?
test_langsmith.py is located at libs/core/tests/unit_tests/document_loaders/test_langsmith.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/tests/unit_tests/document_loaders).

Analyze Your Own Codebase

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

Try Supermodel Free