Home / Class/ TestStrictFormatter Class — langchain Architecture

TestStrictFormatter Class — langchain Architecture

Architecture documentation for the TestStrictFormatter class in test_formatting.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  35ba2f22_6d1f_885b_7489_509b43578ba8["TestStrictFormatter"]
  c2d75b31_bdb7_424a_54c1_ea831065b59e["test_formatting.py"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|defined in| c2d75b31_bdb7_424a_54c1_ea831065b59e
  433b5f03_2f65_c91f_e1e1_9abf918e7511["test_vformat_with_keyword_args()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 433b5f03_2f65_c91f_e1e1_9abf918e7511
  385ecb88_71f0_a537_a8ca_2ffc3acf6c24["test_vformat_with_multiple_keyword_args()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 385ecb88_71f0_a537_a8ca_2ffc3acf6c24
  781e2238_d9ad_00a9_cf15_f1f3ef75df10["test_vformat_with_empty_string()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 781e2238_d9ad_00a9_cf15_f1f3ef75df10
  0110867c_cbfd_87ce_f0bc_4927fb2b1788["test_vformat_with_no_placeholders()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 0110867c_cbfd_87ce_f0bc_4927fb2b1788
  5090efcc_45be_ef66_2ac4_fd68c5de8e77["test_vformat_raises_on_positional_args()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 5090efcc_45be_ef66_2ac4_fd68c5de8e77
  b6245b1a_f84e_fe71_65a0_87d0bb986fad["test_vformat_raises_on_multiple_positional_args()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| b6245b1a_f84e_fe71_65a0_87d0bb986fad
  72a29920_dfe8_bc6a_b31d_8e86e2af6c4e["test_vformat_with_special_characters()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 72a29920_dfe8_bc6a_b31d_8e86e2af6c4e
  c217db26_ae5b_f6c6_ae63_c6fe2f06de80["test_vformat_with_unicode()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| c217db26_ae5b_f6c6_ae63_c6fe2f06de80
  bb69d31d_5c08_2da6_8570_25db9dbed2ac["test_vformat_with_format_spec()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| bb69d31d_5c08_2da6_8570_25db9dbed2ac
  55d9e30b_3c52_da4f_d262_d8498239968a["test_vformat_with_nested_braces()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 55d9e30b_3c52_da4f_d262_d8498239968a
  547df180_7acc_5cf9_2726_384922926ce9["test_validate_input_variables_success()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 547df180_7acc_5cf9_2726_384922926ce9
  03030617_b4e4_ae60_3ce8_fa094fe05564["test_validate_input_variables_with_extra_variables()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| 03030617_b4e4_ae60_3ce8_fa094fe05564
  cf40a3be_d1f1_2397_a122_98d3f9acfbd1["test_validate_input_variables_with_missing_variable()"]
  35ba2f22_6d1f_885b_7489_509b43578ba8 -->|method| cf40a3be_d1f1_2397_a122_98d3f9acfbd1

Relationship Graph

Source Code

libs/core/tests/unit_tests/utils/test_formatting.py lines 8–109

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!"

    def test_vformat_with_unicode(self) -> None:
        """Test `vformat` with unicode characters."""
        fmt = StrictFormatter()
        result = fmt.vformat(
            "{emoji} {text}", [], {"emoji": "🎉", "text": "こんにちは"}
        )
        assert result == "🎉 こんにちは"

    def test_vformat_with_format_spec(self) -> None:
        """Test `vformat` with format specifications."""
        fmt = StrictFormatter()
        result = fmt.vformat("{num:.2f}", [], {"num": 3.14159})
        assert result == "3.14"

    def test_vformat_with_nested_braces(self) -> None:
        """Test `vformat` with escaped braces."""
        fmt = StrictFormatter()
        result = fmt.vformat("{{literal}} {var}", [], {"var": "value"})
        assert result == "{literal} value"

    def test_validate_input_variables_success(self) -> None:
        """Test that `validate_input_variables` succeeds with valid input."""
        fmt = StrictFormatter()
        # Should not raise
        fmt.validate_input_variables("{name} {age}", ["name", "age"])

    def test_validate_input_variables_with_extra_variables(self) -> None:
        """Test `validate_input_variables` with extra variables (should succeed)."""

Frequently Asked Questions

What is the TestStrictFormatter class?
TestStrictFormatter is a class in the langchain codebase, defined in libs/core/tests/unit_tests/utils/test_formatting.py.
Where is TestStrictFormatter defined?
TestStrictFormatter is defined in libs/core/tests/unit_tests/utils/test_formatting.py at line 8.

Analyze Your Own Codebase

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

Try Supermodel Free