Home / Class/ TestIsCodeExecutionRelatedBlock Class — langchain Architecture

TestIsCodeExecutionRelatedBlock Class — langchain Architecture

Architecture documentation for the TestIsCodeExecutionRelatedBlock class in test_prompt_caching.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  84026b53_c23e_171c_9aac_ba34c6489805["TestIsCodeExecutionRelatedBlock"]
  80b9bbd1_b825_9778_a36c_351fbf1d2478["test_prompt_caching.py"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|defined in| 80b9bbd1_b825_9778_a36c_351fbf1d2478
  d889e1fb_ce6f_736e_e4e7_4ab933efcd7b["test_regular_tool_use_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| d889e1fb_ce6f_736e_e4e7_4ab933efcd7b
  927fe855_3f6e_3115_f7fb_d68a9edf0ed4["test_code_execution_tool_use_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| 927fe855_3f6e_3115_f7fb_d68a9edf0ed4
  102231ad_3fb7_0530_3041_7201ca7f5ab6["test_regular_tool_result_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| 102231ad_3fb7_0530_3041_7201ca7f5ab6
  c2b220cf_a8da_e7cc_f6e8_2dab74334253["test_code_execution_tool_result_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| c2b220cf_a8da_e7cc_f6e8_2dab74334253
  92f5a469_5a6f_c2e7_375c_776a83ba38e7["test_text_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| 92f5a469_5a6f_c2e7_375c_776a83ba38e7
  22115633_3acf_e763_a552_dca96f5d6f7c["test_non_dict_block()"]
  84026b53_c23e_171c_9aac_ba34c6489805 -->|method| 22115633_3acf_e763_a552_dca96f5d6f7c

Relationship Graph

Source Code

libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py lines 485–541

class TestIsCodeExecutionRelatedBlock:
    """Tests for _is_code_execution_related_block function."""

    def test_regular_tool_use_block(self) -> None:
        """Test regular tool_use block without caller."""
        block = {
            "type": "tool_use",
            "id": "toolu_regular",
            "name": "get_weather",
            "input": {"location": "NYC"},
        }
        assert not _is_code_execution_related_block(block, set())

    def test_code_execution_tool_use_block(self) -> None:
        """Test tool_use block called by code_execution."""
        block = {
            "type": "tool_use",
            "id": "toolu_code_exec",
            "name": "get_weather",
            "input": {"location": "NYC"},
            "caller": {
                "type": "code_execution_20250825",
                "tool_id": "srvtoolu_abc",
            },
        }
        assert _is_code_execution_related_block(block, set())

    def test_regular_tool_result_block(self) -> None:
        """Test tool_result block for regular tool."""
        block = {
            "type": "tool_result",
            "tool_use_id": "toolu_regular",
            "content": "Sunny, 72°F",
        }
        code_exec_ids = {"toolu_code_exec"}
        assert not _is_code_execution_related_block(block, code_exec_ids)

    def test_code_execution_tool_result_block(self) -> None:
        """Test tool_result block for code_execution called tool."""
        block = {
            "type": "tool_result",
            "tool_use_id": "toolu_code_exec",
            "content": "Sunny, 72°F",
        }
        code_exec_ids = {"toolu_code_exec"}
        assert _is_code_execution_related_block(block, code_exec_ids)

    def test_text_block(self) -> None:
        """Test that text blocks are not flagged."""
        block = {"type": "text", "text": "Hello world"}
        assert not _is_code_execution_related_block(block, set())

    def test_non_dict_block(self) -> None:
        """Test that non-dict values return False."""
        assert not _is_code_execution_related_block("string", set())  # type: ignore[arg-type]
        assert not _is_code_execution_related_block(None, set())  # type: ignore[arg-type]
        assert not _is_code_execution_related_block(123, set())  # type: ignore[arg-type]

Frequently Asked Questions

What is the TestIsCodeExecutionRelatedBlock class?
TestIsCodeExecutionRelatedBlock is a class in the langchain codebase, defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py.
Where is TestIsCodeExecutionRelatedBlock defined?
TestIsCodeExecutionRelatedBlock is defined in libs/partners/anthropic/tests/unit_tests/middleware/test_prompt_caching.py at line 485.

Analyze Your Own Codebase

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

Try Supermodel Free