Home / File/ test_base.py — langchain Source File

test_base.py — langchain Source File

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

File python CoreAbstractions Serialization 6 imports 4 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  04353e17_7a2a_a42e_4595_1cfd1500c7e4["test_base.py"]
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> 91721f45_4909_e489_8c1f_084f8bd87145
  bc0c97a0_93eb_cfbc_6044_05825b687ba4["langchain_core.document_loaders.base"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> bc0c97a0_93eb_cfbc_6044_05825b687ba4
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  e46f4a9d_5482_b595_2107_c5825c92261e["langchain_core.documents.base"]
  04353e17_7a2a_a42e_4595_1cfd1500c7e4 --> e46f4a9d_5482_b595_2107_c5825c92261e
  style 04353e17_7a2a_a42e_4595_1cfd1500c7e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Test Base Schema of documents."""

from collections.abc import Iterator

import pytest
from typing_extensions import override

from langchain_core.document_loaders.base import BaseBlobParser, BaseLoader
from langchain_core.documents import Document
from langchain_core.documents.base import Blob


def test_base_blob_parser() -> None:
    """Verify that the eager method is hooked up to the lazy method by default."""

    class MyParser(BaseBlobParser):
        """A simple parser that returns a single document."""

        @override
        def lazy_parse(self, blob: Blob) -> Iterator[Document]:
            """Lazy parsing interface."""
            yield Document(
                page_content="foo",
            )

    parser = MyParser()

    assert isinstance(parser.lazy_parse(Blob(data="who?")), Iterator)

    # We're verifying that the eager method is hooked up to the lazy method by default.
    docs = parser.parse(Blob(data="who?"))
    assert len(docs) == 1
    assert docs[0].page_content == "foo"


def test_default_lazy_load() -> None:
    class FakeLoader(BaseLoader):
        @override
        def load(self) -> list[Document]:
            return [
                Document(page_content="foo"),
                Document(page_content="bar"),
            ]

    loader = FakeLoader()
    docs = list(loader.lazy_load())
    assert docs == [Document(page_content="foo"), Document(page_content="bar")]


def test_lazy_load_not_implemented() -> None:
    class FakeLoader(BaseLoader):
        pass

    loader = FakeLoader()
    with pytest.raises(NotImplementedError):
        loader.lazy_load()


async def test_default_aload() -> None:
    class FakeLoader(BaseLoader):
        @override
        def lazy_load(self) -> Iterator[Document]:
            yield from [
                Document(page_content="foo"),
                Document(page_content="bar"),
            ]

    loader = FakeLoader()
    docs = loader.load()
    assert docs == [Document(page_content="foo"), Document(page_content="bar")]
    assert docs == [doc async for doc in loader.alazy_load()]
    assert docs == await loader.aload()

Subdomains

Dependencies

  • collections.abc
  • langchain_core.document_loaders.base
  • langchain_core.documents
  • langchain_core.documents.base
  • pytest
  • typing_extensions

Frequently Asked Questions

What does test_base.py do?
test_base.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_base.py?
test_base.py defines 4 function(s): test_base_blob_parser, test_default_aload, test_default_lazy_load, test_lazy_load_not_implemented.
What does test_base.py depend on?
test_base.py imports 6 module(s): collections.abc, langchain_core.document_loaders.base, langchain_core.documents, langchain_core.documents.base, pytest, typing_extensions.
Where is test_base.py in the architecture?
test_base.py is located at libs/core/tests/unit_tests/document_loaders/test_base.py (domain: CoreAbstractions, subdomain: Serialization, 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