Home / File/ test_formatting.py — langchain Source File

test_formatting.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  c2d75b31_bdb7_424a_54c1_ea831065b59e["test_formatting.py"]
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  c2d75b31_bdb7_424a_54c1_ea831065b59e --> 120e2591_3e15_b895_72b6_cb26195e40a6
  5d3a2459_089e_5f20_61eb_223262657e65["langchain_core.utils.formatting"]
  c2d75b31_bdb7_424a_54c1_ea831065b59e --> 5d3a2459_089e_5f20_61eb_223262657e65
  style c2d75b31_bdb7_424a_54c1_ea831065b59e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Tests for langchain_core.utils.formatting."""

import pytest

from langchain_core.utils.formatting import StrictFormatter, formatter


class TestStrictFormatter:
    """Tests for the `StrictFormatter` class."""

    def test_vformat_with_keyword_args(self) -> None:
        """Test that `vformat` works with keyword arguments."""
        fmt = StrictFormatter()
        result = fmt.vformat("Hello, {name}!", [], {"name": "World"})
        assert result == "Hello, World!"

    def test_vformat_with_multiple_keyword_args(self) -> None:
        """Test `vformat` with multiple keyword arguments."""
        fmt = StrictFormatter()
        result = fmt.vformat(
            "{greeting}, {name}! You have {count} messages.",
            [],
            {"greeting": "Hello", "name": "Alice", "count": 5},
        )
        assert result == "Hello, Alice! You have 5 messages."

    def test_vformat_with_empty_string(self) -> None:
        """Test `vformat` with empty format string."""
        fmt = StrictFormatter()
        result = fmt.vformat("", [], {})
        assert result == ""

    def test_vformat_with_no_placeholders(self) -> None:
        """Test `vformat` with no placeholders in format string."""
        fmt = StrictFormatter()
        result = fmt.vformat("Hello, World!", [], {})
        assert result == "Hello, World!"

    def test_vformat_raises_on_positional_args(self) -> None:
        """Test that `vformat` raises `ValueError` when positional args are provided."""
        fmt = StrictFormatter()
        with pytest.raises(
            ValueError,
            match=r"No arguments should be provided, "
            r"everything should be passed as keyword arguments\.",
        ):
            fmt.vformat("{}", ["arg"], {})

    def test_vformat_raises_on_multiple_positional_args(self) -> None:
        """Test that `vformat` raises `ValueError` with multiple positional args."""
        fmt = StrictFormatter()
        with pytest.raises(ValueError, match=r"No arguments should be provided"):
            fmt.vformat("{} {}", ["arg1", "arg2"], {})

    def test_vformat_with_special_characters(self) -> None:
        """Test `vformat` with special characters in values."""
        fmt = StrictFormatter()
        result = fmt.vformat("{text}", [], {"text": "Hello\nWorld\t!"})
        assert result == "Hello\nWorld\t!"

// ... (68 more lines)

Subdomains

Dependencies

  • langchain_core.utils.formatting
  • pytest

Frequently Asked Questions

What does test_formatting.py do?
test_formatting.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What does test_formatting.py depend on?
test_formatting.py imports 2 module(s): langchain_core.utils.formatting, pytest.
Where is test_formatting.py in the architecture?
test_formatting.py is located at libs/core/tests/unit_tests/utils/test_formatting.py (domain: CoreAbstractions, subdomain: Serialization, 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