Home / Function/ test_str_replace_operation() — langchain Function Reference

test_str_replace_operation() — langchain Function Reference

Architecture documentation for the test_str_replace_operation() function in test_anthropic_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b9c2bb66_e5f2_e551_c93c_a3f0c702fbf3["test_str_replace_operation()"]
  6ec57bb9_6c88_435d_d3c5_ccf498cb814d["TestFileOperations"]
  b9c2bb66_e5f2_e551_c93c_a3f0c702fbf3 -->|defined in| 6ec57bb9_6c88_435d_d3c5_ccf498cb814d
  style b9c2bb66_e5f2_e551_c93c_a3f0c702fbf3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py lines 173–200

    def test_str_replace_operation(self) -> None:
        """Test str_replace command execution."""
        middleware = StateClaudeTextEditorMiddleware()

        state: AnthropicToolsState = {
            "messages": [],
            "text_editor_files": {
                "/test.txt": {
                    "content": ["Hello world", "Goodbye world"],
                    "created_at": "2025-01-01T00:00:00",
                    "modified_at": "2025-01-01T00:00:00",
                }
            },
        }

        args = {
            "command": "str_replace",
            "path": "/test.txt",
            "old_str": "world",
            "new_str": "universe",
        }
        result = middleware._handle_str_replace(args, state, "test_id")

        assert isinstance(result, Command)
        assert result.update is not None
        files = result.update.get("text_editor_files", {})
        # Should only replace first occurrence
        assert files["/test.txt"]["content"] == ["Hello universe", "Goodbye world"]

Domain

Subdomains

Frequently Asked Questions

What does test_str_replace_operation() do?
test_str_replace_operation() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py.
Where is test_str_replace_operation() defined?
test_str_replace_operation() is defined in libs/partners/anthropic/tests/unit_tests/middleware/test_anthropic_tools.py at line 173.

Analyze Your Own Codebase

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

Try Supermodel Free